Ejemplo n.º 1
0
 bool IsLegalMove(ChessPiece pieceUserWantToMove, Location target, ref string message)
 {
     if ((IsWhiteTurn() && !pieceUserWantToMove.isWhite) || (!IsWhiteTurn() && pieceUserWantToMove.isWhite))
     {
         message = "Not your turn!!!";
         return(false);
     }
     else if (target.x > 7 || target.x < 0 || target.y < 0 || target.y > 7)
     {
         message = "Stay in game boundries!!";
         return(false);
     }
     else if (board.GetSquareData(target) != null && board.GetSquareData(target).isWhite == pieceUserWantToMove.isWhite)
     {
         message = "Can't put piece on your own piece!!!";
         return(false);
     }
     else if (!pieceUserWantToMove.IsLegalMove(target))
     {
         message = "Iligal move!";
         return(false);
     }
     else if ((pieceUserWantToMove.IsInCheck() && !pieceUserWantToMove.IsMoveBlockCheck(target)) || pieceUserWantToMove.IsMoveMakeCheck(target))
     {
         message = "CHECK BLAT!!";
         return(false);
     }
     return(true);
 }
Ejemplo n.º 2
0
        List <Location> GetAllPossiblePieceMoves(ChessPiece piece)
        {
            var gameBoard        = this.board.GetBoard();
            var allPossibleMoves = new List <Location>();

            for (var i = 0; i < 8; i++)
            {
                for (var j = 0; j < 8; j++)
                {
                    if (gameBoard[i][j] != null && gameBoard[i][j].isWhite == piece.isWhite)
                    {
                        continue;
                    }
                    var targetLocation = new Location(i, j);
                    var str            = "";
                    if (piece.IsLegalMove(targetLocation) && IsLegalMove(piece, targetLocation, ref str))
                    {
                        allPossibleMoves.Add(targetLocation);
                    }
                }
            }
            return(allPossibleMoves);
        }