Esempio n. 1
0
        public static void Main(string[] args)
        {
            var gameState = new GameState();

            gameState.GameBoard = new Board();

            Command cmd = null;

            while (cmd == null || cmd.Value != CommandVal.Quit)
            {
                var input = Console.ReadLine();
                cmd = CommandParser.ParseCommand(input);
                CommandParser.DoCommand(cmd, gameState);

                if (gameState.IsMyTurn)
                {
                    var myMove = Iterate.DoIterate(gameState, () =>
                    {
                        bool waitForLine = false;
                        if (Console.IsInputRedirected)
                        {
                            waitForLine = (Console.In.Peek() != -1);
                        }
                        else if (Console.KeyAvailable)
                        {
                            waitForLine = true;
                        }

                        if (waitForLine)
                        {
                            input = Console.ReadLine();
                            cmd   = CommandParser.ParseCommand(input);
                            CommandParser.DoCommand(cmd, gameState);
                        }
                    });

                    if (myMove != null)
                    {
                        Console.WriteLine("move {0}", myMove.ToAlegbraicNotation(gameState.GameBoard));
                        gameState.GameBoard.MakeMove(myMove);
                    }
                }
            }
        }
Esempio n. 2
0
        static void EpdTest(Command cmd)
        {
            int tests = 0, successes = 0;

            if (cmd.Arguments.Length < 2)
            {
                Console.Error.WriteLine("Missing parameter filename");
                return;
            }
            try
            {
                using (var fs = new FileStream(cmd.Arguments[1], FileMode.Open))
                {
                    Console.WriteLine("beginning test in 5 seconds... type 'quit' to abort");
                    System.Threading.Thread.Sleep(5000);
                    var    sr = new StreamReader(fs);
                    String line;
                    bool   quit = false;

                    var gameState = new GameState();
                    gameState.TimeControl = new TimeControl
                    {
                        Type = TimeControlType.FixedTimePerMove,
                        FixedTimePerSearchSeconds = 5
                    };
                    do
                    {
                        line = sr.ReadLine();

                        if (String.IsNullOrEmpty(line))
                        {
                            break;
                        }

                        var bmRegex   = new Regex("bm (?<bms>[^;]*)");
                        var match     = bmRegex.Match(line);
                        var bestMoves = match.Groups["bms"].Value.Split(' ');

                        Console.WriteLine(line);
                        if (String.IsNullOrEmpty(line))
                        {
                            break;
                        }
                        gameState.GameBoard = Board.ParseFenString(line);
                        var found = Iterate.DoIterate(gameState, () =>
                        {
                            bool waitForLine = false;
                            if (Console.IsInputRedirected)
                            {
                                waitForLine = (Console.In.Peek() != -1);
                            }
                            else if (Console.KeyAvailable)
                            {
                                waitForLine = true;
                            }

                            if (waitForLine)
                            {
                                var input = Console.ReadLine();
                                cmd       = CommandParser.ParseCommand(input);
                                if (cmd.Value == CommandVal.Quit)
                                {
                                    quit             = true;
                                    gameState.TimeUp = true;
                                    Console.WriteLine("Aborting");
                                }
                                else
                                {
                                    Console.WriteLine("Running test!");
                                }
                            }
                        });

                        var  moveStr = found.ToAlegbraicNotation(gameState.GameBoard);
                        bool fail    = true;
                        foreach (var bm in bestMoves)
                        {
                            if (bm.ToLower() == moveStr.ToLower())
                            {
                                fail = false;
                                break;
                            }
                        }
                        tests++;
                        if (fail)
                        {
                            Console.WriteLine("FAIL {0}/{1}", successes, tests);
                        }
                        else
                        {
                            successes++;
                            Console.WriteLine("SUCCESS! {0}/{1}", successes, tests);
                        }
                    } while (!String.IsNullOrEmpty(line) && !quit);
                }
            }
            catch (FileNotFoundException fex)
            {
                Console.WriteLine(fex.Message);
            }

            Console.WriteLine("Test suite complete");
            Console.WriteLine("{0}/{1} Solved", successes, tests);
        }