public void encodeDecodeBoard(string playerDir, string enemyDir, string rawBoard) { Board startBoard = SnakeTestUtils.generateBoard(rawBoard, playerDir, enemyDir); JSONObject jBoard = SnakeProtocolEncoder.compressBoard(startBoard); Board decodedBoard = new Board(jBoard); Assert.True(SnakeTestUtils.compareBoards(startBoard, decodedBoard)); }
public void simulateAndEvaluate(BoardState expected, string playerDir, string enemyDir, string rawBoard) { Board b = SnakeTestUtils.generateBoard(rawBoard, playerDir, enemyDir); b.playMove(new string[] { playerDir, enemyDir }); SnakeTestUtils.printBoard(b); Assert.AreEqual(expected, b.evaluateBoard()); }
public void protocolSimulateBothPlayerMove(string playerDir, string enemyDir, int pX, int pY, int eX, int eY, string rawBoard, string rawExpected) { SnakeAPIRouter router = new SnakeAPIRouter(); Board startBoard = SnakeTestUtils.generateBoard(rawBoard, playerDir, enemyDir); Board expected = SnakeTestUtils.generateBoard(rawExpected, playerDir, enemyDir, new int[] { pX, pY }, new int[] { eX, eY }); JSONObject jObj = SnakeProtocolEncoder.generateSimulateJMsg(startBoard, playerDir, enemyDir); //Debug.Log("Generated simulate move request: \n" + jObj.Print(true) + "\n"); APIMsgConclusion response = router.handleIncomingMsg(jObj.Print()); Assert.True(response.target == MsgTarget.Player); Assert.True(response.status == ResponseStatus.Success); JSONObject newJBoard = new JSONObject(response.msg); //Debug.Log("Generated simulate move response: \n" + newJBoard.Print(true) + "\n"); //JSONObject newJBoard = jResponse.GetField(Constants.JProtocol.board); Board newBoard = new Board(newJBoard); // startBoard.printBoard(); // newBoard.printBoard(); Assert.True(SnakeTestUtils.compareBoards(expected, newBoard)); }
public void getPossibleMovesTest(string playerDir, string enemyDir, string[] playerExpected, string[] enemyExpected) { List <string> playerExpectedList = playerExpected.ToList(); List <string> enemyExpectedList = enemyExpected.ToList(); SnakeAPIRouter router = new SnakeAPIRouter(); //Board startBoard = SnakeTestUtils.generateBoard(rawBoard, playerDir, enemyDir); JSONObject jMsg = SnakeProtocolEncoder.generateGetPossMovesJMsg(playerDir, enemyDir); APIMsgConclusion response = router.handleIncomingMsg(jMsg.Print()); Assert.True(response.target == MsgTarget.Player); Assert.True(response.status == ResponseStatus.Success); Debug.Log(response.msg); PossibleMoves moves = extractPossibleMoves(new JSONObject(response.msg)); Assert.True(SnakeTestUtils.comparePossibleMoves(playerExpectedList, moves.playerMoves)); Assert.True(SnakeTestUtils.comparePossibleMoves(enemyExpectedList, moves.enemyMoves)); Debug.Log("True...."); }
private static void simulateMoveTest(string playerDir, string enemyDir, string rawBoard, string rawExpected) { Board expected = SnakeTestUtils.generateBoard(rawExpected, playerDir, enemyDir); Board newBoard = SnakeTestUtils.generateBoard(rawBoard, playerDir, enemyDir); if (playerDir.Equals("")) { newBoard.playSingleMove(enemyDir, false); } else if (enemyDir.Equals("")) { newBoard.playSingleMove(playerDir, true); } else { newBoard.playMove(new string[] { playerDir, enemyDir }); } SnakeTestUtils.printGrid(expected.getBlockedGrid()); SnakeTestUtils.printGrid(newBoard.getBlockedGrid()); Assert.True(SnakeTestUtils.compareBoards(newBoard, expected)); }
public void evaluateBoard(BoardState expected, string playerDir, string enemyDir, string rawBoard) { Board b = SnakeTestUtils.generateBoard(rawBoard, playerDir, enemyDir); Assert.AreEqual(expected, b.evaluateBoard()); }