コード例 #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));
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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....");
        }
コード例 #5
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));
        }
コード例 #6
0
        public void evaluateBoard(BoardState expected, string playerDir, string enemyDir, string rawBoard)
        {
            Board b = SnakeTestUtils.generateBoard(rawBoard, playerDir, enemyDir);

            Assert.AreEqual(expected, b.evaluateBoard());
        }