示例#1
0
        /// <summary>
        /// Copy the PlayerWorldState pws into Board data format.
        /// </summary>
        public Board(PlayerWorldState pws)
        {
            Width  = pws.GridWidthInSquares;
            Height = pws.GridHeightInSquares;
            B      = new int[Width, Height];

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    if (pws[x, y].Contents == GridSquare.Empty)
                    {
                        B[x, y] = Empty;
                    }
                    else if (pws[x, y].Contents == GridSquare.Impassable)
                    {
                        B[x, y] = Impassable;
                    }
                    else if (pws[x, y].Contents == GridSquare.ActiveColony)
                    {
                        B[x, y] = Active(pws[x, y].Player);
                    }
                    else if (pws[x, y].Contents == GridSquare.PassiveColony)
                    {
                        B[x, y] = Passive(pws[x, y].Player);
                    }
                    else
                    {
                        throw (new Exception("Illegal GridSquare Contents in Board()"));
                    }
                }
            }
        }
        //initiakise gameboard to specifed size
        public int[,] InitialiseGameBoard(PlayerWorldState WorldState)
        {
            int[,] newMap = new int[WorldState.GridWidthInSquares, WorldState.GridHeightInSquares];

            for (int x = 0; x < WorldState.GridWidthInSquares; x++)
            {
                for (int y = 0; y < WorldState.GridHeightInSquares; y++)
                {
                    switch (WorldState[x, y].Contents)
                    {
                    case GridSquare.ContentType.Snail:
                        newMap[x, y] = WorldState[x, y].Player;
                        break;

                    case GridSquare.ContentType.Trail:
                        newMap[x, y] = -WorldState[x, y].Player;
                        break;

                    case GridSquare.ContentType.Impassable:
                        newMap[x, y] = IMPASSABLE;
                        break;

                    default:
                        newMap[x, y] = EMPTY;
                        break;
                    }
                }
            }
            return(newMap);
        }
示例#3
0
        /// <summary>
        /// This is the function that is called to get your moves for each turn.
        /// </summary>
        /// <param name="igrid">This contains the board information - note that this contains GridSquare information only for squares I can see</param>
        /// <returns>A Command for this turn - Up, Down, Left or Right for my tank.</returns>
        public override ICommand GetTurnCommands(IPlayerWorldState igrid)
        {
            MyWorldState = (PlayerWorldState)igrid; // the board
            UpdateMyMap();                          // update my map with the new squares seen
            fsm.Initialize(MyWorldState, MyMap);

            //WriteTrace("MyWorldState:");
            //WriteTrace(MyWorldState);

            WriteTrace("\r\nMyMap:");
            WriteTrace(MyMapToString());

            fsm.DoState();

            WriteTrace("\r\nMyPath:");
            WriteTrace(fsm.aStar.SearchToString(fsm.aStar.MyPath));

            if (fsm.GetCommand() != null)
            {
                WriteTrace(fsm.GetCommand().ToString());
            }
            else
            {
                WriteTrace("null Command");
            }

            return(fsm.GetCommand());
        }
        //returns estimated result of the board
        public double GetEstimatedResult(GameBoard lastBoard, PlayerWorldState WorldState)
        {
            Vector2 <int> player = GetCoordinatesOfID(MyAISnailID);
            Vector2 <int> enemy  = GetCoordinatesOfID(EnemyAiSnailID);

            double TileScore = 0.0;

            TileScore += 1.0 * GetAdvantage();



            if (WorldState[enemy.x, enemy.y].Contents == EMPTY)
            {
                TileScore -= DistanceToEnemy(player.y, WorldState[enemy.x, enemy.y].Y);
                TileScore -= DistanceToEnemy(player.x, WorldState[enemy.x, enemy.y].X);
            }

            if (TileScore > 1000.0)
            {
                TileScore = 1000.0;
            }
            if (TileScore < -1000.0)
            {
                TileScore = -1000.0;
            }

            return(TileScore);
        }
示例#5
0
        public override ICommand GetTurnCommands(IPlayerWorldState igrid)
        {
            myWorldState = (PlayerWorldState)igrid;
            Debug.WriteLine(myWorldState);

            return(null); // Return the command “Do nothing at all!”
        }
