Пример #1
0
        /// <summary>
        /// Detects Checkmate, Stalemate or Draw conditions.
        /// </summary>
        /// <returns>True if no legal moves, or only kings left.</returns>
        public bool detectCheckmate()
        {
            bool wkingonly = this.Board.Pieces[Player.WHITE].Count == 1 && this.Board.Grid[this.Board.Pieces[Player.WHITE][0].number][this.Board.Pieces[Player.WHITE][0].letter].piece == Piece.KING;
            bool bkingonly = this.Board.Pieces[Player.BLACK].Count == 1 && this.Board.Grid[this.Board.Pieces[Player.BLACK][0].number][this.Board.Pieces[Player.BLACK][0].letter].piece == Piece.KING;

            if (!LegalMoveSet.hasMoves(this.Board, this.Turn))
            {
                if (LegalMoveSet.isCheck(this.Board, this.Turn))
                {
                    this.m_UI.LogMove("Checkmate!\n");
                    this.m_UI.SetStatus(false, ((this.Turn == Player.WHITE) ? "Black" : "White") + " wins!");
                }
                else
                {
                    this.m_UI.LogMove("Stalemate!\n");
                }
                return(true);
            }
            else if (wkingonly && bkingonly)
            {
                this.m_UI.LogMove("Draw.\n");
                return(true);
            }
            return(false);
        }
Пример #2
0
        private void MakeMove(move_t m)
        {
            // start move log output
            string move = (this.Turn == Player.WHITE) ? "W" : "B";

            move += ":\t";

            // piece
            switch (this.Board.Grid[m.from.number][m.from.letter].piece)
            {
            case Piece.PAWN:
                move += "P";
                break;

            case Piece.ROOK:
                move += "R";
                break;

            case Piece.KNIGHT:
                move += "k";
                break;

            case Piece.BISHOP:
                move += "B";
                break;

            case Piece.QUEEN:
                move += "Q";
                break;

            case Piece.KING:
                move += "K";
                break;
            }

            // kill
            if (this.Board.Grid[m.to.number][m.to.letter].piece != Piece.NONE || LegalMoveSet.isEnPassant(this.Board, m))
            {
                move += "x";
            }

            // letter
            switch (m.to.letter)
            {
            case 0: move += "a"; break;

            case 1: move += "b"; break;

            case 2: move += "c"; break;

            case 3: move += "d"; break;

            case 4: move += "e"; break;

            case 5: move += "f"; break;

            case 6: move += "g"; break;

            case 7: move += "h"; break;
            }

            // number
            move += (m.to.number + 1).ToString();

            // update board / make actual move
            this.Board = LegalMoveSet.move(this.Board, m);

            // if that move put someone in check
            if (LegalMoveSet.isCheck(this.Board, (Turn == Player.WHITE) ? Player.BLACK : Player.WHITE))
            {
                move += "+";
            }

            // show log
            this.m_UI.LogMove(move + "\n");
        }