Esempio n. 1
0
        public void MakeMove(PieceMove move)
        {
            ChessColor oppositeColor = move.piece.color == ChessColor.White ? ChessColor.Black : ChessColor.White;
            Piece      piece         = move.piece;

            if (piece.color != turn)
            {
                return;
            }
            if (move.moveType == MoveType.Evolve)
            {
                ApplyMove(move);
                PieceEvolve?.Invoke(move.newPos, piece.color);
                //send a evolve event and ask for the piece to evolve
            }
            else if (move.moveType == MoveType.Switch)
            {
                //switch with king
            }
            else if (move.moveType == MoveType.Eat)
            {
                Piece deadPiece = chessBoard.Board[move.newPos.row, move.newPos.column];
                chessBoard.AddToGrave(deadPiece);
                PieceEaten?.Invoke(move.newPos);
                ApplyMove(move);
            }
            else if (move.moveType == MoveType.Normal)
            {
                ApplyMove(move);
            }
            check = IsCheckMate(move.newPos);
            ChangeTurn();
            CheckGame();
        }
Esempio n. 2
0
        bool TestMove(PieceMove move)
        {
            if (move.newPos == check.piecePos)
            {
                return(true);
            }
            chessBoard.Board[move.originPos.row, move.originPos.column] = null;
            Piece oldPiece = chessBoard.Board[move.newPos.row, move.newPos.column];

            chessBoard.Board[move.newPos.row, move.newPos.column] = move.piece;
            CheckInfo checkInfo = IsCheckMate(check.piecePos);

            chessBoard.Board[move.originPos.row, move.originPos.column] = move.piece;
            chessBoard.Board[move.newPos.row, move.newPos.column]       = oldPiece;
            if (checkInfo != null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Esempio n. 3
0
 void ApplyMove(PieceMove move)
 {
     chessBoard.Board[move.originPos.row, move.originPos.column] = null;
     chessBoard.Board[move.newPos.row, move.newPos.column]       = move.piece;
     PieceMoved?.Invoke(move.originPos, move.newPos);
 }