收藏 分享(赏)

基于网格思想的1V1.doc

上传人:s36f12 文档编号:9478430 上传时间:2019-08-09 格式:DOC 页数:29 大小:100.50KB
下载 相关 举报
基于网格思想的1V1.doc_第1页
第1页 / 共29页
基于网格思想的1V1.doc_第2页
第2页 / 共29页
基于网格思想的1V1.doc_第3页
第3页 / 共29页
基于网格思想的1V1.doc_第4页
第4页 / 共29页
基于网格思想的1V1.doc_第5页
第5页 / 共29页
点击查看更多>>
资源描述

1、基于网格思想的 1V1using System;using System.Collections.Generic;using System.Linq;using System.Text;using xna = Microsoft.Xna.Framework;using Microsoft.Dss;using URWPGSim2D.Common;using URWPGSim2D.StrategyLoader;using URWPGSim2D.Core;using URWPGSim2D.Strategy;using URWPGSim2D.StrategyHelper;namespace URWPG

2、Sim2D.Strategypublic class Strategy : MarshalByRefObject, IStrategy#region reserved code never be changed or removed/ / override the InitializeLifetimeService to return null instead of a valid ILease implementation/ to ensure this type of remote object never dies/ / nullpublic override object Initia

3、lizeLifetimeService()/return base.InitializeLifetimeService();return null; / makes the object live indefinitely#endregion/ / 决策类当前对象对应的仿真使命参与队伍的决策数组引用 第一次调用 GetDecision时分配空间/ private Decision decisions = null;/ / 获取队伍名称 在此处设置参赛队伍的名称/ / 队伍名称字符串public string GetTeamName()return “兰之鹰队“;/ / 获取当前仿真使命(比赛项

4、目)当前队伍所有仿真机器鱼的决策数据构成的数组/ / 服务端当前运行着的仿真使命 Mission对象/ 当前队伍在服务端运行着的仿真使命中所处的编号 / 用于作为索引访问 Mission对象的 TeamsRef队伍列表中代表当前队伍的元素/ 当前队伍所有仿真机器鱼的决策数据构成的Decision数组对象public Decision GetDecision(Mission mission, int teamId)/ 决策类当前对象第一次调用 GetDecision时Decision数组引用为 nullif (decisions = null)/ 根据决策类当前对象对应的仿真使命参与队伍仿真机器

5、鱼的数量分配决策数组空间decisions = new Decisionmission.CommonPara.FishCntPerTeam;#region 决策计算过程 需要各参赛队伍实现的部分#region 策略编写帮助信息/=我是华丽的分割线=/=策略编写指南=/1.策略编写工作直接目标是给当前队伍决策数组decisions各元素填充决策值/2.决策数据类型包括两个 int成员,VCode 为速度档位值,TCode 为转弯档位值/3.VCode取值范围 0-14共 15个整数值,每个整数对应一个速度值,速度值整体但非严格递增/有个别档位值对应的速度值低于比它小的档位值对应的速度值,速度值数

6、据来源于实验/4.TCode取值范围 0-14共 15个整数值,每个整数对应一个角速度值/整数 7对应直游,角速度值为 0,整数 6-0,8-14分别对应左转和右转,偏离 7越远,角度速度值越大/5.任意两个速度/转弯档位之间切换,都需要若干个仿真周期,才能达到稳态速度/角速度值/目前运动学计算过程决定稳态速度/角速度值接近但小于目标档位对应的速度/角速度值/6.决策类 Strategy的实例在加载完毕后一直存在于内存中,可以自定义私有成员变量保存必要信息/但需要注意的是,保存的信息在中途更换策略时将会丢失/=我是华丽的分割线=/=策略中可以使用的比赛环境信息和过程信息说明=/场地坐标系: 以

7、毫米为单位,矩形场地中心为原点,向右为正 X,向下为正 Z/ 负 X轴顺时针转回负 X轴角度范围为(-PI,PI)的坐标系,也称为世界坐标系/mission.CommonPara: 当前仿真使命公共参数/mission.CommonPara.FishCntPerTeam: 每支队伍仿真机器鱼数量/mission.CommonPara.MsPerCycle: 仿真周期毫秒数/mission.CommonPara.RemainingCycles: 当前剩余仿真周期数/mission.CommonPara.TeamCount: 当前仿真使命参与队伍数量/mission.CommonPara.Tota

