Example #1
0
        public async Task OppositeSymbolTest()
        {
            // Arrange
            InputPayload InputPayload = new InputPayload()
            {
                Move = 1,
                AzurePlayerSymbol = "X",
                HumanPlayerSymbol = "O",
                GameBoard         = new List <string> {
                    "X", "O", "?", "?", "?", "?", "?", "?", "?"
                },
            };

            // Act
            HttpOperationResponse <object> resultObject = await _client.ProcessComplexInputWithHttpMessagesAsync(InputPayload);

            // Assert
            Assert.AreEqual(StatusCodes.Status200OK, (int)resultObject.Response.StatusCode);
            OutputPayload response = resultObject.Body as OutputPayload;

            if (response != null)
            {
                Assert.IsTrue(
                    (response.AzurePlayerSymbol == "X" && response.HumanPlayerSymbol == "O") ||
                    (response.AzurePlayerSymbol == "O" && response.HumanPlayerSymbol == "X"));
            }
            else
            {
                Assert.Fail("Expected an ExecuteMove response but didn't receive one");
            }
        }
Example #2
0
 public static void OnNext(OutputPayload data)
 {
     string where = data.subject.Substring(Logger.rootLength);
     if (Logger.IsEnabledFor(where, (LogLevel)data.type))
     {
         string when = HiResDateTime.Format(data.time);
         string what = ((LogLevel)data.type).ToString();
         string how = data.context == null ? data.format : data.context.Value.ToString(data.format);
         string ex = data.ex == null ? "" : data.ex.ToString();
         Console.WriteLine("{0}|{1}|{2}|{3}|{4}", when, where, what, how, ex);
     }
     data.context.Release();
 }
Example #3
0
        [ProducesResponseType(typeof(int), StatusCodes.Status400BadRequest)] // Tells swagger that the response format will be an int for a BadRequest (400)
        public ActionResult <OutputPayload> ProcessComplexInput([FromBody] InputPayload inputPayload)
        {
            // Ensure valid player markers, valid board
            if (!(inputPayload.ValidPlayerMarkers()) ||
                (!(TicTacToe.BoardIsValid(inputPayload.gameBoard))))
            {
                return(BadRequest(400));
            }

            // Compute response
            TicTacToe ttt = new TicTacToe(inputPayload.gameBoard,
                                          inputPayload.azurePlayerSymbol, inputPayload.humanPlayerSymbol);
            WinStatus ws = ttt.winStatus;

            // If game isn't over, get the AI's next move
            int?nextMove;

            if (ws.winner.Equals(TicTacToe.GAME_NOT_DONE_STR))
            {
                int choice = ttt.MinimaxWithPruningMove();
                ttt[TicTacToe.IndexToTuple(choice)] = inputPayload.azurePlayerSymbol;
                nextMove = choice;

                // Recalculate win status
                ws = TicTacToe.GetWinStatus(ttt.board);
            }
            else
            {
                nextMove = null;
            }

            // Assemble response payload
            OutputPayload complexOutput = new OutputPayload()
            {
                move = nextMove,
                azurePlayerSymbol = inputPayload.azurePlayerSymbol,
                humanPlayerSymbol = inputPayload.humanPlayerSymbol,
                winner            = ws.winner,
                winPositions      = (ws.winPositions == null) ? null : ws.winPositions.ConvertAll(i => i.ToString()),
                gameBoard         = TicTacToe.BoardToList(ttt.board),
            };

            return(complexOutput);
        }
Example #4
0
        public async Task TieTest()
        {
            // Arrange
            InputPayload InputPayload = new InputPayload()
            {
                Move = 7,
                AzurePlayerSymbol = "X",
                HumanPlayerSymbol = "O",
                GameBoard         = new List <string> {
                    "X", "O", "X", "X", "O", "X", "O", "X", "O"
                },
            };

            // Act
            HttpOperationResponse <object> resultObject = await _client.ProcessComplexInputWithHttpMessagesAsync(InputPayload);

            OutputPayload response = resultObject.Body as OutputPayload;

            // Assert
            Assert.IsTrue(response.Winner.Equals("tie"));
        }