public void TestMakingMoves() { Board board2 = new Board(); TestingHelper.MakeSomeMoves(board2); Debug.WriteLine(board2.ToString()); }
public void TestEnPassantCapture() { Board board2 = new Board(); TestingHelper.MakeSomeMoves(board2); board2.MakeUserMove("c5d6"); Debug.WriteLine(board2.ToString()); }
public void TestCastling() { Board board2 = new Board(); TestingHelper.MakeSomeMoves(board2); board2.MakeUserMove("e1c1"); board2.MakeUserMove("e8c8"); Debug.WriteLine(board2.ToString()); }
public static void MakeSomeMoves(Board board) { List<UInt64> hashesSoFar = new List<UInt64>(); hashesSoFar.Add(board.ZobristHash); bool success; board.MakeUserMove("e2e4"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); string fenString = board.ToString(); Debug.WriteLine(fenString); board.MakeUserMove("c7c5"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); fenString = board.ToString(); Debug.WriteLine(fenString); board.MakeUserMove("g1f3"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); fenString = board.ToString(); Debug.WriteLine(fenString); board.MakeUserMove("b8c6"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); fenString = board.ToString(); Debug.WriteLine(fenString); board.MakeUserMove("d2d4"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); fenString = board.ToString(); Debug.WriteLine(fenString); board.MakeUserMove("e7e6"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); fenString = board.ToString(); Debug.WriteLine(fenString); board.MakeUserMove("c1e3"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); fenString = board.ToString(); Debug.WriteLine(fenString); board.MakeUserMove("g7g6"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); fenString = board.ToString(); Debug.WriteLine(fenString); board.MakeUserMove("d4c5"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); fenString = board.ToString(); Debug.WriteLine(fenString); board.MakeUserMove("f8g7"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); board.MakeUserMove("f1c4"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); board.MakeUserMove("g8f6"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); board.MakeUserMove("b1c3"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); board.MakeUserMove("b7b6"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); board.MakeUserMove("d1d2"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); board.MakeUserMove("c8b7"); board.MakeUserMove("e3f4"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); fenString = board.ToString(); Debug.WriteLine(fenString); success = board.MakeUserMove("d8e7"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); success = board.MakeUserMove("e4e5"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); success = board.MakeUserMove("d7d5"); if (hashesSoFar.Contains(board.ZobristHash)) { throw new InvalidOperationException("Hash Already Included!!"); } hashesSoFar.Add(board.ZobristHash); fenString = board.ToString(); Debug.WriteLine(fenString); }
static void Main(string[] args) { // variables sbyte ownSide; Board board = new Board(); Stack<BoardState> undoStack = new Stack<BoardState>(); // int depth = 6; UInt16 move; Tuple<UInt16, int, long, int> moveDepthTimeAndScore; string opponentMoveString; Console.WriteLine("Filthy Mind Chess"); Console.WriteLine(); /*********** Input opponent side ************/ while (true) { Console.Write("Choose your side (w/b): "); char opponentSideChar = Console.ReadKey().KeyChar; Console.WriteLine(); if (opponentSideChar == 'w') { ownSide = Side.Black; break; } else if (opponentSideChar == 'b') { ownSide = Side.White; break; } else { Console.WriteLine("Invalid side."); } } /*************** End of input opponent side ******************/ /*************** Start game *******************/ Console.WriteLine("Start playing."); Console.WriteLine(); if (ownSide == Side.White) { moveDepthTimeAndScore = AlphaBeta2.IDASParallel(board, ownSide); // AlphaBeta2.IterativeDeepeningParallel(board, ownSide); // AlphaBeta2.RootAlphaBetaTTParallel(board, ownSide, depth).Item1; move = moveDepthTimeAndScore.Item1; if (board.MakeMove(move)) { Console.WriteLine("Filthy Mind: {0} (Depth: {1} plies; Time: {2}ms; Score: {3})", board.ConvertToAlgebraicNotation(move), moveDepthTimeAndScore.Item2, moveDepthTimeAndScore.Item3, moveDepthTimeAndScore.Item4); } } while (true) { Console.Write("You: "); opponentMoveString = Console.ReadLine(); if (opponentMoveString.ToLower() == "exit") { break; } if (opponentMoveString.ToLower() == "fen") { Console.WriteLine("Board Position: {0}", board.ToString()); continue; } if (opponentMoveString.Trim().ToLower() == "undo") { if (undoStack.Count > 0) { board.RestoreState(undoStack.Pop()); Console.WriteLine("Undid last move."); } else { Console.WriteLine("Nothing to undo!"); } continue; } try { undoStack.Push(board.GetBoardState()); if (!board.MakeUserMove(opponentMoveString)) { Console.WriteLine("Failed to make move. Try again."); undoStack.Pop(); continue; } } catch (Exception ex) { undoStack.Pop(); Console.WriteLine("ERROR: {0}", ex.Message); continue; } // make move for own side moveDepthTimeAndScore = AlphaBeta2.IDASParallel(board, ownSide); // AlphaBeta2.IterativeDeepeningParallel(board, ownSide); // AlphaBeta2.RootAlphaBetaTTParallel(board, ownSide, depth).Item1; move = moveDepthTimeAndScore.Item1; if (board.MakeMove(move)) { Console.WriteLine("Filthy Mind: {0} (Depth: {1} plies; Time: {2}ms; Score: {3})", board.ConvertToAlgebraicNotation(move), moveDepthTimeAndScore.Item2, moveDepthTimeAndScore.Item3, moveDepthTimeAndScore.Item4); } } Console.WriteLine("End of the game. Press any key to close the window."); Console.ReadKey(); /*************** End of game ******************/ }