示例#1
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);
        }
示例#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);

            double sameScore    = 0;
            double totalAttacks = 0;
            var    start        = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            foreach (var entry in fens)
            {
                ChessBoardUtil.SetFen(entry.Key, cb);
                _threadData.StartPly();
                MoveGenerator.GenerateAttacks(_threadData, cb);
                while (_threadData.HasNext())
                {
                    var move = _threadData.Next();
                    if (!cb.IsLegal(move))
                    {
                        continue;
                    }

                    totalAttacks++;
                    var seeScore      = SeeUtil.GetSeeCaptureScore(cb, move);
                    var materialScore = EvalUtil.CalculateMaterialScore(cb);
                    var qScore        = ChessConstants.ColorFactor[cb.ColorToMoveInverse] * materialScore -
                                        CalculateQScore(cb, move, true);
                    if (seeScore == qScore)
                    {
                        sameScore++;
                    }

                    // else {
                    // seeScore = SEEUtil.getSeeCaptureScore(cb, move);
                    // qScore = ChessConstants.COLOR_FACTOR[cb.colorToMoveInverse] * materialScore - calculateQScore(cb,
                    // move, true);
                    // }
                }

                _threadData.EndPly();
            }

            Console.WriteLine($"{sameScore:f0} {totalAttacks:f0} = {sameScore / totalAttacks:f4}");
            Console.WriteLine("msec: " + (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - start));
        }
示例#3
0
        public static void Main()
        {
            // read all fens, including score
            var fens = Tuner.LoadFens("d:\\backup\\chess\\epds\\quiet-labeled.epd", true, true);

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

            var tested = 0;
            var ok     = 0;
            var nok    = 0;

            foreach (var(fen, score) in fens)
            {
                var cb = ChessBoardInstances.Get(0);
                ChessBoardUtil.SetFen(fen, cb);
                if (BitOperations.PopCount((ulong)cb.AllPieces) > 3)
                {
                    continue;
                }

                if (cb.Pieces[ChessConstants.White][ChessConstants.Pawn] == 0 &&
                    cb.Pieces[ChessConstants.Black][ChessConstants.Pawn] == 0)
                {
                    continue;
                }

                tested++;
                if (KpkBitbase.IsDraw(cb) == (score == 0.5))
                {
                    ok++;
                }
                else
                {
                    nok++;
                }
            }

            Console.WriteLine();
            Console.WriteLine("Tested " + tested);
            Console.WriteLine("OK " + ok);
            Console.WriteLine("NOK " + nok);
        }