示例#6
0
        /// <summary>
        /// Return the commands for this turn
        /// </summary>
        public override ICommand GetTurnCommands(IPlayerWorldState igrid)
        {
            myWorldState = (PlayerWorldState)igrid;

            // initialise my own copy of Board
            TheBoard = new Board(myWorldState);

            // reset the counter of boards evaluated
            BoardsEvaluated = 0;

            // No BestMove known yet - BestMove == null corresponds to passing the turn
            BestMove = new Move();

            // Search for the best move
            double alpha = GetGameResultDepthLimitedAlphaBeta(this.ID, 0, -1000.0, 1000.0);

            // Display the best move so far for debugging purposes
            if (BestMove.TheCommand == null)
            {
                WriteTrace("Best Move - PASS - after " + BoardsEvaluated + " boards");
            }
            else
            {
                WriteTrace("Best Move - " + BestMove + " - after " + BoardsEvaluated + " boards");
            }

            // return the move
            return(BestMove.TheCommand);
        }
        //creates copy of player world state
        public GameBoard(PlayerWorldState WorldState)
        {
            MyAISnailID     = WorldState.ID;
            boardStateArray = InitialiseGameBoard(WorldState);

            if (WorldState.ID == 1)
            {
                playerStartPostition = new Vector2 <int>(0, 0);
            }
            else
            {
                playerStartPostition = new Vector2 <int>(WorldState.GridWidthInSquares - 1, WorldState.GridHeightInSquares - 1);
            }
        }
        public override ICommand GetTurnCommands(IPlayerWorldState igrid)
        {
            MyWorldState = (PlayerWorldState)igrid;

            UpdateMyMap(); // update my "map" of squares seen to date

            // Write all of the properties of this player which are inherited from BasePlayer to the Trace Window
            WriteTrace("this.AITimePerGame: " + this.AITimePerGame);
            WriteTrace("this.AITimePerTurn: " + this.AITimePerTurn);
            WriteTrace("this.CPUTimeUsedSeconds: " + this.CPUTimeUsedSeconds);
            WriteTrace("this.ID: " + this.ID);
            WriteTrace("this.MaxNumOverTimeAITurns: " + this.MaxNumOverTimeAITurns);
            WriteTrace("this.MaxNumTurns: " + this.MaxNumTurns);
            WriteTrace("this.Name: " + this.Name);
            WriteTrace("this: " + this);

            // Write all of the properties of this player's PlayerWorldState to the Trace Window
            WriteTrace("MyWorldState.CanSee(PlayerWorldState.Facing.Up,5,0,7,4,mygrid): " + MyWorldState.CanSee(PlayerWorldState.Facing.Up, 5, 0, 7, 4, MyMap));
            WriteTrace("MyWorldState.EmptySquaresSeen: " + MyWorldState.EmptySquaresSeen);
            WriteTrace("MyWorldState.GridHeightInSquares: " + MyWorldState.GridHeightInSquares);
            WriteTrace("MyWorldState.GridWidthInSquares: " + MyWorldState.GridWidthInSquares);
            WriteTrace("MyWorldState.ID: " + MyWorldState.ID);
            WriteTrace("MyWorldState.Kills: " + MyWorldState.Kills);
            WriteTrace("MyWorldState.MaximumVisionDistance: " + MyWorldState.MaximumVisionDistance);
            WriteTrace("MyWorldState.MyFacing: " + MyWorldState.MyFacing);
            WriteTrace("MyWorldState.MyGridSquare: " + MyWorldState.MyGridSquare);
            WriteTrace("MyWorldState.MyVisibleSquares: ");
            foreach (GridSquare gs in MyWorldState.MyVisibleSquares)
            {
                WriteTrace(gs);
            }
            WriteTrace("MyWorldState.PlayerCount: " + MyWorldState.PlayerCount);
            WriteTrace("MyWorldState.RockSquaresSeen: " + MyWorldState.RockSquaresSeen);
            WriteTrace("MyWorldState.Score: " + MyWorldState.Score);
            WriteTrace("MyWorldState.ScorePerEmptySquareSeen: " + MyWorldState.ScorePerEmptySquareSeen);
            WriteTrace("MyWorldState.ScorePerOpposingTankDestroyed: " + MyWorldState.ScorePerOpposingTankDestroyed);
            WriteTrace("MyWorldState.ScorePerRockSquareSeen: " + MyWorldState.ScorePerRockSquareSeen);
            WriteTrace("MyWorldState.ShotsFired: " + MyWorldState.ShotsFired);
            WriteTrace("MyWorldState: " + MyWorldState);
            WriteTrace("MyWorldState.TurnNumber: " + MyWorldState.TurnNumber);

            WriteTrace("My Map:");
            WriteTrace(MyMapToString());

            // the command
            Command c = new Command(Command.Move.Up, true); // move up and shoot

            return(c);
        }
