Example #1
0
    public MoveResult Move(Position origin, Position destination)
    {
        var move = new Move(origin, destination, this.Board);

        move.Legality = Legality.CheckMove(move, this.Board, this.Turn);

        this.LastAttemptedMove = move;

        switch (move.Legality)
        {
        case Rule.None:
            this.LastMove = this.LastAttemptedMove;

            this.CompleteMove(move);

            var win = false;
            if (win)
            {
                move.MoveResult = MoveResult.Checkmate;
                return(MoveResult.Checkmate);
            }

            move.MoveResult = MoveResult.Legal;
            break;

        case Rule.InCheck:
            move.MoveResult = MoveResult.Check;
            break;

        default:
            move.MoveResult = MoveResult.Illegal;
            break;
        }

        return(move.MoveResult);
    }
Example #2
0
        private static bool GetLegality(int originRank, int originFile, int destinationRank, int destinationFile, Board board)
        {
            var move = GetMove(originRank, originFile, destinationRank, destinationFile, board);

            return(Legality.CheckMove(move, board, new Player(move.Piece.Color)) == Rule.None);
        }