/// <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)); }
/// <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)); }
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()); }
internal static string CreateCommandSimulateEnemy(SnakeBoard board, MovesToSimulate simMoves) { return(CreateCommandSimulate(board, simMoves, JProtocol.simEnemyMove)); }
internal static string CreateCommandSimulateBoth(SnakeBoard board, MovesToSimulate simMoves) { return(CreateCommandSimulate(board, simMoves, Actions.simMove)); }
private SnakeBoard HandleSimulateMove(SnakeBoard board, MovesToSimulate simMoves, string request) { string response = SendCommandReceiveMessage(request); return(SnakeJsonHandler.ParseResponseSimulate(response)); }