public bool CheckForWinner(TicTacToeBoxClass.TicTacToeBox ticTacToeBox) { return(CheckForWinnerOrTie.checkForWinnerOrTie(ticTacToeBox, Setting.playerGlyph, Setting.aIGlyph) != (int)GameStatusCodes.GenResult.NoWinner); }
public void User_Moves() { var user = new User(); var correctTicTacToeBox = new TicTacToeBoxClass.TicTacToeBox( ListModule.OfSeq(new List <string>() { "x", "-2-", "-3-", "-4-", "-5-", "-6-", "-7-", "-8-", "-9-" })); var ticTacToeBox = user.Move( new TicTacToeBoxClass.TicTacToeBox(Game.makeTicTacToeBox(3)) , 1, "x", "@"); for (var i = 0; i < correctTicTacToeBox.cellCount(); i++) { Assert.Equal(correctTicTacToeBox.getGlyphAtLocation(i) , ticTacToeBox.getGlyphAtLocation(i)); } }
public void SerializeTicTacToeBox_Json() { var ticTacToeBox = new TicTacToeBoxClass .TicTacToeBox(Game.makeTicTacToeBox(3)); var example = @"{ ""board"" : [""-1-"", ""-2-"", ""-3-"", ""-4-"", ""-5-"", ""-6-"", ""-7-"", ""-8-"", ""-9-""], ""gameOver"" : ""false""}"; var converter = new JsonConverter(); var serialize = converter.SerializeTicTacToeBox(ticTacToeBox); Assert.Equal(example, serialize); }
private string PostRequest(string request, IHttpResponse httpResponse, ServerProperties serverProperties) { var game = ((TicTacToeGame) serverProperties.ServiceSpecificObjectsWrapper); var data = WebUtility.UrlDecode(request.Remove(0, request.LastIndexOf("\r\n\r\n", StringComparison.Ordinal) + 4)); var move = data.Substring(0, data.IndexOf("&", StringComparison.Ordinal)) .Replace("box=", ""); if (move.StartsWith("-") && move.EndsWith("-") && move.Length > 2) { move = move.Replace("-", ""); } var ticTacToeBox = new TicTacToeBoxClass.TicTacToeBox( ListModule.OfSeq(GetBoxValues(data))); var errorMesageCode = Game.isUserInputCorrect(ticTacToeBox, move, game.Setting.playerGlyph, game.Setting.aIGlyph); if (errorMesageCode == Translate.Blank) { ticTacToeBox = (TicTacToeBoxClass.TicTacToeBox) game.Play(ticTacToeBox, CleanInput.SanitizeHumanPickedPlace(move, 9)); } httpResponse.SendHeaders(new List <string> { "HTTP/1.1 200 OK\r\n", "Cache-Control: no-cache\r\n", "Content-Type: text/html\r\n", "Content-Length: " + GetByteCount(GameFormPage(ticTacToeBox, game, errorMesageCode, serverProperties)) + "\r\n\r\n" }); httpResponse .SendBody(GetByte(GameFormPage(ticTacToeBox, game, errorMesageCode, serverProperties)), GetByteCount(GameFormPage(ticTacToeBox, game, errorMesageCode, serverProperties))); return("200 OK"); }
private string GetRequest(IHttpResponse httpResponse) { var ticTacToeBox = new TicTacToeBoxClass.TicTacToeBox(Game.makeTicTacToeBox(3)); httpResponse.SendHeaders(new List <string> { "HTTP/1.1 200 OK\r\n", "Cache-Control: no-cache\r\n", "Content-Type: text/html\r\n", "Content-Length: " + GetByteCount(StartingFormPage(ticTacToeBox)) + "\r\n\r\n" }); httpResponse .SendBody(GetByte(StartingFormPage(ticTacToeBox)), GetByteCount(StartingFormPage(ticTacToeBox))); return("200 OK"); }
public void Ai_Moves() { var settings = new GameSettings.gameSetting(3, "x", "@" , (int)PlayerValues.playerVals.Human , false, false, false); var ai = new Ai(); var correctTicTacToeBox = new TicTacToeBoxClass.TicTacToeBox( ListModule.OfSeq(new List <string>() { "x", "x", "x", "x", "x", "x", "x", "x", "@" })); var ticTacToeBox = ai.Move( new TicTacToeBoxClass.TicTacToeBox(ListModule.OfSeq(new List <string>() { "x", "x", "x", "x", "x", "x", "x", "x", "-9-" })) , settings); for (var i = 0; i < correctTicTacToeBox.cellCount(); i++) { Assert.Equal(correctTicTacToeBox.getGlyphAtLocation(i) , ticTacToeBox.getGlyphAtLocation(i)); } }