Ejemplo n.º 1
0
        public static void Main()
        {
            var cb = ChessBoardInstances.Get(0);

            MainEngine.MaxDepth             = MaxPly;
            UciOut.NoOutput                 = true;
            EngineConstants.Power2TtEntries = 2;
            TtUtil.Init(false);
            long totalNodesSearched = 0;

            var epdStrings = BestMoveTest.GetEpdStrings("Resources/WAC-201.epd");

            for (var index = 0; index < NumberOfPositions; index++)
            {
                Console.WriteLine(index);
                var epdString = epdStrings[index + 20];
                Statistics.Reset();
                var epd = new Epd(epdString);
                ChessBoardUtil.SetFen(epd.GetFen(), cb);
                SearchUtil.Start(cb);
                totalNodesSearched += ChessBoardUtil.CalculateTotalMoveCount();
            }

            Console.WriteLine("Total   " + totalNodesSearched);
            Console.WriteLine("Average " + totalNodesSearched / NumberOfPositions);
        }
Ejemplo n.º 2
0
        private static void ReadLine(string line)
        {
            var tokens = line.Split(" ");

            if (tokens[0].Equals("uci"))
            {
                UciOut.SendUci();
            }
            else if (tokens[0].Equals("isready"))
            {
                Console.WriteLine("readyok");
            }
            else if (tokens[0].Equals("ucinewgame"))
            {
                TtUtil.Init(false);
                TtUtil.ClearValues();
            }
            else if (tokens[0].Equals("position"))
            {
                Position(tokens);
            }
            else if (tokens[0].Equals("go"))
            {
                Go(tokens);
            }
            else if (tokens[0].Equals("ponderhit"))
            {
                Pondering = false;
                if (_maxTimeExceeded)
                {
                    NegamaxUtil.IsRunning = false;
                }
            }
            else if (tokens[0].Equals("eval"))
            {
                UciOut.Eval(_cb, _threadData);
            }
            else if (tokens[0].Equals("setoption"))
            {
                if (tokens.Length > 4)
                {
                    SetOption(tokens[2], tokens[4]);
                }
            }
            else if (tokens[0].Equals("quit"))
            {
                Environment.Exit(0);
            }
            else if (tokens[0].Equals("stop"))
            {
                NegamaxUtil.IsRunning = false;
            }
            else
            {
                Console.WriteLine("Unknown command: " + tokens[0]);
            }
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            var cb = ChessBoardInstances.Get(0);

            ChessBoardUtil.SetFen(FenStandardMiddlegame, cb);
            TimeUtil.SetSimpleTimeWindow(5000);
            TtUtil.Init(false);
            SearchUtil.Start(cb);
            Statistics.Print();
        }
Ejemplo n.º 4
0
        public static void Main()
        {
            UciOut.NoOutput = true;
            TtUtil.Init(false);

            DoTest(GetEpdStrings("Resources/WAC-201.epd"));
            // DoTest(GetEpdStrings("Resources/EigenmannEndgame.epd"));

            Console.WriteLine("");
            Console.WriteLine("Total: " + _positionTestOk + "/" + (_positionTestOk + _positionTestNok));
        }
Ejemplo n.º 5
0
        public static void Main()
        {
            var cb = ChessBoardInstances.Get(0);

            // read all fens, including score
            var fens = Tuner.LoadFens("d:\\backup\\chess\\epds\\violent.epd", false, true);

            Console.WriteLine("Fens found : " + fens.Count);

            // NegamaxUtil.isRunning = true;
            EngineConstants.Power2TtEntries = 1;
            TtUtil.Init(false);

            double totalPositions = 0;
            double sameScore      = 0;
            long   totalError     = 0;
            var    watch          = new Stopwatch();

            watch.Start();
            foreach (var entry in fens)
            {
                ChessBoardUtil.SetFen(entry.Key, cb);
                if (cb.CheckingPieces == 0)
                {
                    continue;
                }

                totalPositions++;
                var searchScore = NegamaxUtil.CalculateBestMove(cb, ThreadData, 0, 1, Util.ShortMin, Util.ShortMax, 0);
                TtUtil.ClearValues();
                var qScore = QuiescenceUtil.CalculateBestMove(cb, ThreadData, Util.ShortMin, Util.ShortMax);

                if (searchScore == qScore)
                {
                    sameScore++;
                }
                else
                {
                    var error = searchScore - qScore;
                    // if (error > 500) {
                    // System.out.println(searchScore + " " + qScore);
                    // QuiescenceUtil.calculateBestMove(cb, threadData, Util.SHORT_MIN, Util.SHORT_MAX);
                    // }

                    totalError += error;
                }
            }

            var averageError = (int)(totalError / (totalPositions - sameScore));

            Console.WriteLine($"{sameScore / totalPositions:f4} {averageError}");
            Console.WriteLine("msec: " + watch.ElapsedMilliseconds);
        }
Ejemplo n.º 6
0
        private static void Go(string[] goCommandTokens)
        {
            // go movestogo 30 wtime 3600000 btime 3600000
            // go wtime 40847 btime 48019 winc 0 binc 0 movestogo 20

            Statistics.Reset();
            TimeUtil.Reset();
            TimeUtil.SetMoveCount(_cb.MoveCounter);
            MaxDepth  = EngineConstants.MaxPlies;
            Pondering = false;

            TtUtil.Init(false);
            var ttEntry = TtUtil.GetEntry(_cb.ZobristKey);

            if (ttEntry.Key != 0 && ttEntry.Flag == TtUtil.FlagExact)
            {
                TimeUtil.SetTtHit();
            }

            // go
            // go infinite
            // go ponder
            if (goCommandTokens.Length != 1)
            {
                for (var i = 1; i < goCommandTokens.Length; i++)
                {
                    if (goCommandTokens[i].Equals("infinite"))
                    {
                        // TODO are we clearing the values again?
                        TtUtil.ClearValues();
                    }
                    else if (goCommandTokens[i].Equals("ponder"))
                    {
                        Pondering = true;
                    }
                    else if (goCommandTokens[i].Equals("movetime"))
                    {
                        var s = goCommandTokens[i + 1];
                        TimeUtil.SetExactMoveTime(int.Parse(s));
                    }
                    else if (goCommandTokens[i].Equals("movestogo"))
                    {
                        var s = goCommandTokens[i + 1];
                        TimeUtil.SetMovesToGo(int.Parse(s));
                    }
                    else if (goCommandTokens[i].Equals("depth"))
                    {
                        var s = goCommandTokens[i + 1];
                        MaxDepth = int.Parse(s);
                    }
                    else if (goCommandTokens[i].Equals("wtime"))
                    {
                        if (_cb.ColorToMove != ChessConstants.White)
                        {
                            continue;
                        }
                        var s = goCommandTokens[i + 1];
                        TimeUtil.SetTotalTimeLeft(int.Parse(s));
                    }
                    else if (goCommandTokens[i].Equals("btime"))
                    {
                        if (_cb.ColorToMove != ChessConstants.Black)
                        {
                            continue;
                        }
                        var s = goCommandTokens[i + 1];
                        TimeUtil.SetTotalTimeLeft(int.Parse(s));
                    }
                    else if (goCommandTokens[i].Equals("winc") || goCommandTokens[i].Equals("binc"))
                    {
                        var s = goCommandTokens[i + 1];
                        TimeUtil.SetIncrement(int.Parse(s));
                    }
                }
            }

            TimeUtil.Start();

            Task.Run(SearchTask);
        }