Exemple #1
0
        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 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));
        }
Exemple #3
0
        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));
        }