我的第一个机器人足球程序.doc

上传人:枫** 文档编号:542557736 上传时间:2024-01-21 格式:DOC 页数:12 大小:45.51KB
返回 下载 相关 举报
我的第一个机器人足球程序.doc_第1页
第1页 / 共12页
我的第一个机器人足球程序.doc_第2页
第2页 / 共12页
我的第一个机器人足球程序.doc_第3页
第3页 / 共12页
我的第一个机器人足球程序.doc_第4页
第4页 / 共12页
我的第一个机器人足球程序.doc_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《我的第一个机器人足球程序.doc》由会员分享,可在线阅读,更多相关《我的第一个机器人足球程序.doc(12页珍藏版)》请在金锄头文库上搜索。

1、我的第一个机器人足球程序(960行) (一)2007-05-07 19:04/lili/ Strategy.cpp : Defines the entry point for the DLL application#include stdafx.h#include Strategy.h#include BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) switch (ul_reason_for_call) case DLL_PROCESS_ATTACH: case DLL_T

2、HREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; return TRUE;/global variablesconst double PI = 3.1415926;int WHO = 1; /1 blue 0 yellowconst double MAXL = 112; /球场对角线长FILE *DEBUGFILE; /调试文件Environment *ENV;int NEEDROTATE5 = 1, 1, 1, 1, 1; /1 need, else not needint PD5 = 0; /巡逻方向

3、,由 点 1 到 2double TRACE622 = -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1; /纪录 5 个机器人的轨迹double DISPLACEMENT6 = 0; /纪录每个机器人在 1/6 秒内的位移int EV6 = 0; /estimate v 估计的机器人的速度 and the balldouble COUNT1 = 0, COUNT2 = 0; /保存调用次数double PBP2 = 0, 0; /预测的球的坐标 predict ball positionint WI

4、B = 5; /whree is balldouble ROBOTLENGTH = 3.2; /length of a robot/basic methodsvoid go(Robot *robot, int rID, const double x, const double y); /朝某点运动void backGo(Robot *robot, int rID, const double x, const double y); /double rotateTo(Robot *robot, int rID, const double desX, const double desY); /转动v

5、oid stop(Robot *robot, int rID); /停止void to(Robot *robot, int rID, double x, double y); /到某点静止void backTo(Robot *robot, int rID, double x, double y); /反向到某点静止void estimateV(); /估计所有机器人的速度,and the ballvoid predictBall(double s); /预测球的出现void run(Robot *robot, int rID, int vl, int vr);/advanced methods

6、void passBall(Robot *robotS, Robot *robotG, int rIDS, int rIDG); /传球 robot send ,robot getvoid patrol(Robot *robot, int rID, double x1, double y1, double x2, double y2); /在 2 点间晃动void nearBall(Robot *robot, int rID, double x, double y); /接近球,并且与 x,y 不在球的同一边void kickBall(Robot *robot, int rID, double

7、 x, double y); /把球打到指定地点/stratgiesbool canKShoot(Robot *robot, int rID);/是否可以用头撞球进 can kick shootbool canRShoot(Robot *robot, int rID); /是否可以旋转撞球进 rotateint whereIsBall(); /判断球在哪个区域,返回区域编号bool hasEnemyBetween(Robot *robot, double x, double y); /is there enemy between robot and x,yvoid defend(int wib

8、); /void attack(int wib); /role controllervoid waiter(Robot *robot, int rID, double x, double y); /在 x,y 点等待球,一旦 r.xx,距离小于某值时kick ballvoid activeDefender(Robot *robot, int rID); /绕到球的右边 kick ballvoid negativeDefender(Robot *robot, int rID, double x, double y); /首在某点并对着球,一旦距离小于某一值 kick ball,b.x xvoid

9、 keepHelper(Robot *robot, int rID); /协助守门员在球门的另一半守门,x 坐标小于守门员void keeper(Robot *robot, int rID); /守门员,在固定 x 坐标跟着球的 y 坐标跑void attacker(Robot *robot, int rID); /绕到球的右边 kick ball/strategy for all statesvoid strategyForD(Environment *env); /defaultvoid strategyForFB(Environment *env);void strategyForPlK

10、(Environment *env);void strategyForPeK(Environment *env);void strategyForFK(Environment *env);void strategyForGK(Environment *env);extern C STRATEGY_API void Create ( Environment *env )/ allocate user data and assign to env-userData/ eg. env-userData = ( void * ) new MyVariables ();extern C STRATEGY

11、_API void Destroy ( Environment *env )/ free any user data created in Create ( Environment * )/ eg. if ( env-userData != NULL ) delete ( MyVariables * ) env-userData;extern C STRATEGY_API void Strategy ( Environment *env )/here are my Strategies ,as the game state differes calls the responding metho

12、d COUNT2 +;ENV = env;estimateV();switch(env-gameState) case 0 : strategyForD(env);break; case FREE_BALL : strategyForD(env); break; case PLACE_KICK : strategyForD(env); break; case PENALTY_KICK : strategyForPeK(env); break; case FREE_KICK : strategyForD(env); break; case GOAL_KICK : strategyForD(env

13、); break;void strategyForD(Environment *env) /对默认情况/double bx,by ,rx; /balls coordinateint lt = 0;bx = env-currentBall.pos.x;by = env-currentBall.pos.y;rx = env-home0.pos.x;whereIsBall();/to(&env-home3, 3,env-currentBall.pos.x, env-currentBall.pos.y);/negativeDefender(&env-home2,2,0,58);/activeDefen

14、der(&env-home1,1);/activeDefender(&env-home2,2);/activeDefender(&env-home3,3);/attacker(&env-home4,4);keeper(&env-home0,0);switch(WIB) case 1 : defend(1); break; case 2 : defend(2); break; case 3 : defend(3); break; case 4 : attack(4); break; case 5 : attack(5); break; case 6 : attack(6); break; case 7 : attack(7); break; case 8 : attack(8); break; case 9 : attack(9); break;/以下相当于紧急模块if(bx 88.28 & by 33.93 & by -0.5) go(&env-home0, 0, bx-0.3, by);for(lt=0;lthomelt, lt) & env-

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号