示例#1
0
文件: Program.cs 项目: Cakez0r/AiCtf
 public void Initialize(CtfGameRules rules, int yourTeamId)
 {
 }
示例#2
0
 public void Initialize(CtfGameRules rules, int yourTeamId)
 {
 }
示例#3
0
文件: CtfGame.cs 项目: Cakez0r/AiCtf
        /// <summary>
        /// Create a ctf game
        /// </summary>
        /// <param name="rules">The rules of this game</param>
        /// <param name="ais">All AIs that will be competing in this game</param>
        public CtfGame(CtfGameRules rules, IList<ICtfAi> ais)
        {
            if (rules == null)
            {
                throw new ArgumentNullException("rules");
            }

            if (ais == null)
            {
                throw new ArgumentNullException("ais");
            }

            SpawnPositions = new Dictionary<int, Vector2>();
            Rules = rules;
            States = new List<CtfGameState>(Rules.TurnLimit);

            //Calculate spacing of objects for spawn positions
            float teamSpacing = MathHelper.TwoPi / ais.Count;
            float shipSpacing = MathHelper.TwoPi / Rules.ShipsPerTeam;

            float flagRadius = Rules.ArenaRadius - (2 * Rules.ShipRadius) - Rules.FlagRadius;

            CtfGameState initialState = new CtfGameState();

            initialState.Teams = new List<Team>(ais.Count);
            int teamIndex = 0;

            //Initialise all the teams
            foreach (ICtfAi ai in ais)
            {
                var team = new Team()
                {
                    Name = ai.Name ?? "Unnamed AI"
                };

                team.Flag = new Flag()
                {
                    Bounds = new BoundingCircle(Vector2.FromPolar(flagRadius, teamSpacing * teamIndex), Rules.FlagRadius),
                    Owner = team.Id,
                };
                SpawnPositions[team.Flag.Id] = team.Flag.Position;

                m_ais[team.Id] = ai;

                team.Ships = new List<Ship>();

                for (int i = 0; i < rules.ShipsPerTeam; i++)
                {
                    var ship = new Ship()
                    {
                        Bounds = new BoundingCircle(team.Flag.Position + Vector2.FromPolar(Rules.FlagRadius + Rules.ShipRadius, i * shipSpacing), Rules.ShipRadius),
                        Owner = team.Id,
                        Rotation = (i * shipSpacing),
                    };

                    SpawnPositions[ship.Id] = ship.Position;
                    m_lastFireTurns[ship.Id] = int.MinValue + 1;

                    team.Ships.Add(ship);
                }

                team.Projectiles = new List<Projectile>();

                initialState.Teams.Add(team);

                teamIndex++;
            }

            States.Add(initialState);
            m_currentState = initialState;
        }