コード例 #1
0
        private static int Perft(ChessBoard cb, ThreadData threadData, int depth)
        {
            threadData.StartPly();
            MoveGenerator.GenerateMoves(threadData, cb);
            MoveGenerator.GenerateAttacks(threadData, cb);

            if (depth == 0)
            {
                threadData.EndPly();
                return(1);
            }

            var counter = 0;

            while (threadData.HasNext())
            {
                var move = threadData.Next();
                if (!cb.IsLegal(move))
                {
                    continue;
                }

                cb.DoMove(move);
                EvalUtil.CalculateScore(cb, threadData);
                counter += Perft(cb, threadData, depth - 1);
                cb.UndoMove(move);
            }

            threadData.EndPly();
            return(counter);
        }
コード例 #2
0
ファイル: EvalTest.cs プロジェクト: respel/Chess22kDotNet
        public static void Main()
        {
            var cb = ChessBoardInstances.Get(0);

            ChessBoardUtil.SetFen("1r1q1rk1/2p1npb1/b3p1p1/p5N1/1ppPB2R/P1N1P1P1/1P2QPP1/2K4R w - - 0 20 ", cb);
            EvalUtil.CalculateScore(cb, ThreadData.GetInstance(0));
        }
コード例 #3
0
        public static void Main()
        {
            var fens = Tuner.LoadFens("d:\\backup\\chess\\epds\\quiet-labeled.epd", true, false);

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

            var cb         = ChessBoardInstances.Get(0);
            var threadData = ThreadData.GetInstance(0);

            foreach (var(key, value) in fens)
            {
                ChessBoardUtil.SetFen(key, cb);
                var error = Math.Pow(value - ErrorCalculator.CalculateSigmoid(EvalUtil.CalculateScore(cb, threadData)),
                                     2);

                for (var i = 0; i < LargestError.Length; i++)
                {
                    if (!(error > LargestError[i]))
                    {
                        continue;
                    }
                    LargestError[i]    = error;
                    LargestErrorFen[i] = key;
                    break;
                }
            }

            for (var i = 0; i < LargestError.Length; i++)
            {
                Console.WriteLine($"{LargestErrorFen[i],60} -> {LargestError[i]}");
            }
        }
コード例 #4
0
        public double Call()
        {
            double totalError = 0;

            foreach (var(key, value) in _fens)
            {
                ChessBoardUtil.SetFen(key, _cb);
                totalError += Math.Pow(
                    value - CalculateSigmoid(ChessConstants.ColorFactor[_cb.ColorToMove] *
                                             EvalUtil.CalculateScore(_cb, _threadData)),
                    2);
            }

            totalError /= _fens.Count;
            return(totalError);
        }
コード例 #5
0
        public static void Main()
        {
            var fens = Tuner.LoadFens("d:\\backup\\chess\\epds\\quiet-labeled.epd", true, false);

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

            var kpk   = new ErrorCount("KPK ");
            var kbnk  = new ErrorCount("KBNK");
            var kbpk  = new ErrorCount("KBPK");
            var krkp  = new ErrorCount("KRKP");
            var kqkp  = new ErrorCount("KQKP");
            var krkb  = new ErrorCount("KRKB");
            var krkn  = new ErrorCount("KRKN");
            var kbpkp = new ErrorCount("KBPKP");
            var krbkb = new ErrorCount("KRBKB");
            var krbkr = new ErrorCount("KRBKR");

            var cb         = ChessBoardInstances.Get(0);
            var threadData = ThreadData.GetInstance(0);

            foreach (var(key, value) in fens)
            {
                ChessBoardUtil.SetFen(key, cb);

                var error = Math.Pow(
                    value - ErrorCalculator.CalculateSigmoid(ChessConstants.ColorFactor[cb.ColorToMove] *
                                                             EvalUtil.CalculateScore(cb, threadData)),
                    2);
                if (MaterialUtil.IsKbnk(cb.MaterialKey))
                {
                    kbnk.AddError(error);
                }
                else if (MaterialUtil.IsKqkp(cb.MaterialKey))
                {
                    kqkp.AddError(error);
                }
                else if (MaterialUtil.IsKrkp(cb.MaterialKey))
                {
                    krkp.AddError(error);
                }
                else if (MaterialUtil.IsKrkb(cb.MaterialKey))
                {
                    krkb.AddError(error);
                }
                else if (MaterialUtil.IsKrkn(cb.MaterialKey))
                {
                    krkn.AddError(error);
                }
                else if (MaterialUtil.IsKpk(cb.MaterialKey))
                {
                    krkn.AddError(error);
                }
                else if (MaterialUtil.IsKbpk(cb.MaterialKey))
                {
                    kbpk.AddError(error);
                }
                else if (MaterialUtil.IsKbpkp(cb.MaterialKey))
                {
                    kbpkp.AddError(error);
                }
                else if (MaterialUtil.IsKrbkb(cb.MaterialKey))
                {
                    krbkb.AddError(error);
                }
                else if (MaterialUtil.IsKrbkr(cb.MaterialKey))
                {
                    krbkr.AddError(error);
                }
            }

            kpk.Print();
            kbnk.Print();
            krkp.Print();
            kqkp.Print();
            krkb.Print();
            krkn.Print();
            krbkb.Print();
            krbkr.Print();
            kbpk.Print();
            kbpkp.Print();
        }