基于人工智能算法实现AI足球比赛
1.对于机器人足球,只需要轮循计算机控制的所有球员,让每个球员针对场上情况作出最正确的响应就行了。计算机的速度非常快,虽然是轮循,但几乎不会察觉出其中的先后次序,给人的感觉就是在同时进行。其实操作系统的多线程,也是这样实现的。X86构架的cpu,多线程多任务程序是运行在保护模式下的,其根本思想就是将cpu时间切片,这个时间片上处理a任务,不管有没有处理完,下一个时间片上一定处理b任务,一圈循环下来
·
相关资料:http://t.csdn.cn/1XSne
实现目标:

目前进展:

主要用到就是射门概率那块,用随机数+能力值来控制
#include <iostream>
#include "footballManager.h"
FootballManager::FootballManager()
{
this->showMenu();
};
//FootballManager::
void FootballManager::exitSystem()
{
system("cls");
cout << "已成功退出,欢迎下次使用" << endl;
system("pause");
}
void FootballManager::showMenu()
{
cout << "-----------------------------------------------------" << endl;
cout << " 英超联赛正在进行中,我是本场解说本泽马 " << endl;
cout << "********** 1.开始本场比赛 **********" << endl;
cout << "********** 2.查看英超积分排行榜 **********" << endl;
cout << "********** 3.清空比赛记录 **********" << endl;
cout << "********** 0.退出比赛程序 **********" << endl;
cout << "-----------------------------------------------------" << endl;
cout << endl;
}
//初始化球员姓名、能力
void FootballManager::initPlayer() {
this->player.playerName = "Cristiano Ronaldo";
this->player.finsh = 95;
this->player.number = 7;
this->player.pass = 96;
this->player.speed = 97;
}
//确定阵容
void FootballManager::detmineLineup()
{
cout << "本次双方阵容" << endl;
cout << this->player.number << "号" << this->player.playerName << endl;
}
//比赛进行
void FootballManager::getScore()
{
int time = this->courtLength;
while(time)
{
time -= this->player.speed - 90;
if (time == this->courtLength - rand() % 30)
{
cout << this->player.playerName << " 准备射门了" << endl;
break;
}
}
this->player.shot();
}
void FootballManager::changeBall()
{
cout << this->player.playerName << " 中路拿球" << endl;
cout << this->player.playerName << " 快速带球" << endl;
cout << this->player.playerName << " 全力冲刺" << endl;
}
//开始比赛
void FootballManager::startGame()
{
this->initPlayer();
this->detmineLineup();
this->changeBall();
this->getScore();
}
FootballManager::~FootballManager()
{
};
#pragma once
#include <iostream>
#include "player.h"
using namespace std;
class FootballManager
{
public:
int courtLength = 105, courtWidth = 68;
Player player;
FootballManager();
//交互界面
void showMenu();
//退出
void exitSystem();
//球员初始化
void initPlayer();
//确定阵容(初始化)
void detmineLineup();
//比赛进行
void getScore();
//开球
void startGame();
//球权
void changeBall();
~FootballManager();
};
#pragma once
#include <iostream>
using namespace std;
class Player
{
public:
Player();
string playerName;
int number;
int speed;
int finsh;
int pass;
void shot();
~Player();
};
#include "footballManager.h"
#include <iostream>
using namespace std;
int main()
{
FootballManager fifa;
int choice = 0;
while (true)
{
cin >> choice;
switch (choice)
{
case 1:
fifa.startGame();
break;
case 2:
break;
case 3:
break;
case 0:
fifa.exitSystem();
return 0;
break;
default:
system("cls");
break;
}
}
system("pause");
return 0;
}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐
所有评论(0)