示例#9
0
        public override ICommand GetTurnCommands(IPlayerWorldState igrid)
        {
            //the Board
            WorldState = (PlayerWorldState)igrid;

            // Search for the best move
            Negamax NM = new Negamax(-1000.0, 1000.0, MaxDepth);

            // Make a working copy of the board, with me about to move
            GameBoard = new GameBoard(WorldState);

            // No BestMove known yet - BestMove == null corresponds to passing the turn
            BestMove = null;

            double alpha = NM.NegaMaxSearchFunction(GameBoard, 0, -1000.0, 1000.0, WorldState);

            BestMove = NM.NegaBest;

            return(BestMove.Com);
        }
示例#10
0
        /// <summary>
        /// Initialize the class with the current World State and Map of the grid.
        /// </summary>
        public void Initialize(PlayerWorldState pws, PathSquare[,] map)
        {
            this.MyWorldState = pws;
            this.MyMap        = map;
            aStar.Initialize(pws, map);

            // if is the first round, finds an unseen square to go to
            if (!bInit)
            {
                bInit = true;
                FindUnseenSquare();
            }

            // if in battle and the target is destroyed, leave Battle state
            if (bInBattle && (KillCount < MyWorldState.Kills || ShootCount >= MaxShootTimes))
            {
                bInBattle        = false;
                TargetTankSquare = null;
                MyCommand        = null;
                ShootCount       = 0;
            }
        }
示例#11
0
        public override ICommand GetTurnCommands(IPlayerWorldState igrid)
        {
            myWorldState = (PlayerWorldState)igrid;
            // bot can only move, but not shoot
            // 0 - Up, 1-Down, 2- Left, 3-Right, 4-RotateLeft, 5-RotateRight, 6-Stay
            Random rand      = new Random();
            int    direction = rand.Next(7);

            for (int i = 0; i < myWorldState.MyVisibleSquares.Count; i++)
            {
                WriteTrace(myWorldState.MyVisibleSquares[i] + " ");
            }

            //WriteTrace("ScoreEmptySquare " + myWorldState.ScorePerEmptySquareSeen);
            //WriteTrace("ScoreTankDestroyed " + myWorldState.ScorePerOpposingTankDestroyed);
            //WriteTrace("ScoreRockSquare " + myWorldState.ScorePerRockSquareSeen);

            switch (direction)
            {
            case 0: return(new Command(Command.Move.Up, false));

            case 1: return(new Command(Command.Move.Down, false));

            case 2: return(new Command(Command.Move.Left, false));

            case 3: return(new Command(Command.Move.Right, false));

            case 4: return(new Command(Command.Move.RotateLeft, false));

            case 5: return(new Command(Command.Move.RotateRight, false));

            case 6: return(new Command(Command.Move.Stay, false));
            }

            return(null);
        }
示例#12
0
 public void Initialize(PlayerWorldState pws, PathSquare[,] map)
 {
     this.MyWorldState = pws;
     this.MyMap        = map;
 }
示例#13
0
 public GridSquare GetMyLocation(PlayerWorldState state)
 {
     Debug.WriteLine(state.MyGridSquare);
     return(null);
 }
示例#14
0
        public double NegaMaxSearchFunction(GameBoard GameBoard, int Depth, double AlphaValue, double BetaValue, PlayerWorldState WorldState)
        {
            List <Move> moves = GameBoard.GetMoves(GameBoard.MyAISnailID, GameBoard.MyAISnailTrailID);

            if (Depth == MaxDepth)
            {
                //returns estimated guess of best score for board
                return(GameBoard.GetEstimatedResult(GameBoard, WorldState));
            }

            foreach (Move m in moves)
            {
                if (AlphaValue >= BetaValue)
                {
                    //cuts off search
                    return(AlphaValue);
                }

                //do move m
                GameBoard.DoMove(m);

                //minus value is current players poin of view
                double Move = -NegaMaxSearchFunction(GameBoard, Depth + 1, -BetaValue, -AlphaValue, WorldState);
                if (Move > AlphaValue)
                {
                    AlphaValue = Move;
                    if (Depth == 0)
                    {
                        //save best move from the root
                        NegaBest = m;
                    }
                }
                //undo move m
                GameBoard.UndoMove(m);
            }
            //returns alpha value
            return(AlphaValue);
        }