Ejemplo n.º 1
0
        internal static MoveList Quiets(Board position)
        {
            MoveList quietMoves = new MoveList();

            position.CollectQuiets(m => quietMoves.Add(m, 0));
            return(quietMoves);
        }
Ejemplo n.º 2
0
        public static MoveList SortedQuiets(Board position, History history)
        {
            MoveList quiets = new MoveList();

            position.CollectQuiets(m => quiets.Add(m, history.Value(position, m)));
            quiets.Sort();
            return(quiets);
        }
Ejemplo n.º 3
0
        internal static MoveList SortedCaptures(Board position)
        {
            MoveList captures = new MoveList();

            position.CollectCaptures(m => captures.Add(m, ScoreMvvLva(m, position)));
            captures.Sort();
            return(captures);
        }
Ejemplo n.º 4
0
 internal static IEnumerable <Board> PlayCaptures(Board position)
 {
     foreach (var capture in MoveList.SortedCaptures(position))
     {
         var nextPosition = new Board(position, capture);
         if (!nextPosition.IsChecked(position.SideToMove))
         {
             yield return(nextPosition);
         }
     }
 }
Ejemplo n.º 5
0
        internal static IEnumerable <(Move Move, Board Board)> Play(Board position, int depth, KillerMoves killers, History history)
        {
            //1. Is there a known best move for this position? (PV Node)
            if (Transpositions.GetBestMove(position, out Move bestMove))
            {
                var nextPosition = new Board(position, bestMove);
                yield return(bestMove, nextPosition);
            }

            //2. Try all captures ordered by Mvv-Lva
            foreach (var capture in MoveList.SortedCaptures(position))
            {
                var nextPosition = new Board(position, capture);
                if (!nextPosition.IsChecked(position.SideToMove))
                {
                    yield return(capture, nextPosition);
                }
            }

            //3. Play quiet moves that have caused a beta cutoff elsewhere if available
            foreach (Move killer in killers.Get(depth))
            {
                if (position[killer.ToSquare] != Piece.None || !position.IsPlayable(killer))
                {
                    continue;
                }

                var nextPosition = new Board(position, killer);
                if (!nextPosition.IsChecked(position.SideToMove))
                {
                    yield return(killer, nextPosition);
                }
            }

            //4. Play the remaining quiet moves ordered by history
            foreach (var move in MoveList.SortedQuiets(position, history))
            {
                if (killers.Contains(depth, move))
                {
                    continue;
                }

                var nextPosition = new Board(position, move);
                if (!nextPosition.IsChecked(position.SideToMove))
                {
                    yield return(move, nextPosition);
                }
            }
        }