private static void PrintState(FourInARowState state) { for (Int32 y = FourInARowState.RowCount - 1; y >= 0; y--) { for (Int32 x = 0, mx = FourInARowState.ColumnCount; x < mx; x++) { String text; switch (state.Get(x, y)) { case FourInARowFieldState.Cross: text = "X"; break; case FourInARowFieldState.Circle: text = "O"; break; default: text = "_"; break; } Console.Write(text); } Console.WriteLine(); } Console.WriteLine(); }
internal static FourInARowState PrepareState(String[] input) { FourInARowState result = new FourInARowState(); for (Int32 q = 0; q < FourInARowState.RowCount; q++) { String line = input[q]; for (Int32 w = 0; w < FourInARowState.ColumnCount; w++) { Char ch = line[w]; if (ch == 'x') { result.Set(w, q, FourInARowFieldState.Cross); } else if (ch == 'o') { result.Set(w, q, FourInARowFieldState.Circle); } } } return(result); }
private static void PlayFourInARowTest() { //String[] input = new[] // { // "oo.o...", // "x......", // "x......", // ".......", // ".......", // ".......", // }; //String[] input = new[] // { // "oooxooo", // "xxxoxxx", // "oooxooo", // "xxxoxxx", // "xoxoxox", // "oo.o...", // }; String[] input = new[] { "oooxooo", "xxxoxxx", "oooxooo", "xxxoxxx", "xoxoxox", "oo.o...", }; FourInARowState state = FourInARowTests.PrepareState(input); FourInARowFactory factory = new FourInARowFactory(); IGameLogic logic = factory.CreateLogic(); MiniMaxAlgorithmImproved alg = new MiniMaxAlgorithmImproved(3, factory, true); PrintState((FourInARowState)state); Int32 res = factory.CreateStateEvaluator().Evaluate(state, GamePlayer.PlayerMax); IGameMove move = alg.FindBestMove(state, GamePlayer.PlayerMax); IGameState newState = logic.MakeMove(move, state); PrintState((FourInARowState)newState); }
private static FourInARowMove Common(String[] input, IGameAlgorithm algorithm, IGameFactory gameFactory) { FourInARowState state = PrepareState(input); IGameFactory factory = gameFactory; IGameLogic logic = factory.CreateLogic(); IGameAlgorithm alg = algorithm; Int32 res = factory.CreateStateEvaluator().Evaluate(state, GamePlayer.PlayerMax); return((FourInARowMove)alg.FindBestMove(state, GamePlayer.PlayerMax)); }
private static void PlayFourInARow() { Console.BufferHeight = 8000; FourInARowFactory factory = new FourInARowFactory(); IGameLogic logic = factory.CreateLogic(); IGameAlgorithm alg = new MiniMaxWithAlfaBetaPrunningDynamic(3, factory); /// new MiniMaxWithAlfaBetaPrunningB(8, factory); // new MiniMaxAlgorithmImproved(6, factory, true); IGameState state = new FourInARowState(); while (true) { IGameMove move = alg.FindBestMove(state, GamePlayer.PlayerMax); if (null != move) { state = logic.MakeMove(move, state); } else { break; } PrintState((FourInARowState)state); if (logic.IsFinished(state)) { break; } Int32 x = Int32.Parse(Console.ReadLine()); state = logic.MakeMove(new FourInARowMove { Column = x, State = FourInARowFieldState.Circle }, state); if (logic.IsFinished(state)) { break; } } PrintState((FourInARowState)state); }
public void TestMoveEvaluation() { String[] inputA = new[] { ".x.o...", ".x.....", ".......", ".......", ".......", "......." }; String[] inputB = new[] { "...o.x.", ".....x.", ".......", ".......", ".......", "......." }; FourInARowState stateA = PrepareState(inputA); FourInARowState stateB = PrepareState(inputB); FourInARowFactory factory = new FourInARowFactory(); IGameStateEvaluator evaluator = factory.CreateStateEvaluator(); Int32 rateA = evaluator.Evaluate(stateA, GamePlayer.PlayerMax); Int32 rateB = evaluator.Evaluate(stateB, GamePlayer.PlayerMax); Assert.AreEqual(rateA, rateB); rateA = evaluator.Evaluate(stateA, GamePlayer.PlayerMin); rateB = evaluator.Evaluate(stateB, GamePlayer.PlayerMin); Assert.AreEqual(rateA, rateB); }
public void TestAnotherWin() { String[] input = new[] { "oooxooo", "xxxoxxx", "oooxooo", "xxxoxxx", "xoxoxox", "oooooo.", }; FourInARowState state = PrepareState(input); FourInARowFactory factory = new FourInARowFactory(); IGameLogic logic = factory.CreateLogic(); Boolean result = logic.IsFinished(state); Assert.IsTrue(result); }