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));
        }
예제 #2
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....");
        }