/// <summary>
        /// Sorts the specified list of moves (best moves are higher which can cause more prunes).
        /// </summary>
        /// <param name="color">The current color.</param>
        /// <param name="bitboard">The bitboard.</param>
        /// <param name="moves">The list of moves to sort.</param>
        /// <returns>The sorted list of moves.</returns>
        private List <Move> SortMoves(Color color, Bitboard bitboard, LinkedList <Move> moves)
        {
#if QUIESCENCE_SORT_MOVES
            var see        = new SEECalculator();
            var seeResults = see.Calculate(color, bitboard);

            var sortedMoves = moves
                              .Select(p =>
                                      new
            {
                Move     = p,
                SEEScore = seeResults.FirstOrDefault(
                    q => q.InitialAttackerFrom == p.From &&
                    q.InitialAttackerTo == p.To)?.Score ?? 100000
            })
                              .Where(p => p.SEEScore >= 0)
                              .OrderByDescending(p => p.SEEScore)
                              .Select(p => p.Move)
                              .ToList();

            return(sortedMoves);
#else
            return(moves.ToList());
#endif
        }
Ejemplo n.º 2
0
        private void AssignSEEScores(Color color, Bitboard bitboard, List <RegularSortedMove> movesToSort)
        {
            var see        = new SEECalculator();
            var seeResults = see.Calculate(color, bitboard);

            foreach (var seeResult in seeResults)
            {
                var sortedMove = movesToSort.FirstOrDefault(p => p.Move.From == seeResult.InitialAttackerFrom &&
                                                            p.Move.To == seeResult.InitialAttackerTo);

                if (sortedMove != null)
                {
                    sortedMove.Score = seeResult.Score;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Runs static exchange evaluation.
        /// </summary>
        /// <param name="command">The SEE command</param>
        private void RunSEE(Command command)
        {
            var colorArgument = command.GetArgument <string>(0);

            var colorParseResult = Enum.TryParse(colorArgument, true, out Color color);

            if (!colorParseResult)
            {
                ConsoleManager.WriteLine($"$rInvalid color type ($R{color}$r)");
                return;
            }

            var seeCalculator = new SEECalculator();
            var seeResults    = seeCalculator.Calculate(color, Bitboard);

            foreach (var result in seeResults)
            {
                ConsoleManager.WriteLine($"$g{result.InitialAttackerFrom} $r({result.InitialAttackerType})$w -> " +
                                         $"$g{result.InitialAttackerTo} $r({result.AttackedPieceType})$w: " +
                                         $"$g{result.Score}");
            }
        }