Ejemplo n.º 1
0
        public static void Set(ChessBoard cb, int[] moves, int bestMove)
        {
            Array.Fill(moves, 0);
            moves[0] = bestMove;
            cb.DoMove(bestMove);

            for (var i = 1; i < moves.Length; i++)
            {
                var ttEntry = TtUtil.GetEntry(cb.ZobristKey);
                if (ttEntry.Key == 0)
                {
                    break;
                }

                var move = ttEntry.Move;
                if (move == 0)
                {
                    break;
                }

                moves[i] = move;
                cb.DoMove(move);
            }

            for (var i = moves.Length - 1; i >= 0; i--)
            {
                if (moves[i] == 0)
                {
                    continue;
                }

                cb.UndoMove(moves[i]);
            }
        }
Ejemplo n.º 2
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);
        }