public bool testCheck(Collor collor)
 {
     if (!kingCheck(collor))
     {
         return(false);
     }
     foreach (Piece x in pieceGame(collor))
     {
         bool[,] mat = x.possiMov();
         for (int i = 0; i < tab.lines; i++)
         {
             for (int j = 0; j < tab.coluns; j++)
             {
                 if (mat[i, j])
                 {
                     Position orig          = x.position;
                     Position desti         = new Position(i, j);
                     Piece    capturedPiece = exMovi(x.position, desti);
                     bool     testCheck     = kingCheck(collor);
                     cancelMov(orig, desti, capturedPiece);
                     if (!testCheck)
                     {
                         return(false);
                     }
                 }
             }
         }
     }
     return(true);
 }
Beispiel #2
0
 public Piece(Collor collor, Board board)
 {
     this.position    = null;
     this.collor      = collor;
     this.board       = board;
     this.amountOfMov = 0;
 }
Beispiel #3
0
        public bool CheckMate(Collor collor)
        {
            if (!InChedk(collor))
            {
                return(false);
            }
            foreach (Piece xequeMate in PiecesOnBoardChess(collor))
            {
                bool[,] xeque = xequeMate.CharacteringMove();
                for (int i = 0; i < chess.lines; i++)
                {
                    for (int j = 0; j < chess.collumns; j++)
                    {
                        if (xeque[i, j])
                        {
                            Position take        = xequeMate.position;
                            Position put         = new Position(i, j);
                            Piece    captured    = Movable(take, put);
                            bool     inXequeMate = InChedk(collor);
                            RewindMove(take, put, captured);

                            if (!inXequeMate)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            return(true);
        }
Beispiel #4
0
 /// <summary> Constructor da classe Peça.</summary>
 /// <param name="board"></param>
 /// <param name="collor"></param>
 public Piece(Board board, Collor collor)
 {
     position               = null;
     this.board             = board;
     this.collor            = collor;
     movement               = 0;
     Console.OutputEncoding = System.Text.Encoding.Unicode; // para as imagens das peças.
 }
 private Collor opponent(Collor collor)
 {
     if (collor == Collor.White)
     {
         return(Collor.Black);
     }
     else
     {
         return(Collor.White);
     }
 }
Beispiel #6
0
 /// <summary>Peça adverçaria.</summary>
 /// <param name="collor"></param>
 /// <returns></returns>
 private Collor AnotherPlayer(Collor collor)
 {
     if (collor == Collor.WHITE)
     {
         return(Collor.BLACK);
     }
     else
     {
         return(Collor.WHITE);
     }
 }
Beispiel #7
0
 /// <summary>Devolve o rei de dada cor.</summary>
 /// <param name="collor"></param>
 /// <returns>null se não existir rei.</returns>
 private Piece TheKing(Collor collor)
 {
     foreach (Piece found in PiecesOnBoardChess(collor))
     {
         if (found is King)
         {
             return(found);
         }
     }
     return(null);
 }
 private Piece king(Collor collor)
 {
     foreach (Piece x in pieceGame(collor))
     {
         if (x is King)
         {
             return(x);
         }
     }
     return(null);
 }
        public HashSet <Piece> piecesCaptured(Collor collor)
        {
            HashSet <Piece> aux = new HashSet <Piece>();

            foreach (Piece x in capturated)
            {
                if (x.collor == collor)
                {
                    aux.Add(x);
                }
            }
            return(aux);
        }
Beispiel #10
0
        /// <summary>Conjunto das peças capturadas separadas por cor.</summary>
        /// <param name="collor"></param>
        /// <returns></returns>
        public HashSet <Piece> PiecesCaptureSepareteCollor(Collor collor)
        {
            HashSet <Piece> separetePieceCollor = new HashSet <Piece>();

            foreach (Piece x in captured)
            {
                if (x.collor.Equals(collor))
                {
                    separetePieceCollor.Add(x);
                }
            }
            return(separetePieceCollor);
        }
Beispiel #11
0
        /// <summary>Conjunto das peças em jogo.</summary>
        /// <param name="collor"></param>
        /// <returns></returns>
        public HashSet <Piece> PiecesOnBoardChess(Collor collor)
        {
            HashSet <Piece> piecesOnBoard = new HashSet <Piece>();

            foreach (Piece fill in pieces)
            {
                if (fill.collor.Equals(collor))
                {
                    piecesOnBoard.Add(fill);
                }
            }
            piecesOnBoard.ExceptWith(PiecesCaptureSepareteCollor(collor));// exceto essa cor.
            return(piecesOnBoard);
        }
        public HashSet <Piece> pieceGame(Collor collor)
        {
            HashSet <Piece> aux = new HashSet <Piece>();

            foreach (Piece x in pieces)
            {
                if (x.collor == collor)
                {
                    aux.Add(x);
                }
            }
            aux.ExceptWith(piecesCaptured(collor));
            return(aux);
        }
        public bool kingCheck(Collor collor)
        {
            Piece K = king(collor);

            if (K == null)
            {
                throw new BoardException("Dont have King " + collor + " on the board");
            }
            foreach (Piece x in pieceGame(opponent(collor)))
            {
                bool[,] mat = x.possiMov();
                if (mat[K.position.line, K.position.column])
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #14
0
        /// <summary>Está em xeque.</summary>
        /// <param name="collor"></param>
        /// <returns></returns>
        public bool InChedk(Collor collor)
        {
            Piece king = TheKing(collor);

            if (king == null)
            {
                throw new ExceptionChess($"{image[2]}Not have of collor the king {collor} on board chess.");
            }
            foreach (Piece move in PiecesOnBoardChess(AnotherPlayer(collor)))
            {
                bool[,] movePossible = move.CharacteringMove();
                if (movePossible[king.position.line, king.position.collumn])
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #15
0
 public King(Board board, Collor collor, ChessMatch match) : base(collor, board)
 {
     this.match = match;
 }
Beispiel #16
0
 public Knight(Board board, Collor collor) : base(board, collor)
 {
 }
Beispiel #17
0
 /// <summary>Construtor da classe Rei (King).</summary>
 /// <param name="board"></param>
 /// <param name="collor"></param>
 public King(Board board, Collor collor, GameManager situation) : base(board, collor)
 {
     this.situation = situation;
 }
Beispiel #18
0
 public Queen(Board board, Collor collor) : base(collor, board)
 {
 }
Beispiel #19
0
 public Bishop(Board board, Collor collor) : base(board, collor)
 {
 }
Beispiel #20
0
 public Pawn(Board board, Collor collor, GameManager passant) : base(board, collor)
 {
     this.passant = passant;
 }
Beispiel #21
0
 public Tower(Board board, Collor collor) : base(collor, board)
 {
 }
Beispiel #22
0
 public Bishop(Board board, Collor collor) : base(collor, board)
 {
 }
Beispiel #23
0
 public Knight(Board board, Collor collor) : base(collor, board)
 {
 }
Beispiel #24
0
 /// <summary>Construtor.</summary>
 /// <param name="board"></param>
 /// <param name="collor"></param>
 public Rock(Board board, Collor collor) : base(board, collor)
 {
 }
Beispiel #25
0
 public Queen(Board board, Collor collor) : base(board, collor)
 {
 }