Esempio n. 1
0
        private static void PerformanceTesting(string fen, int perftDepth, TimeSpan timespan)
        {
            var position = BoardParsing.PositionFromFen(fen);

            Debugging.Dump(position);

            var       moveGen          = new MoveGenerator();
            var       perft            = new Perft(moveGen);
            Stopwatch overallStopwatch = new Stopwatch();

            overallStopwatch.Start();
            while (true)
            {
                int perftNum = perftDepth;
                Console.Write($"Perft {perftNum}: ");

                Stopwatch sw = new Stopwatch();
                sw.Start();
                int perftResults = perft.GoPerft(position, perftNum);
                sw.Stop();
                double knps = ((double)perftResults) / sw.ElapsedMilliseconds;  // it just works out
                Console.WriteLine($"{perftResults} ({knps:F2} knps)");
                if (overallStopwatch.Elapsed > timespan)
                {
                    break;
                }
            }

            //perft.GoPerft(position, perftDepth);
        }
Esempio n. 2
0
 public SimpleUci(IMoveGenerator moveGenerator, ISearch search, TextReader input, TextWriter output)
 {
     _position           = BoardParsing.PositionFromFen(InitialFen);
     _moveGenerator      = moveGenerator;
     _search             = search;
     _timeStrategy       = new DefaultTimeStrategy();
     _input              = input;
     _output             = output;
     _searchWorkerThread = new SearchWorkerThread();
 }
Esempio n. 3
0
        public void Setup()
        {
            var moveGen = new MoveGenerator();

            _perft = new Perft(moveGen);

            _openingPosition = BoardParsing.PositionFromFen(OpeningFen);
            _midgamePosition = BoardParsing.PositionFromFen(MidgameFen);
            _endgamePosition = BoardParsing.PositionFromFen(EndgameFen);
        }
Esempio n. 4
0
        private static void Bench()
        {
            var moveGen   = new MoveGenerator();
            var evaluator = new Evaluator();
            var promotionMvvLvaMoveOrderer = new CompositeMoveOrderer(new IMoveOrderer[] { new PromotionsOrderer(), new MvvLvaOrderer() });
            var qSearch      = new SimpleQSearch(evaluator, moveGen, promotionMvvLvaMoveOrderer, CompositeMoveOrderer.NullMoveOrderer);
            var search       = new SimpleAlphaBetaSearch(moveGen, evaluator, qSearch);
            var timeStrategy = new TimePerMoveStrategy(TimeSpan.FromSeconds(10));

            search.Search(BoardParsing.PositionFromFen(MidgameFen), timeStrategy, s => { });
        }
Esempio n. 5
0
        public static void DumpEvalsForEachPosition()
        {
            var evaluator = new Evaluator();

            foreach (var(fen, _) in GetPerftCasesEnumerator())
            {
                var position = BoardParsing.PositionFromFen(fen);

                Console.WriteLine($"{fen} {evaluator.Evaluate(position)}");
            }
        }
Esempio n. 6
0
        private static void DivideTesting(string fen, int depth, params string[] moves)
        {
            var position = BoardParsing.PositionFromFen(fen);

            Debugging.Dump(position);

            var moveGen = new MoveGenerator();
            var perft   = new Perft(moveGen);

            foreach (var moveStr in moves)
            {
                Move move = BoardParsing.GetMoveFromCoordinateString(moveGen, position, moveStr);
                position = Position.MakeMove(new Position(), move, position);
                Debugging.Dump(position);
            }

            GoDivide(moveGen, perft, position, depth - moves.Length);
        }
Esempio n. 7
0
        private void SetPosition(string optionsStr)
        {
            var options = optionsStr.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList();

            if (options[0] == "startpos")
            {
                _position = BoardParsing.PositionFromFen(InitialFen);
                options.RemoveAt(0);
            }
            else if (options[0] == "fen")
            {
                string fen = "";
                options.RemoveAt(0);
                while (options.Count > 0 && options[0] != "moves")
                {
                    fen += $"{options[0]} ";
                    options.RemoveAt(0);
                }

                _position = BoardParsing.PositionFromFen(fen);
            }
            else
            {
                throw new Exception($"Invalid option: {options[0]}");
            }

            if (!_position.IsValid())
            {
                throw new Exception("Invalid position");
            }

            if (options.Any() && options[0] == "moves")
            {
                options.RemoveAt(0);

                foreach (var moveStr in options)
                {
                    Move move = BoardParsing.GetMoveFromCoordinateString(_moveGenerator, _position, moveStr);
                    _position = Position.MakeMove(new Position(), move, _position);
                }
            }
        }
Esempio n. 8
0
        private static void IncrementalPerft(string fen, int maxDepth)
        {
            var position = BoardParsing.PositionFromFen(fen);

            Debugging.Dump(position);

            var moveGen = new MoveGenerator();
            var perft   = new Perft(moveGen);

            for (int i = 1; i <= maxDepth; i++)
            {
                Console.Write($"Perft {i}: ");

                Stopwatch sw = new Stopwatch();
                sw.Start();
                int perftResults = perft.GoPerft(position, i);
                sw.Stop();
                double knps = ((double)perftResults) / sw.ElapsedMilliseconds;  // it just works out
                Console.WriteLine($"{perftResults} ({knps:F2} knps)");
            }
        }
Esempio n. 9
0
        private static void GoDivide(MoveGenerator moveGenerator, Perft perft, Position position, int depth)
        {
            if (depth <= 0)
            {
                Console.WriteLine($"##### No moves generated at depth {depth}");
                return;
            }

            var total = 0;

            List <Move> moves = new List <Move>();

            moveGenerator.Generate(moves, position);

            var movesDict = new SortedDictionary <string, Move>();

            foreach (var move in moves)
            {
                movesDict.Add(BoardParsing.CoordinateStringFromMove(move), move);
            }

            foreach (var(moveStr, move) in movesDict)
            {
                var nextBoard = Position.MakeMove(new Position(), move, position);

                // check move legality if using a pseudolegal move generator
                if (!moveGenerator.OnlyLegalMoves && nextBoard.MovedIntoCheck())
                {
                    continue;
                }

                Console.Write($"{moveStr}: ");

                int count = perft.GoPerft(nextBoard, depth - 1);
                Console.WriteLine(count);
                total += count;
            }
            Console.WriteLine($"##### Total moves: {total}");
        }
Esempio n. 10
0
        public void BitboardSquaresTest(string fen, int depth)
        {
            var position = BoardParsing.PositionFromFen(fen);

            BitboardSquaresTestHelper(position, depth);
        }
Esempio n. 11
0
 public override string ToString()
 {
     return(BoardParsing.NaiveSanStringFromMove(this));
 }
Esempio n. 12
0
        public void ZobristTest(string fen, int depth)
        {
            var position = BoardParsing.PositionFromFen(fen);

            ZobristTestHelper(position, depth);
        }
Esempio n. 13
0
        public string FenTest(string fen)
        {
            var position = BoardParsing.PositionFromFen(fen);

            return(BoardParsing.FenStringFromBoard(position));
        }
Esempio n. 14
0
 public override string ToString()
 {
     return(BoardParsing.FenStringFromBoard(this));
 }
Esempio n. 15
0
 private void PrintBestMove(Move bestMove)
 {
     _output.WriteLine($"bestmove {BoardParsing.CoordinateStringFromMove(bestMove)}");
 }
Esempio n. 16
0
        public int PerftWithHashingTest(string fen, int depth)
        {
            var position = BoardParsing.PositionFromFen(fen);

            return(_perftWithHashing.GoPerft(position, depth));
        }