コード例 #1
0
        public override void SetMobileState(int index, ref MobileState newMobileState)
        {
            if (index < Constants.TANK_COUNT)
            {
                if (newMobileState.IsActive)
                {
                    // TODO: Set the new TankState

                    return;
                }
                else
                {
                    TankStates[index] = null;
                }
            }
            else
            {
                int bulletIndex = index - Constants.TANK_COUNT;
                if (newMobileState.IsActive)
                {
                    // TODO: Set the new BulletState
                }
                else
                {
                    BulletStates[bulletIndex] = null;
                }
            }
        }
コード例 #2
0
 public MobileState[] CloneMobileStates()
 {
     MobileState[] newMobileStates = new MobileState[MobileStates.Length];
     for (int i = 0; i < MobileStates.Length; i++)
     {
         newMobileStates[i] = MobileStates[i].Clone();
     }
     return(newMobileStates);
 }
コード例 #3
0
        public MobileState Clone()
        {
            MobileState clonedState = new MobileState
            {
                Pos      = this.Pos,
                Dir      = this.Dir,
                IsActive = this.IsActive
            };

            return(clonedState);
        }
コード例 #4
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            StringWriter  sw = new StringWriter(sb);

            sw.WriteLine("Tick: {0}. Outcome: {1}", Tick, Outcome);
            for (int i = 0; i < Constants.TANK_COUNT; i++)
            {
                int    b      = Constants.MIN_BULLET_INDEX + i;
                Tank   tank   = (Tank)Game.Current.Elements[i];
                Bullet bullet = (Bullet)Game.Current.Elements[b];

                MobileState tankState   = GetMobileState(i);
                MobileState bulletState = GetMobileState(b);
                sw.Write("t{0}.{1} [id:{2}]: ", tank.PlayerNumber, tank.Number, tank.Id);
                if (tankState.IsActive)
                {
                    sw.Write("{0} @ {1}. ", tankState.Dir, tankState.Pos);
                }
                else
                {
                    sw.Write("DEAD. ");
                }
                if (bulletState.IsActive)
                {
                    sw.WriteLine("BULLET [id:{0}]: {1} @ {2}.",
                                 Game.Current.Turns[Tick].BulletIds[i],
                                 bulletState.Dir, bulletState.Pos);
                }
                else
                {
                    sw.WriteLine("NO BULLET IN PLAY.");
                }
            }
            sw.Flush();
            return(sb.ToString());
        }
コード例 #5
0
        public static bool AreGameStatesEquivalent(GameState gameState1, GameState gameState2, out string reasonDifferent)
        {
            if (gameState1.Tick != gameState2.Tick)
            {
                reasonDifferent = "Different ticks";
                return(false);
            }

            if (gameState1.Outcome != gameState2.Outcome)
            {
                reasonDifferent = "Outcomes different";
                return(false);
            }

            if (!object.Equals(gameState1.Walls, gameState2.Walls))
            {
                reasonDifferent = "Walls are different";
                return(false);
            }

            for (int i = 0; i < Constants.MOBILE_ELEMENT_COUNT; i++)
            {
                MobileState mobileState1 = gameState1.GetMobileState(i);
                MobileState mobileState2 = gameState2.GetMobileState(i);
                if (mobileState1 != mobileState2)
                {
                    Element     element     = Game.Current.Elements[i];
                    ElementType elementType = element.ElementType;
                    reasonDifferent = String.Format("{0} Element {1} different (player {2}, index {3})",
                                                    elementType, i, element.PlayerNumber, element.Number);
                    return(false);
                }
            }

            reasonDifferent = String.Empty;
            return(true);
        }
コード例 #6
0
 public override void SetMobileState(int index, ref MobileState newMobileState)
 {
     MobileStates[index] = newMobileState;
 }
コード例 #7
0
 public abstract void SetMobileState(int index, ref MobileState newMobileState);