/// <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)); }
/// <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)); }
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()); }
/// <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)); }
/* * 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[, ]; }
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()); }
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); }
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]; } } } }
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)); }
protected override void ExtractState(JObject jState) { BoardStruct boardStruct = SnakeJsonHandler.ParseResponseState(jState); currentBoard = new SnakeBoard(currentBoard, boardStruct); }
/// <summary> /// Sends a command to restart the game. /// </summary> public new void RestartGame() { currentBoard = null; base.RestartGame(); }
public SnakeBoard(SnakeBoard board, BoardStruct boardStruct) { ExtractOldBoardInfo(board); ExtractResponseInfo(boardStruct); }