Example #1
0
 private void SetViewList()
 {
     Square[,] boardPiece = board.GetBoard();
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             if (board.GetBoard()[i, j].HasPiece())
             {
                 viewBoard[i, j] = new PieceView(board.GetBoard()[i, j].GetPiece());
             }
         }
     }
 }
Example #2
0
 private void SetViewList()
 {
     Boolean[,] boardBoolean = board.GetHasPiece();
     Piece[,] boardPiece     = board.GetBoard();
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             if (board.GetHasPiece()[i, j])
             {
                 viewBoard[i, j] = new PieceView(board.GetBoard()[i, j]);
             }
         }
     }
 }
Example #3
0
        private static List <BoardPosition> CheckCastling(BoardPosition bp, ChessBoardView pChessBoard)
        {
            List <BoardPosition> boardPositionList = new List <BoardPosition>();

            boardPositionList.Add(bp);
            Piece     p  = pChessBoard.GetChessBoard().GetBoard()[bp.X, bp.Y].GetPiece();
            PieceView pv = pChessBoard.GetViewBoard()[bp.X, bp.Y];

            int i = bp.X;
            int j = bp.Y;

            if (p.color == Piece.Colors.WHITE)
            {
                if (!pv.GetHasMoved())
                {
                    if (pChessBoard.GetChessBoard().GetBoard()[0, 7].GetPiece() != null)
                    {
                        if (pChessBoard.GetChessBoard().GetBoard()[0, 7].GetPiece().pieceType.type == PieceType.Types.ROOK)
                        {
                            if (!pChessBoard.GetViewBoard()[0, 7].GetHasMoved())
                            {
                                if (!pChessBoard.GetChessBoard().GetBoard()[1, 7].HasPiece() &&
                                    !pChessBoard.GetChessBoard().GetBoard()[2, 7].HasPiece() &&
                                    !pChessBoard.GetChessBoard().GetBoard()[3, 7].HasPiece())
                                {
                                    if (!SquareIsThreatened(pChessBoard.GetChessBoard().GetBoard()[4, 7].GetPiece(), new BoardPosition(0, 7), pChessBoard) &&
                                        !SquareIsThreatened(pChessBoard.GetChessBoard().GetBoard()[4, 7].GetPiece(), new BoardPosition(1, 7), pChessBoard) &&
                                        !SquareIsThreatened(pChessBoard.GetChessBoard().GetBoard()[4, 7].GetPiece(), new BoardPosition(2, 7), pChessBoard) &&
                                        !SquareIsThreatened(pChessBoard.GetChessBoard().GetBoard()[4, 7].GetPiece(), new BoardPosition(3, 7), pChessBoard) &&
                                        !SquareIsThreatened(pChessBoard.GetChessBoard().GetBoard()[4, 7].GetPiece(), new BoardPosition(5, 7), pChessBoard))
                                    {
                                        boardPositionList.Add(new BoardPosition(2, 7));
                                    }
                                }
                            }
                        }
                    }
                    if (pChessBoard.GetChessBoard().GetBoard()[7, 7].GetPiece() != null)
                    {
                        if (pChessBoard.GetChessBoard().GetBoard()[7, 7].GetPiece().pieceType.type == PieceType.Types.ROOK)
                        {
                            if (!pChessBoard.GetViewBoard()[7, 7].GetHasMoved())
                            {
                                if (!pChessBoard.GetChessBoard().GetBoard()[6, 7].HasPiece() &&
                                    !pChessBoard.GetChessBoard().GetBoard()[5, 7].HasPiece())
                                {
                                    if (!SquareIsThreatened(pChessBoard.GetChessBoard().GetBoard()[4, 7].GetPiece(), new BoardPosition(4, 7), pChessBoard) &&
                                        !SquareIsThreatened(pChessBoard.GetChessBoard().GetBoard()[4, 7].GetPiece(), new BoardPosition(5, 7), pChessBoard) &&
                                        !SquareIsThreatened(pChessBoard.GetChessBoard().GetBoard()[4, 7].GetPiece(), new BoardPosition(6, 7), pChessBoard) &&
                                        !SquareIsThreatened(pChessBoard.GetChessBoard().GetBoard()[4, 7].GetPiece(), new BoardPosition(7, 7), pChessBoard))
                                    {
                                        boardPositionList.Add(new BoardPosition(6, 7));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (p.color == Piece.Colors.BLACK)
            {
                if (!pv.GetHasMoved())
                {
                    if (pChessBoard.GetChessBoard().GetBoard()[0, 0].GetPiece() != null)
                    {
                        if (pChessBoard.GetChessBoard().GetBoard()[0, 0].GetPiece().pieceType.type == PieceType.Types.ROOK)
                        {
                            if (!pChessBoard.GetViewBoard()[0, 0].GetHasMoved())
                            {
                                if (!pChessBoard.GetChessBoard().GetBoard()[1, 0].HasPiece() &&
                                    !pChessBoard.GetChessBoard().GetBoard()[2, 0].HasPiece() &&
                                    !pChessBoard.GetChessBoard().GetBoard()[3, 0].HasPiece())
                                {
                                    if (!SquareIsThreatened(pChessBoard.GetChessBoard().GetBoard()[4, 0].GetPiece(), new BoardPosition(1, 0), pChessBoard) &&
                                        !SquareIsThreatened(pChessBoard.GetChessBoard().GetBoard()[4, 0].GetPiece(), new BoardPosition(2, 0), pChessBoard) &&
                                        !SquareIsThreatened(pChessBoard.GetChessBoard().GetBoard()[4, 0].GetPiece(), new BoardPosition(3, 0), pChessBoard))
                                    {
                                        boardPositionList.Add(new BoardPosition(2, 0));
                                    }
                                }
                            }
                        }
                    }
                    if (pChessBoard.GetChessBoard().GetBoard()[7, 0].GetPiece() != null)
                    {
                        if (pChessBoard.GetChessBoard().GetBoard()[7, 0].GetPiece().pieceType.type == PieceType.Types.ROOK)
                        {
                            if (!pChessBoard.GetViewBoard()[7, 0].GetHasMoved())
                            {
                                if (!pChessBoard.GetChessBoard().GetBoard()[6, 0].HasPiece() &&
                                    !pChessBoard.GetChessBoard().GetBoard()[5, 0].HasPiece())
                                {
                                    if (!SquareIsThreatened(pChessBoard.GetChessBoard().GetBoard()[4, 7].GetPiece(), new BoardPosition(5, 0), pChessBoard) &&
                                        !SquareIsThreatened(pChessBoard.GetChessBoard().GetBoard()[4, 7].GetPiece(), new BoardPosition(6, 0), pChessBoard))
                                    {
                                        boardPositionList.Add(new BoardPosition(6, 0));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(boardPositionList);
        }
Example #4
0
        private static List <BoardPosition> GetKingMoves(BoardPosition bp, ChessBoardView pChessBoard)
        {
            List <BoardPosition> boardPositionList = new List <BoardPosition>();

            boardPositionList.Add(bp);
            Piece     p  = pChessBoard.GetChessBoard().GetBoard()[bp.X, bp.Y].GetPiece();
            PieceView pv = pChessBoard.GetViewBoard()[bp.X, bp.Y];

            int i = bp.X;
            int j = bp.Y;

            boardPositionList.AddRange(CheckCastling(bp, pChessBoard));
            ///////////////
            if (i >= 1)
            {
                if (j >= 1)
                {
                    if (!pChessBoard.GetChessBoard().GetBoard()[i - 1, j - 1].HasPiece())
                    {
                        boardPositionList.Add(new BoardPosition(i - 1, j - 1));
                    }
                    else
                    {
                        if (!p.IsSameColor(pChessBoard.GetChessBoard().GetBoard()[i - 1, j - 1].GetPiece()))
                        {
                            boardPositionList.Add(new BoardPosition(i - 1, j - 1));
                        }
                    }
                }

                if (!pChessBoard.GetChessBoard().GetBoard()[i - 1, j].HasPiece())
                {
                    boardPositionList.Add(new BoardPosition(i - 1, j));
                }
                else
                {
                    if (j < 7)
                    {
                        if (!p.IsSameColor(pChessBoard.GetChessBoard().GetBoard()[i - 1, j + 1].GetPiece()))
                        {
                            boardPositionList.Add(new BoardPosition(i - 1, j + 1));
                        }
                    }
                }

                if (j <= 6)
                {
                    if (!pChessBoard.GetChessBoard().GetBoard()[i - 1, j + 1].HasPiece())
                    {
                        boardPositionList.Add(new BoardPosition(i - 1, j + 1));
                    }
                    else
                    {
                        if (!p.IsSameColor(pChessBoard.GetChessBoard().GetBoard()[i - 1, j + 1].GetPiece()))
                        {
                            boardPositionList.Add(new BoardPosition(i - 1, j + 1));
                        }
                    }
                }
            }
            if (j >= 1)
            {
                if (!pChessBoard.GetChessBoard().GetBoard()[i, j - 1].HasPiece())
                {
                    boardPositionList.Add(new BoardPosition(i, j - 1));
                }
                else
                {
                    if (!p.IsSameColor(pChessBoard.GetChessBoard().GetBoard()[i, j - 1].GetPiece()))
                    {
                        boardPositionList.Add(new BoardPosition(i, j - 1));
                    }
                }
            }
            if (j <= 6)
            {
                if (!pChessBoard.GetChessBoard().GetBoard()[i, j + 1].HasPiece())
                {
                    boardPositionList.Add(new BoardPosition(i, j + 1));
                }
                else
                {
                    if (!p.IsSameColor(pChessBoard.GetChessBoard().GetBoard()[i, j + 1].GetPiece()))
                    {
                        boardPositionList.Add(new BoardPosition(i, j + 1));
                    }
                }
            }
            if (i <= 6)
            {
                if (j >= 1)
                {
                    if (!pChessBoard.GetChessBoard().GetBoard()[i + 1, j - 1].HasPiece())
                    {
                        boardPositionList.Add(new BoardPosition(i + 1, j - 1));
                    }
                    else
                    {
                        if (!p.IsSameColor(pChessBoard.GetChessBoard().GetBoard()[i + 1, j - 1].GetPiece()))
                        {
                            boardPositionList.Add(new BoardPosition(i + 1, j - 1));
                        }
                    }
                }

                if (!pChessBoard.GetChessBoard().GetBoard()[i + 1, j].HasPiece())
                {
                    boardPositionList.Add(new BoardPosition(i + 1, j));
                }
                else
                {
                    if (j < 7)
                    {
                        if (!p.IsSameColor(pChessBoard.GetChessBoard().GetBoard()[i + 1, j + 1].GetPiece()))
                        {
                            boardPositionList.Add(new BoardPosition(i + 1, j + 1));
                        }
                    }
                }

                if (j <= 6)
                {
                    if (!pChessBoard.GetChessBoard().GetBoard()[i + 1, j + 1].HasPiece())
                    {
                        boardPositionList.Add(new BoardPosition(i + 1, j + 1));
                    }
                    else
                    {
                        if (!p.IsSameColor(pChessBoard.GetChessBoard().GetBoard()[i + 1, j + 1].GetPiece()))
                        {
                            boardPositionList.Add(new BoardPosition(i + 1, j + 1));
                        }
                    }
                }
            }
            return(boardPositionList);
        }