public void WriteLineToTxtFile_HasWrittenToFileCorrectly_Equal() { #region ResultString ChessBoard board = new ChessBoard(); board.InitializeGame(); string result; result = Eval.BasePawnValue.ToString() + " " + Eval.BaseBishopValue.ToString() + " " + Eval.BaseKnightValue.ToString() + " " + Eval.BaseRookValue + " " + Eval.BaseQueenValue.ToString() + " " + Eval.BaseKingValue.ToString() + " " + Eval.CheckMateConstant.ToString() + " " + Eval.LateGameBonusRooks.ToString() + " " + Eval.LateGameBonusKnights.ToString() + " " + Eval.LateGameBonusBishop.ToString() + " " + Eval.FactorRook.ToString() + " " + Eval.FactorBishop.ToString() + " " + Eval.FactorKnight.ToString() + " "; foreach (int i in board.WhitePawn.PositionValues) { result += i + " "; } foreach (int i in board.WhiteKnight.PositionValues) { result += i + " "; } foreach (int i in board.WhiteBishop.PositionValues) { result += i + " "; } foreach (int i in board.WhiteRook.PositionValues) { result += i + " "; } foreach (int i in board.WhiteQueen.PositionValues) { result += i + " "; } foreach (int i in board.WhiteKing.PositionValues) { result += i + " "; } foreach (int i in board.BlackPawn.PositionValues) { result += i + " "; } foreach (int i in board.BlackKnight.PositionValues) { result += i + " "; } foreach (int i in board.BlackBishop.PositionValues) { result += i + " "; } foreach (int i in board.BlackRook.PositionValues) { result += i + " "; } foreach (int i in board.BlackQueen.PositionValues) { result += i + " "; } foreach (int i in board.BlackKing.PositionValues) { result += i + " "; } #endregion string fileName = "TxtFile.txt"; string path = Path.GetFullPath(fileName); using (File.Create(fileName)){} Bayes.WriteLineToTxtFile(path, result); string[] readText = File.ReadAllLines(path); File.Delete(fileName); Assert.Equal(result, readText.Last <string>()); }
public void Handler(string inputString) { Trace.WriteLine("Handler() input: " + inputString); string[] input = inputString.Split(' '); switch (input[0]) { case "protover": protover = Convert.ToInt32(input[1]); if (protover == 2) { Console.WriteLine("feature colors=0 done=1"); } break; case "new": chessBoard.InitializeGame(); Bayes.HandleEvalConfig(out depth, Path.GetFullPath("config.txt")); if (Bayes.TuneEvalValues) { Bayes.ModifyValues(Bayes.RandomizeEvalConfiguration(Bayes.CreateOutputString(chessBoard)), chessBoard); } else { Bayes.ModifyValues(Bayes.FindBestEvalConfiguration(Path.GetFullPath("log.txt")), chessBoard); } isFirstGo = true; break; case "level": movesPerMinutes = Convert.ToInt32(input[1]); minutes = Convert.ToInt32(input[2]); break; case "accepted": switch (input[1]) { case "colors": isAcceptedColors = true; break; case "time": isAcceptedTime = true; break; } break; case "quit": System.Environment.Exit(0); break; case "force": force = true; break; case "rejected": throw new Exception("Feature '" + input[1] + "' was not accepted."); case "result": if (Bayes.TuneEvalValues) { Bayes.RepetetionPerEvalConfiguration--; if (Bayes.RepetetionPerEvalConfiguration == 0) { Bayes.Seed++; Bayes.RepetetionPerEvalConfiguration = 10; } } Bayes.WriteToEvalConfig(Path.GetFullPath("config.txt"), depth); switch (input[1]) { case "1-0": chessBoard.State = ChessBoardGameState.WhiteMate; Bayes.WriteLineToTxtFile(Path.GetFullPath("log.txt"), Bayes.CreateEvalConfigurationStringLogFormat(true, Bayes.CreateOutputString(chessBoard))); break; case "0-1": chessBoard.State = ChessBoardGameState.BlackMate; Bayes.WriteLineToTxtFile(Path.GetFullPath("log.txt"), Bayes.CreateEvalConfigurationStringLogFormat(false, Bayes.CreateOutputString(chessBoard))); break; case "1/2-1/2": chessBoard.State = ChessBoardGameState.Draw; Bayes.WriteLineToTxtFile(Path.GetFullPath("log.txt"), Bayes.CreateEvalConfigurationStringLogFormat(false, Bayes.CreateOutputString(chessBoard))); break; case "*": Console.WriteLine("Error (unknown command): " + input[0]); break; } break; case "go": if (isFirstGo == true) { force = false; DoMove(); isFirstGo = false; } else { Console.WriteLine("Error (Not handled): go"); } break; default: if (STRINGMOVE_FORMAT.IsMatch(input[0])) { Logger.OutputMove(input[0]); ColoredBitBoard bitBoardMoveRecived = _winboardConverter.ConvertStringMoveToBitBoard(input[0]); chessBoard.Update(bitBoardMoveRecived); whiteTurn = !whiteTurn; if (force == false) { DoMove(); } } else { Console.WriteLine("Error (unknown command): " + input[0]); } break; } }