Beispiel #1
0
        static void TestIDAS()
        {
            Board board = new Board();

            TestingHelper.MakeSomeMoves(board);
            Evaluation2.Initialise();

            Stopwatch sw = new Stopwatch();

            sw.Start();
            Tuple <UInt16, int, long, int> bestMoveAndScore = AlphaBeta2.IDASParallel(board, Side.White);

            // AlphaBeta2.IterativeDeepeningParallel(board, Side.White);


            //Tuple<UInt16, int> bestMoveAndScore = AlphaBeta2.RootAlphaBetaTTParallel(board, Side.White, 6);
            //bestMoveAndScore = AlphaBeta2.RootAlphaBetaTTParallel(board, Side.White, 7);
            //, -120, -60);
            sw.Stop();

            //Console.WriteLine("Best Move For White: {0}. Depth: {1}. Score:{2}. TIME: {3} milliseconds",
            //   board.ConvertToAlgebraicNotation(bestMoveAndScore.Item1), 7, bestMoveAndScore.Item2, sw.ElapsedMilliseconds);

            Console.WriteLine("Best Move For White: {0}. Depth: {1}. Score:{2}. TIME: {3} milliseconds",
                              board.ConvertToAlgebraicNotation(bestMoveAndScore.Item1), bestMoveAndScore.Item2, bestMoveAndScore.Item4, sw.ElapsedMilliseconds);
        }
Beispiel #2
0
        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 ******************/
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            // variables
            sbyte ownSide;
            Board board = new Board();
            Stack <BoardState> undoStack = new Stack <BoardState>();

            UInt16 move;
            Tuple <UInt16, int, long, int> moveDepthTimeAndScore;

            string userMove, filthyMindMove = "INVALID_MOVE";

            File.Delete(LogFileName);
            string guiMessage = Console.ReadLine();

            File.AppendAllText(LogFileName, "\nGUI: " + guiMessage + Environment.NewLine);

            Console.WriteLine("id name Shutranj");
            Console.WriteLine("id author Okash Khawaja");
            Console.WriteLine("uciok");

            guiMessage = Console.ReadLine();
            File.AppendAllText(LogFileName, "GUI: " + guiMessage + Environment.NewLine);

            Console.WriteLine("readyok");

            guiMessage = Console.ReadLine();
            File.AppendAllText(LogFileName, "GUI: " + guiMessage + Environment.NewLine);

            guiMessage = Console.ReadLine();
            File.AppendAllText(LogFileName, "GUI: " + guiMessage + Environment.NewLine);

            guiMessage = Console.ReadLine();
            File.AppendAllText(LogFileName, "GUI: " + guiMessage + Environment.NewLine);

            /********** this is when the game begins **************/

            guiMessage = Console.ReadLine();
            File.AppendAllText(LogFileName, "GUI: " + guiMessage + Environment.NewLine);

            if (guiMessage == "quit" || guiMessage == "stop")
            {
                return;
            }
            userMove = ParseOutLastMove(guiMessage);

            guiMessage = Console.ReadLine();
            File.AppendAllText(LogFileName, "GUI: " + guiMessage + Environment.NewLine);

            // if empty then engine is playing white so make move first
            if (String.IsNullOrWhiteSpace(userMove))
            {
                ownSide = Side.White;

                moveDepthTimeAndScore = AlphaBeta2.IDASParallel(board, ownSide);

                move = moveDepthTimeAndScore.Item1;
                if (board.MakeMove(move))
                {
                    filthyMindMove = board.ConvertToAlgebraicNotation(move);
                    File.AppendAllText(LogFileName, String.Format(
                                           "Filthy Mind: {0} (Depth: {1} plies; Time: {2}ms; Score: {3}){4}", filthyMindMove,
                                           moveDepthTimeAndScore.Item2, moveDepthTimeAndScore.Item3, moveDepthTimeAndScore.Item4, Environment.NewLine));
                }

                // communicate move back to gui
                Console.WriteLine(BestMoveStringFormat, filthyMindMove);
            }
            else
            {
                ownSide = Side.Black;
            }



            while (true)
            {
                guiMessage = Console.ReadLine();
                File.AppendAllText(LogFileName, "GUI: " + guiMessage + Environment.NewLine);

                if (guiMessage == "quit" || guiMessage == "stop")
                {
                    break;
                }
                userMove = ParseOutLastMove(guiMessage);

                guiMessage = Console.ReadLine();
                File.AppendAllText(LogFileName, "GUI: " + guiMessage + Environment.NewLine);

                board.MakeUserMove(userMove);

                moveDepthTimeAndScore = AlphaBeta2.IDASParallel(board, ownSide);

                move = moveDepthTimeAndScore.Item1;
                if (board.MakeMove(move))
                {
                    filthyMindMove = board.ConvertToAlgebraicNotation(move);
                    File.AppendAllText(LogFileName, String.Format(
                                           "Filthy Mind: {0} (Depth: {1} plies; Time: {2}ms; Score: {3}){4}", filthyMindMove,
                                           moveDepthTimeAndScore.Item2, moveDepthTimeAndScore.Item3, moveDepthTimeAndScore.Item4, Environment.NewLine));
                }

                // communicate move back to gui
                Console.WriteLine(BestMoveStringFormat, filthyMindMove);
            }
        }