示例#1
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));
        }
示例#2
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));
        }
示例#3
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());
        }
示例#4
0
 internal static string CreateCommandSimulateEnemy(SnakeBoard board, MovesToSimulate simMoves)
 {
     return(CreateCommandSimulate(board, simMoves, JProtocol.simEnemyMove));
 }
示例#5
0
 internal static string CreateCommandSimulateBoth(SnakeBoard board, MovesToSimulate simMoves)
 {
     return(CreateCommandSimulate(board, simMoves, Actions.simMove));
 }
示例#6
0
        private SnakeBoard HandleSimulateMove(SnakeBoard board, MovesToSimulate simMoves, string request)
        {
            string response = SendCommandReceiveMessage(request);

            return(SnakeJsonHandler.ParseResponseSimulate(response));
        }