Example #1
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]);
            }
        }
Example #2
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);
        }
Example #3
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);
        }