Exemplo n.º 1
0
        /// <summary>
        /// Returns the state of the board.
        /// </summary>
        public BoardState EvaluateBoard(SnakeBoard board)
        {
            string request  = SnakeJsonHandler.CreateCommandEvaluate(board);
            string response = SendCommandReceiveMessage(request);

            return(SnakeJsonHandler.ParseResponseEvaluate(response));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the possible moves for both the player and the enemy, based off directions only.
        /// </summary>
        public PossibleMoves GetPossibleMoves(SnakeBoard board)
        {
            string request  = SnakeJsonHandler.CreateCommandPossibleMoves(board);
            string response = SendCommandReceiveMessage(request);

            return(SnakeJsonHandler.ParseResponsePossibleMoves(response));
        }
Exemplo n.º 3
0
        internal static string CreateCommandEvaluate(SnakeBoard board)
        {
            JObject jsonCommand = new JObject(
                new JProperty(Constants.Fields.action, Actions.evalBoard),
                new JProperty(JProtocol.board, SerializeBoard(board))
                );

            //Console.WriteLine("Evaluate command: \n" + jsonCommand + "\n");
            return(jsonCommand.ToString());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns a board where the moves have been applied.
        /// </summary>
        public SnakeBoard SimulateMoves(SnakeBoard board, string playerMove, string enemyMove)
        {
            MovesToSimulate simMoves = new MovesToSimulate()
            {
                playerMove = playerMove, enemyMove = enemyMove
            };
            string request = SnakeJsonHandler.CreateCommandSimulateBoth(board, simMoves);

            return(HandleSimulateMove(board, simMoves, request));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Simulate a move where only the enemy moves.
        /// </summary>
        /// <param name="board">The board which the move is applied to.</param>
        /// <param name="move">The direction in which you want to simulate a move.</param>
        /// <returns>The board where the move has been applied.</returns>
        public SnakeBoard SimulateEnemyMove(SnakeBoard board, string move)
        {
            MovesToSimulate simMoves = new MovesToSimulate()
            {
                enemyMove = move
            };
            string request = SnakeJsonHandler.CreateCommandSimulateEnemy(board, simMoves);

            return(HandleSimulateMove(board, simMoves, request));
        }
Exemplo n.º 6
0
        /*
         * internal static string CreateDirectionCommand(string direction) {
         *  JObject jsonCommand = new JObject(
         *      new JProperty(JProtocol.dir, direction)
         *      );
         *  Console.WriteLine("Direction Command: \n" + jsonCommand + "\n");
         *  return jsonCommand.ToString();
         * }
         */

        internal static string CreateCommandPossibleMoves(SnakeBoard board)
        {
            JObject jsonCommand = new JObject(
                new JProperty(Constants.Fields.action, Actions.getPossMoves),
                new JProperty(JProtocol.player, board.GetPlayerDirection()),
                new JProperty(JProtocol.enemy, board.GetEnemyDirection())
                );

            //Console.WriteLine("PossibleMoves Command: \n" + jsonCommand + "\n");

            return(jsonCommand.ToString());
        }
 /// <summary>
 /// Constructor for SnakeBoard which makes a deep copy of the passed board.
 /// </summary>
 /// <param name="board">Board to be deep copied.</param>
 public SnakeBoard(SnakeBoard board)
 {
     player = new Placement()
     {
         x = board.player.x, y = board.player.y, dir = board.player.dir
     };
     enemy = new Placement()
     {
         x = board.enemy.x, y = board.enemy.y, dir = board.enemy.dir
     };
     blocked = board.blocked.Clone() as bool[, ];
 }
Exemplo n.º 8
0
        private static string CreateCommandSimulate(SnakeBoard board, MovesToSimulate simMoves, string action)
        {
            JObject jsonCommand = new JObject(
                new JProperty(Constants.Fields.action, action),
                JObject.FromObject(simMoves, serializer).Children(),
                new JProperty(JProtocol.board, SerializeBoard(board))
                );

            //Console.WriteLine("Simulate Command: \n" + jsonCommand + "\n");

            return(jsonCommand.ToString());
            //return FixVariableNamings(jsonCommand.ToString());
        }
Exemplo n.º 9
0
        private static JObject SerializeBoard(SnakeBoard board)
        {
            JObject jObject = new JObject(
                new JProperty(JProtocol.player,
                              JObject.FromObject(board.player)),
                new JProperty(JProtocol.enemy,
                              JObject.FromObject(board.enemy))
                );

            //if (includeBlocked)
            jObject.Add(new JProperty(JProtocol.blocked, JArray.FromObject(board.GetBlockedList(false))));
            return(jObject);
        }
Exemplo n.º 10
0
 private void ExtractOldBoardInfo(SnakeBoard board)
 {
     if (board != null)
     {
         for (int x = 0; x < boardWidth; x++)
         {
             for (int y = 0; y < boardHeight; y++)
             {
                 blocked[x, y] = board.blocked[x, y];
             }
         }
     }
 }
Exemplo n.º 11
0
 internal static string CreateCommandSimulateEnemy(SnakeBoard board, MovesToSimulate simMoves)
 {
     return(CreateCommandSimulate(board, simMoves, JProtocol.simEnemyMove));
 }
Exemplo n.º 12
0
 internal static string CreateCommandSimulateBoth(SnakeBoard board, MovesToSimulate simMoves)
 {
     return(CreateCommandSimulate(board, simMoves, Actions.simMove));
 }
Exemplo n.º 13
0
        private SnakeBoard HandleSimulateMove(SnakeBoard board, MovesToSimulate simMoves, string request)
        {
            string response = SendCommandReceiveMessage(request);

            return(SnakeJsonHandler.ParseResponseSimulate(response));
        }
Exemplo n.º 14
0
        protected override void ExtractState(JObject jState)
        {
            BoardStruct boardStruct = SnakeJsonHandler.ParseResponseState(jState);

            currentBoard = new SnakeBoard(currentBoard, boardStruct);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Sends a command to restart the game.
 /// </summary>
 public new void RestartGame()
 {
     currentBoard = null;
     base.RestartGame();
 }
Exemplo n.º 16
0
 public SnakeBoard(SnakeBoard board, BoardStruct boardStruct)
 {
     ExtractOldBoardInfo(board);
     ExtractResponseInfo(boardStruct);
 }