Exemplo n.º 1
0
            /// <summary>
            /// Checks if the current state of the game has potential for
            /// Zugzwang. A zugzwang is a position where you are fine if you don't move, but
            /// your position collapses if you are forced to move. We simply detect this by
            /// checking if we are in an endgame.
            /// </summary>
            /// <param name="board">board to check.</param>
            /// <returns>True if we are in an endgame and there is possabilety of zugzwang.</returns>
            private bool ColorToPlayZugzwang(Board board)
            {
                switch (board.State.ColorToPlay)
                {
                case PieceColor.White:
                {
                    int score = 0;
                    foreach (Square square in board.WhitePieceLocations)
                    {
                        if (board[square] == Piece.WhiteRook || board[square] == Piece.WhiteBishop ||
                            board[square] == Piece.WhiteKnight || board[square] == Piece.WhiteQueen)
                        {
                            score += m_evaluator.PieceValue(board[square]);
                            if (score > m_evaluator.PieceValue(Piece.WhiteRook))
                            {
                                return(false);
                            }
                        }
                    }
                }
                break;

                case PieceColor.Black:
                {
                    int score = 0;
                    foreach (Square square in board.BlackPieceLocations)
                    {
                        if (board[square] == Piece.BlackRook || board[square] == Piece.BlackBishop ||
                            board[square] == Piece.BlackKnight || board[square] == Piece.BlackQueen)
                        {
                            score += m_evaluator.PieceValue(board[square]);
                            if (score > m_evaluator.PieceValue(Piece.BlackRook))
                            {
                                return(false);
                            }
                        }
                    }
                }
                break;
                }

                return(true);
            }
Exemplo n.º 2
0
            public int Compare(Move x, Move y)
            {
                if (x.IsCaptureMove && !y.IsCaptureMove)
                {
                    return(-1);
                }
                if (!x.IsCaptureMove && y.IsCaptureMove)
                {
                    return(1);
                }
                if (x.IsCaptureMove && y.IsCaptureMove)
                {
                    int xCaptureVal = m_evaluator.PieceValue(x.Capture);
                    int yCaptureVal = m_evaluator.PieceValue(y.Capture);

                    if (xCaptureVal > yCaptureVal)
                    {
                        return(-1);
                    }
                    if (xCaptureVal < yCaptureVal)
                    {
                        return(1);
                    }

                    int xAttackerVal = m_evaluator.PieceValue(x.Piece);
                    int yAttackerVal = m_evaluator.PieceValue(y.Piece);

                    if (xAttackerVal < yAttackerVal)
                    {
                        return(-1);
                    }
                    if (xAttackerVal > yAttackerVal)
                    {
                        return(1);
                    }
                }
                //TODO: Also sort according to pawn promotion moves.

                return(0);
            }