8、lSeconds: 当前仿真使命运行时间秒数/mission.EnvRef.Balls: /当前仿真使命涉及到的仿真水球列表,列表元素的成员意义参见 URWPGSim2D.Common.Ball类定义中的注释/mission.EnvRef.FieldInfo: /当前仿真使命涉及到的仿真场地,各成员意义参见URWPGSim2D.Common.Field类定义中的注释/mission.EnvRef.ObstaclesRect: /当前仿真使命涉及到的方形障碍物列表,列表元素的成员意义参见 URWPGSim2D.Common.RectangularObstacle类定义中的注释/mission.E

9、nvRef.ObstaclesRound:/当前仿真使命涉及到的圆形障碍物列表,列表元素的成员意义参见 URWPGSim2D.Common.RoundedObstacle类定义中的注释/mission.TeamsRefteamId:/决策类当前对象对应的仿真使命参与队伍(当前队伍)/mission.TeamsRefteamId.Para:/当前队伍公共参数,各成员意义参见URWPGSim2D.Common.TeamCommonPara类定义中的注释/mission.TeamsRefteamId.Fishes:/当前队伍仿真机器鱼列表,列表元素的成员意义参见 URWPGSim2D.Common.

10、RoboFish类定义中的注释/mission.TeamsRefteamId.Fishesi.PositionMm和 PolygonVertices0,BodyDirectionRad,VelocityMmPs,/ AngularVelocityRadPs,Tactic:/当前队伍第 i条仿真机器鱼鱼体矩形中心和鱼头顶点在场地坐标系中的位置(用到 X坐标和 Z坐标) ,鱼体方向,速度值,/ 角速度值,决策值/=我是华丽的分割线=/=典型循环=/for (int i = 0; i -135dirbBtoG = DirBToG(ballPt, rightGoal);/球到右球门方向tempPt.X

11、 = ballPt.X - (float)(r * Math.Cos(dirbBtoG);tempPt.Z = ballPt.Z - (float)(r * Math.Sin(dirbBtoG);StrategyHelper.Helpers.Dribble(ref decisions0, mission.TeamsRefteamId.Fishes0,tempPt, dirbBtoG, 5, 10, 150, 14, 8, 14, mission.CommonPara.MsPerCycle, true);return decisions;else if (mission.EnvRef.Balls

12、0.PositionMm.X -200 tempPt.X = ballPt.X - (float)(r * Math.Cos(dirFish);tempPt.Z = ballPt.Z - (float)(r * Math.Sin(dirFish);StrategyHelper.Helpers.Dribble(ref decisions0, mission.TeamsRefteamId.Fishes0,tempPt, dirFish, 5, 10, 150, 14, 8, 14, mission.CommonPara.MsPerCycle, true);return decisions;else

13、 if (mission.EnvRef.Balls0.PositionMm.X -200 tempPt.X = ballPt.X - (float)(r * Math.Cos(dirFish);tempPt.Z = ballPt.Z - (float)(r * Math.Sin(dirFish);StrategyHelper.Helpers.Dribble(ref decisions0, mission.TeamsRefteamId.Fishes0,tempPt, dirFish, 5, 10, 150, 14, 8, 14, mission.CommonPara.MsPerCycle, tr

14、ue);return decisions;else if (mission.EnvRef.Balls0.PositionMm.Z = -500)tempPt.X = ballPt.X - (float)(r * Math.Cos(dirFish);tempPt.Z = ballPt.Z - (float)(r * Math.Sin(dirFish);StrategyHelper.Helpers.Dribble(ref decisions0, mission.TeamsRefteamId.Fishes0,tempPt, dirFish, 5, 10, 170, 14, 8, 14, missio

15、n.CommonPara.MsPerCycle, true);return decisions;else if (mission.EnvRef.Balls0.PositionMm.Z = 950)/球门左外rightGoal = new xna.Vector3(1350f, 0f, 200);dirbBtoG = DirBToG(ballPt, rightGoal);/球到右球门方向tempPt.X = ballPt.X - (float)(r * Math.Cos(dirbBtoG);tempPt.Z = ballPt.Z - (float)(r * Math.Sin(dirbBtoG);S

16、trategyHelper.Helpers.Dribble(ref decisions0, mission.TeamsRefteamId.Fishes0,tempPt, dirFish, 5, 10, 200, 14, 8, 14, mission.CommonPara.MsPerCycle, true);return decisions;else if (mission.EnvRef.Balls0.PositionMm.Z = 950)/球门右外rightGoal = new xna.Vector3(1350f, 0f, -200);dirbBtoG = DirBToG(ballPt, ri

17、ghtGoal);/球到右球门方向tempPt.X = ballPt.X - (float)(r * Math.Cos(dirbBtoG);tempPt.Z = ballPt.Z - (float)(r * Math.Sin(dirbBtoG);StrategyHelper.Helpers.Dribble(ref decisions0, mission.TeamsRefteamId.Fishes0,tempPt, dirFish, 5, 10, 200, 14, 8, 14, mission.CommonPara.MsPerCycle, true);return decisions;#endr

18、egion#region/防守策略else if (mission.EnvRef.Balls0.PositionMm.X = -950if (dirFish = -950tempPt.X = ballPt.X - (float)(r * Math.Cos(dirFish);tempPt.Z = ballPt.Z - (float)(r * Math.Sin(dirFish);StrategyHelper.Helpers.Dribble(ref decisions0, mission.TeamsRefteamId.Fishes0,tempPt, dirFish, 5, 10, 200, 14,

19、8, 14, mission.CommonPara.MsPerCycle, true);return decisions;else if (mission.EnvRef.Balls0.PositionMm.X = -950tempPt.X = ballPt.X - (float)(r * Math.Cos(dirFish);tempPt.Z = ballPt.Z - (float)(r * Math.Sin(dirFish);StrategyHelper.Helpers.Dribble(ref decisions0, mission.TeamsRefteamId.Fishes0,tempPt,

20、 dirFish, 5, 10, 200, 14, 8, 14, mission.CommonPara.MsPerCycle, true);return decisions;else if (mission.EnvRef.Balls0.PositionMm.X 700 | mission.EnvRef.Balls0.PositionMm.Z 0 dirbBtoG = DirBToG(ballPt, rightGoal);/球到右球门方向tempPt.X = ballPt.X - (float)(r * Math.Cos(dirbBtoG);tempPt.Z = ballPt.Z - (floa

21、t)(r * Math.Sin(dirbBtoG);StrategyHelper.Helpers.Dribble(ref decisions0, mission.TeamsRefteamId.Fishes0,tempPt, dirFish, 5, 10, 150, 14, 8, 14, mission.CommonPara.MsPerCycle, true);return decisions;elserightGoal = new xna.Vector3(1350f, 0f, 0f);dirbBtoG = DirBToG(ballPt, rightGoal);/球到右球门方向tempPt.X

22、= ballPt.X - (float)(r * Math.Cos(dirbBtoG);tempPt.Z = ballPt.Z - (float)(r * Math.Sin(dirbBtoG);StrategyHelper.Helpers.Dribble(ref decisions0, mission.TeamsRefteamId.Fishes0,tempPt, dirbBtoG, 5, 10, 150, 14, 8, 14, mission.CommonPara.MsPerCycle, true);return decisions;#endregion#endregion#endregion

23、#region/右半场策略if (mission.TeamsRefteamId.Para.MyHalfCourt = HalfCourt.RIGHT)#region/进攻策略if (mission.EnvRef.Balls0.PositionMm.Z -135tempPt.X = ballPt.X - (float)(r * Math.Cos(dirFish);tempPt.Z = ballPt.Z - (float)(r * Math.Sin(dirFish);StrategyHelper.Helpers.Dribble(ref decisions0, mission.TeamsReftea

24、mId.Fishes0,tempPt, dirFish, 5, 10, 150, 14, 8, 14, mission.CommonPara.MsPerCycle, true);return decisions;else if (mission.EnvRef.Balls0.PositionMm.X -200 tempPt.X = ballPt.X - (float)(r * Math.Cos(dirFish);tempPt.Z = ballPt.Z - (float)(r * Math.Sin(dirFish);StrategyHelper.Helpers.Dribble(ref decisi

25、ons0, mission.TeamsRefteamId.Fishes0,tempPt, dirFish, 5, 10, 150, 14, 8, 14, mission.CommonPara.MsPerCycle, true);return decisions;else if (mission.EnvRef.Balls0.PositionMm.Z = -500)tempPt.X = ballPt.X - (float)(r * Math.Cos(dirFish);tempPt.Z = ballPt.Z - (float)(r * Math.Sin(dirFish);StrategyHelper

26、.Helpers.Dribble(ref decisions0, mission.TeamsRefteamId.Fishes0,tempPt, dirFish, 5, 10, 170, 14, 14, 8, mission.CommonPara.MsPerCycle, true);return decisions;else if (mission.EnvRef.Balls0.PositionMm.Z = 200 tempPt.X = ballPt.X - (float)(r * Math.Cos(dirFish);tempPt.Z = ballPt.Z - (float)(r * Math.S

27、in(dirFish);StrategyHelper.Helpers.Dribble(ref decisions0, mission.TeamsRefteamId.Fishes0,tempPt, dirFish, 5, 10, 200, 14, 8, 8, mission.CommonPara.MsPerCycle, true);return decisions;else if (mission.EnvRef.Balls0.PositionMm.X = 200dirbBtoG = DirBToG(ballPt, rightGoal);/球到右球门方向tempPt.X = ballPt.X -

28、(float)(r * Math.Cos(dirbBtoG);tempPt.Z = ballPt.Z - (float)(r * Math.Sin(dirbBtoG);StrategyHelper.Helpers.Dribble(ref decisions0, mission.TeamsRefteamId.Fishes0,tempPt, dirFish, 5, 10, 150, 14, 8, 14, mission.CommonPara.MsPerCycle, true);return decisions;elserightGoal = new xna.Vector3(1350f, 0f, 0

29、f);dirbBtoG = DirBToG(ballPt, rightGoal);/球到右球门方向tempPt.X = ballPt.X - (float)(r * Math.Cos(dirbBtoG);tempPt.Z = ballPt.Z - (float)(r * Math.Sin(dirbBtoG);StrategyHelper.Helpers.Dribble(ref decisions0, mission.TeamsRefteamId.Fishes0,tempPt, dirbBtoG, 5, 10, 150, 14, 8, 14, mission.CommonPara.MsPerCy

30、cle, true);return decisions;#endregion#endregionreturn decisions;#region/球到球门的方向public float DirBToG(xna.Vector3 ballPt, xna.Vector3 goalPt)float dirBToG = 0;if (goalPt.X = 1350)dirBToG = (float)Math.Atan(ballPt.Z - goalPt.Z) / (ballPt.X - goalPt.X);if (goalPt.X = -1350)dirBToG = (float)Math.Atan(ba

31、llPt.Z - goalPt.Z) / (ballPt.X - goalPt.X);if (dirBToG = 0)dirBToG = -3.14f + dirBToG;elsedirBToG = 3.14f + dirBToG;return dirBToG;#endregion#region /角度差计算public float CalVectorAngleDiff(xna.Vector3 BaseEmitPostion, xna.Vector3 BaseTailPositon, float AngleOfCalVector)xna.Vector3 AngleOfBase = BaseTailPositon - BaseEmitPostion;float AngleDiff = AngleOfCalVector - (float)Math.Atan2(AngleOfBase.Z, AngleOfBase.X);/当角度.进行处理使之范围处于-if (AngleDiff Math.PI)AngleDiff = AngleDiff - (float)Math.PI * 2;return AngleDiff;#endregion

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报