Пример #1
0
 public override double getValue(BoardGen board)
 {
     for (int x = 0; x < 8; x++)
     {
         for (int y = 0; y < 8; y++)
         {
             if (board.getPanels()[x, y] == getPanel())
             {
                 if (board.getPanels()[x, y] == getPanel())
                 {
                     double val = (getType().Substring(0, 1) == "W") ? KnightTable[x, y] : KnightTable[x, y];
                     return(val + 30);
                 }
             }
         }
     }
     return(0);
 }
Пример #2
0
        public override void setMoves(BoardGen board, bool checkUp, bool suicide)
        {
            possibleMoves = new List <Panel>();
            Panel tempPan = null;

            capturePossible = false;
            List <Panel> panelsRemove = new List <Panel>();

            /*A knight moves in a L shape pattern, any "L" shape (3 squares in a
             * straight line and then one to the left or right).*/

            foreach (Panel x in board.getPanels())
            {
                if ((getPanel().Location.X == x.Location.X + 40 ||
                     getPanel().Location.X == x.Location.X - 40) &&
                    (getPanel().Location.Y == x.Location.Y + 80 ||
                     getPanel().Location.Y == x.Location.Y - 80))
                {
                    if (board.getPanelsInUse().Contains(x))
                    {
                        foreach (Piece y in board.getPieces())
                        {
                            if (y.getPanel() == x)
                            {
                                if (getType().Substring(0, 1) !=
                                    y.getType().Substring(0, 1))
                                {
                                    possibleMoves.Add(x);
                                }
                            }
                        }
                    }
                    else
                    {
                        possibleMoves.Add(x);
                    }
                }
                if ((getPanel().Location.X == x.Location.X + 80 ||
                     getPanel().Location.X == x.Location.X - 80) &&
                    (getPanel().Location.Y == x.Location.Y + 40 ||
                     getPanel().Location.Y == x.Location.Y - 40))
                {
                    if (board.getPanelsInUse().Contains(x))
                    {
                        foreach (Piece y in board.getPieces())
                        {
                            if (y.getPanel() == x)
                            {
                                if (getType().Substring(0, 1) !=
                                    y.getType().Substring(0, 1))
                                {
                                    possibleMoves.Add(x);
                                }
                            }
                        }
                    }
                    else
                    {
                        possibleMoves.Add(x);
                    }
                }
            }

            foreach (Panel x in possibleMoves)
            {
                foreach (Piece p in board.getPieces())
                {
                    if (x == p.getPanel())
                    {
                        capturePossible = true;
                    }
                }
            }


            /*This part gets all the possible moves, no need to remove panels being
             * blocked as a knight can jump over pieces. The only thing that would
             * make it not possible is if a same coloured piece is on the panel, this
             * was easy enough to add to the if statements*/

            if (checkUp && !suicide) //if checking for check and this is not suicide chess (as chess doesn't exist in suicide chess)
            {
                Piece toRem   = null;
                bool  removed = false;
                tempPan = getPanel();
                foreach (Panel x in possibleMoves)
                {
                    if (board.getPanelsInUse().Contains(x))
                    {
                        foreach (Piece z in board.getPieces().ToList())
                        {
                            if (z.getPanel() == x)
                            {
                                toRem   = z;
                                removed = true;
                                board.RemovePiece(z);
                            }
                        }
                    }

                    setPanel(x);

                    board.setPanelsInUse();

                    foreach (Piece y in board.getPieces().ToList())
                    {
                        if (!y.getType().Contains(getType()))
                        {
                            y.setMoves(board, false, suicide);
                        }
                    }

                    if (checkCheck(board) && checkType() ==
                        getType().Substring(0, 1))
                    {
                        panelsRemove.Add(x);
                    }

                    setPanel(tempPan);

                    if (removed)
                    {
                        board.AddPiece(toRem);
                        removed = false;
                    }

                    board.setPanelsInUse();
                }

                foreach (Panel x in panelsRemove)
                {
                    possibleMoves.Remove(x);
                }
            }

            /* Exactly like all other pieces, this part checks all of the current
             * possible moves for the the bisop to see if any would leave the player
             * in check, if it would, it is not a valid move and is removed. */

            if (capturePossible && suicide) //if it is suicide chess and there is a capture possible
            {
                List <Panel> newPossibleMoves = new List <Panel>();
                foreach (Panel x in possibleMoves)
                {
                    foreach (Piece y in board.getPieces())
                    {
                        if (x == y.getPanel())
                        {
                            newPossibleMoves.Add(x);
                        }
                    }
                }
                possibleMoves = newPossibleMoves;
                //captures are the only possible moves if a capture is possible
            }
            else if (!capturePossible && suicide) //if there no captures possible in suicide chess
            {
                foreach (Piece x in board.getPieces())
                {
                    if (x.capture() && x.getType().Substring(0, 1) == getType().Substring(0, 1))
                    {
                        possibleMoves = new List <Panel>();
                        break;
                        //if there are no possible captures, but there are possible captures from other pieces, this piece cannot move
                    }
                }
            }
        }
Пример #3
0
        public override void setMoves(BoardGen board, bool checkUp, bool suicide)
        {
            possibleMoves = new List <Panel>();
            List <Panel> panelsRemove = new List <Panel>();
            Piece        piece        = null;
            Panel        tempPan      = null;

            capturePossible = false;


            //A king can move 1 sqaure in any direction.



            foreach (Panel x in board.getPanels())
            {
                foreach (Piece c in board.getPieces())
                {
                    if (c.getPanel() == x)
                    {
                        piece = c;
                    }
                }
                if (x.Location.X == getPanel().Location.X)
                {
                    if (x.Location.Y == getPanel().Location.Y + 40 ||
                        x.Location.Y == getPanel().Location.Y - 40)
                    {
                        possibleMoves.Add(x);
                    }
                }
                if (x.Location.X == getPanel().Location.X + 40)
                {
                    if (x.Location.Y == getPanel().Location.Y + 40 ||
                        x.Location.Y == getPanel().Location.Y - 40 ||
                        x.Location.Y == getPanel().Location.Y)
                    {
                        possibleMoves.Add(x);
                    }
                }
                if (x.Location.X == getPanel().Location.X - 40)
                {
                    if (x.Location.Y == getPanel().Location.Y + 40 ||
                        x.Location.Y == getPanel().Location.Y - 40 ||
                        x.Location.Y == getPanel().Location.Y)
                    {
                        possibleMoves.Add(x);
                    }
                }

                /*Similarly to other pieces this section gets all moves that would
                 * be possible for the king on an empty board*/


                if (piece != null)
                {
                    if (piece.getType().Substring(0, 1) == getType().Substring(0, 1) &&
                        board.getPanelsInUse().Contains(x))
                    {
                        panelsRemove.Add(x);
                    }
                    else
                    {
                    }
                }

                /*And this just adds all the blocked sqaures to a list of not
                 * possible moves*/
            }

            foreach (Panel x in panelsRemove)
            {
                possibleMoves.Remove(x);
            }
            bool castle1 = false;
            bool castle2 = false;

            if (!getMoved())
            {
                if (!board.getPanelsInUse().Contains(board.getPanels()[5, getType().Substring(0, 1) == "W" ? 7 : 0]) && !board.getPanelsInUse().Contains(board.getPanels()[6, getType().Substring(0, 1) == "W" ? 7 : 0]))
                {
                    possibleMoves.Add(board.getPanels()[6, getType().Substring(0, 1) == "W" ? 7 : 0]);

                    castle1 = true;
                }

                if (!board.getPanelsInUse().Contains(board.getPanels()[1, getType().Substring(0, 1) == "W" ? 7 : 0]) && !board.getPanelsInUse().Contains(board.getPanels()[2, getType().Substring(0, 1) == "W" ? 7 : 0]) && !board.getPanelsInUse().Contains(board.getPanels()[3, getType().Substring(0, 1) == "W" ? 7 : 0]))
                {
                    possibleMoves.Add(board.getPanels()[2, getType().Substring(0, 1) == "W" ? 7 : 0]);

                    castle2 = true;
                }
            }

            if (checkUp && !suicide) //if checking for check and this is not suicide chess (as chess doesn't exist in suicide chess)
            {
                Piece toRem   = null;
                bool  removed = false;
                tempPan = getPanel();
                foreach (Panel x in possibleMoves)
                {
                    if (board.getPanelsInUse().Contains(x))
                    {
                        foreach (Piece z in board.getPieces().ToList())
                        {
                            if (z.getPanel() == x)
                            {
                                toRem   = z;
                                removed = true;
                                board.RemovePiece(z);
                            }
                        }
                    }
                    setPanel(x);
                    board.setPanelsInUse();

                    foreach (Piece y in board.getPieces().ToList())
                    {
                        if (!y.getType().Contains(getType()))
                        {
                            y.setMoves(board, false, suicide);
                        }
                    }

                    if (checkCheck(board))
                    {
                        if (castle1 && x == board.getPanels()[5, getType().Substring(0, 1) == "W" ? 7 : 0])
                        {
                            panelsRemove.Add(board.getPanels()[6, getType().Substring(0, 1) == "W" ? 7 : 0]);
                        }
                        if (castle2 && x == board.getPanels()[3, getType().Substring(0, 1) == "W" ? 7 : 0])
                        {
                            panelsRemove.Add(board.getPanels()[2, getType().Substring(0, 1) == "W" ? 7 : 0]);
                        }
                        panelsRemove.Add(x);
                    }

                    setPanel(tempPan);

                    if (removed)
                    {
                        board.AddPiece(toRem);
                        removed = false;
                    }

                    board.setPanelsInUse();
                }

                foreach (Panel x in panelsRemove)
                {
                    possibleMoves.Remove(x);
                }

                foreach (Panel x in possibleMoves)
                {
                    foreach (Piece p in board.getPieces())
                    {
                        if (x == p.getPanel())
                        {
                            capturePossible = true;
                        }
                    }
                }
            }

            /* Exactly like all other pieces, this part checks all of the current
             * possible moves for the queen to see if any would leave the player
             * in check, if it would, it is not a valid move and is removed. */

            if (capturePossible && suicide) //if it is suicide chess and there is a capture possible
            {
                List <Panel> newPossibleMoves = new List <Panel>();
                foreach (Panel x in possibleMoves)
                {
                    foreach (Piece y in board.getPieces())
                    {
                        if (x == y.getPanel())
                        {
                            newPossibleMoves.Add(x);
                        }
                    }
                }
                possibleMoves = newPossibleMoves;
                //captures are the only possible moves if a capture is possible
            }
            else if (!capturePossible && suicide) //if there no captures possible in suicide chess
            {
                foreach (Piece x in board.getPieces())
                {
                    if (x.capture() && x.getType().Substring(0, 1) == getType().Substring(0, 1))
                    {
                        possibleMoves = new List <Panel>();
                        break;
                        //if there are no possible captures, but there are possible captures from other pieces, this piece cannot move
                    }
                }
            }
        }
Пример #4
0
        public override void setMoves(BoardGen board, bool checkUp, bool suicide)
        {
            possibleMoves = new List <Panel>();
            Piece piece   = null;
            Panel tempPan = null;

            capturePossible = false;

            //A bishop may move along the diagnol it is on

            foreach (Panel x in board.getPanels())
            {
                for (int i = 0; i < 8; i++)
                {
                    foreach (Piece c in board.getPieces())
                    {
                        if (c.getPanel() == x)
                        {
                            piece = c;
                        }
                    }

                    if ((getPanel().Location.X == x.Location.X + (40 * i) ||
                         getPanel().Location.X == x.Location.X - (40 * i)) &&
                        (getPanel().Location.Y == x.Location.Y + (40 * i) ||
                         getPanel().Location.Y == x.Location.Y - (40 * i)))
                    {
                        if (board.getPanelsInUse().Contains(x))
                        {
                            foreach (Piece y in board.getPieces())
                            {
                                if (y.getPanel() == x)
                                {
                                    if (getType().Substring(0, 1) !=
                                        y.getType().Substring(0, 1))
                                    {
                                        possibleMoves.Add(x);
                                    }
                                }
                            }
                        }
                        else
                        {
                            possibleMoves.Add(x);
                        }
                    }
                }
            }

            /* This bit just gets all of the panels in a diagonal direction from the
             * bishop in use */

            List <Panel> panelsRemove = new List <Panel>();

            foreach (Panel x in board.getPanels())
            {
                for (int i = 0; i < 8; i++)
                {
                    if ((getPanel().Location.X == x.Location.X + (40 * i) ||
                         getPanel().Location.X == x.Location.X - (40 * i)) &&
                        (getPanel().Location.Y == x.Location.Y + (40 * i) ||
                         getPanel().Location.Y == x.Location.Y - (40 * i)) &&
                        board.getPanelsInUse().Contains(x))
                    {
                        if (x.Location.Y < getPanel().Location.Y&&
                            x.Location.X < getPanel().Location.X)
                        {
                            foreach (Panel g in possibleMoves)
                            {
                                if (g.Location.Y < x.Location.Y && g.Location.X <
                                    x.Location.X)
                                {
                                    panelsRemove.Add(g);
                                }
                            }
                        }
                        else if (x.Location.Y < getPanel().Location.Y&&
                                 x.Location.X > getPanel().Location.X)
                        {
                            foreach (Panel g in possibleMoves)
                            {
                                if (g.Location.Y < x.Location.Y && g.Location.X >
                                    x.Location.X)
                                {
                                    panelsRemove.Add(g);
                                }
                            }
                        }
                        else if (x.Location.Y > getPanel().Location.Y&&
                                 x.Location.X < getPanel().Location.X)
                        {
                            foreach (Panel g in possibleMoves)
                            {
                                if (g.Location.Y > x.Location.Y && g.Location.X <
                                    x.Location.X)
                                {
                                    panelsRemove.Add(g);
                                }
                            }
                        }
                        else if (x.Location.Y > getPanel().Location.Y&&
                                 x.Location.X > getPanel().Location.X)
                        {
                            foreach (Panel g in possibleMoves)
                            {
                                if (g.Location.Y > x.Location.Y &&
                                    g.Location.X > x.Location.X)
                                {
                                    panelsRemove.Add(g);
                                }
                            }
                        }
                    }
                }
            }

            /* This part adds all of the panels that are blocked in some way to an
             * array that removes all of those panels from possible moves (the next
             * part */

            foreach (Panel x in possibleMoves)
            {
                foreach (Piece p in board.getPieces())
                {
                    if (x == p.getPanel())
                    {
                        capturePossible = true;
                    }
                }
            }


            foreach (Panel x in panelsRemove)
            {
                possibleMoves.Remove(x);
            }

            if (checkUp && !suicide) //if checking for check and this is not suicide chess (as chess doesn't exist in suicide chess)
            {
                Piece toRem   = null;
                bool  removed = false;
                tempPan = getPanel();
                foreach (Panel x in possibleMoves)
                {
                    if (board.getPanelsInUse().Contains(x))
                    {
                        foreach (Piece z in board.getPieces().ToList())
                        {
                            if (z.getPanel() == x)
                            {
                                toRem   = z;
                                removed = true;
                                board.RemovePiece(z);
                            }
                        }
                    }

                    setPanel(x);

                    board.setPanelsInUse();

                    foreach (Piece y in board.getPieces().ToList())
                    {
                        if (!y.getType().Contains(getType()))
                        {
                            y.setMoves(board, false, suicide);
                        }
                    }

                    if (checkCheck(board) && checkType() ==
                        getType().Substring(0, 1))
                    {
                        panelsRemove.Add(x);
                    }

                    setPanel(tempPan);

                    if (removed)
                    {
                        board.AddPiece(toRem);
                        removed = false;
                    }

                    board.setPanelsInUse();
                }

                /* This part checks all of the current possible moves for the
                 * the bisop to see if any would leave the player in check, if it
                 * would, it is not a valid move and is removed. */

                foreach (Panel x in panelsRemove)
                {
                    possibleMoves.Remove(x);
                }
            }

            if (capturePossible && suicide) //if it is suicide chess and there is a capture possible
            {
                List <Panel> newPossibleMoves = new List <Panel>();
                foreach (Panel x in possibleMoves)
                {
                    foreach (Piece y in board.getPieces())
                    {
                        if (x == y.getPanel())
                        {
                            newPossibleMoves.Add(x);
                        }
                    }
                }
                possibleMoves = newPossibleMoves;
                //captures are the only possible moves if a capture is possible
            }
            else if (!capturePossible && suicide) //if there no captures possible in suicide chess
            {
                foreach (Piece x in board.getPieces())
                {
                    if (x.capture() && x.getType().Substring(0, 1) == getType().Substring(0, 1))
                    {
                        possibleMoves = new List <Panel>();
                        break;
                        //if there are no possible captures, but there are possible captures from other pieces, this piece cannot move
                    }
                }
            }
        }
Пример #5
0
        public override void setMoves(BoardGen board, bool checkUp, bool suicide)
        {
            Piece piece   = null;
            Panel tempPan = null;

            possibleMoves = new List <Panel>();
            List <Panel> panelsRemove = new List <Panel>();

            capturePossible = false;
            bool noMoves = false;

            /*White's pawns can move up the board, Black's move down. If it is
             * the first move then a pawn can move two squares, otherwise only
             * one. Pawns also take other pieces diagonaly.*/

            foreach (Panel x in board.getPanels())
            {
                foreach (Piece c in board.getPieces())
                {
                    if (c.getPanel() == x)
                    {
                        piece = c;
                    }
                }
                if (piece != null)
                {
                    if (getType().Substring(0, 1).Equals("W"))
                    {
                        if (board.getPanelsInUse().Contains(x) &&
                            (x.Location.Y == getPanel().Location.Y - 40) &&
                            (x.Location.X == getPanel().Location.X))
                        {
                            noMoves = true;
                            foreach (Panel z in board.getPanels())
                            {
                                if ((((getPanel().Location.Y == z.Location.Y + 40) &&
                                      (z.Location.X == getPanel().Location.X - 40)) ||
                                     (z.Location.X == getPanel().Location.X + 40)))
                                {
                                    noMoves = false;
                                }
                            }
                        }
                        else if (!(board.getPanelsInUse().Contains(x)) &&
                                 (getPanel().Location.Y == 240) &&
                                 ((x.Location.Y == getPanel().Location.Y - 40) ||
                                  (x.Location.Y == getPanel().Location.Y - 80)) &&
                                 (x.Location.X == getPanel().Location.X))
                        {
                            possibleMoves.Add(x);
                        }
                        else if (!(board.getPanelsInUse().Contains(x)) &&
                                 (x.Location.Y == getPanel().Location.Y - 40) &&
                                 (x.Location.X == getPanel().Location.X))
                        {
                            possibleMoves.Add(x);
                        }
                        else if (board.getPanelsInUse().Contains(x) &&
                                 (getType().Substring(0, 1) !=
                                  piece.getType().Substring(0, 1)))
                        {
                            if ((getPanel().Location.Y == x.Location.Y + 40 &&
                                 (x.Location.X == getPanel().Location.X - 40 ||
                                  x.Location.X == getPanel().Location.X + 40)))
                            {
                                possibleMoves.Add(x);
                            }
                        }
                    }
                    else if (getType().Substring(0, 1).Equals("B"))
                    {
                        if (board.getPanelsInUse().Contains(x) &&
                            (x.Location.Y == getPanel().Location.Y + 40) &&
                            (x.Location.X == getPanel().Location.X))
                        {
                            noMoves = true;
                            foreach (Panel z in board.getPanels())
                            {
                                if ((((getPanel().Location.Y == z.Location.Y - 40) &&
                                      (z.Location.X == getPanel().Location.X - 40)) ||
                                     (z.Location.X == getPanel().Location.X + 40)))
                                {
                                    noMoves = false;
                                }
                            }
                        }
                        else if (!(board.getPanelsInUse().Contains(x)) &&
                                 (getPanel().Location.Y == 40) &&
                                 ((x.Location.Y == getPanel().Location.Y + 40) ||
                                  (x.Location.Y == getPanel().Location.Y + 80)) &&
                                 (x.Location.X == getPanel().Location.X))
                        {
                            possibleMoves.Add(x);
                        }
                        else if (!(board.getPanelsInUse().Contains(x)) &&
                                 (x.Location.Y == getPanel().Location.Y + 40) &&
                                 (x.Location.X == getPanel().Location.X))
                        {
                            possibleMoves.Add(x);
                        }
                        else if (board.getPanelsInUse().Contains(x) &&
                                 (getType().Substring(0, 1) !=
                                  piece.getType().Substring(0, 1)))
                        {
                            if ((getPanel().Location.Y == x.Location.Y - 40 &&
                                 (x.Location.X == getPanel().Location.X - 40 ||
                                  x.Location.X == getPanel().Location.X + 40)))
                            {
                                possibleMoves.Add(x);
                            }
                        }
                    }
                }
            }

            /*This section adds all the moves the pawn could make if the board were
             * empty to a list called possibleMoves and then all the ones that are
             * made invalid due to other pieces are added to the list called
             * panelsRemove*/

            foreach (Panel x in panelsRemove)
            {
                possibleMoves.Remove(x);
            }

            foreach (Panel x in possibleMoves)
            {
                foreach (Piece p in board.getPieces())
                {
                    if (x == p.getPanel())
                    {
                        capturePossible = true;
                    }
                }
            }


            if (checkUp && !suicide) //if checking for check and this is not suicide chess (as chess doesn't exist in suicide chess)
            {
                Piece toRem   = null;
                bool  removed = false;
                tempPan = getPanel();
                foreach (Panel x in possibleMoves)
                {
                    if (board.getPanelsInUse().Contains(x))
                    {
                        foreach (Piece z in board.getPieces().ToList())
                        {
                            if (z.getPanel() == x)
                            {
                                toRem   = z;
                                removed = true;
                                board.RemovePiece(z);
                            }
                        }
                    }

                    setPanel(x);

                    board.setPanelsInUse();

                    foreach (Piece y in board.getPieces().ToList())
                    {
                        if (!y.getType().Contains(getType()))
                        {
                            y.setMoves(board, false, suicide);
                        }
                    }

                    if (checkCheck(board) && checkType() == getType().Substring(0, 1))
                    {
                        panelsRemove.Add(x);
                    }

                    setPanel(tempPan);

                    if (removed)
                    {
                        board.AddPiece(toRem);
                        removed = false;
                    }

                    board.setPanelsInUse();
                }

                foreach (Panel x in panelsRemove)
                {
                    possibleMoves.Remove(x);
                }

                if (noMoves)
                {
                    possibleMoves = new List <Panel>();
                }
            }

            /* Exactly like all other pieces, this part checks all of the current
             * possible moves for the pawn to see if any would leave the player
             * in check, if it would, it is not a valid move and is removed. */

            if (capturePossible && suicide) //if it is suicide chess and there is a capture possible
            {
                List <Panel> newPossibleMoves = new List <Panel>();
                foreach (Panel x in possibleMoves)
                {
                    foreach (Piece y in board.getPieces())
                    {
                        if (x == y.getPanel())
                        {
                            newPossibleMoves.Add(x);
                        }
                    }
                }
                possibleMoves = newPossibleMoves;
                //captures are the only possible moves if a capture is possible
            }
            else if (!capturePossible && suicide) //if there no captures possible in suicide chess
            {
                foreach (Piece x in board.getPieces())
                {
                    if (x.capture() && x.getType().Substring(0, 1) == getType().Substring(0, 1))
                    {
                        possibleMoves = new List <Panel>();
                        break;
                        //if there are no possible captures, but there are possible captures from other pieces, this piece cannot move
                    }
                }
            }
        }
Пример #6
0
        public override void setMoves(BoardGen board, bool checkUp, bool suicide)
        {
            possibleMoves   = new List <Panel>();
            capturePossible = false;
            //Rooks can move in a straigh line, up, down, left and right.
            foreach (Panel x in board.getPanels())
            {
                if ((getPanel().Location.Y == x.Location.Y ||
                     getPanel().Location.X == x.Location.X))
                {
                    if (board.getPanelsInUse().Contains(x))
                    {
                        foreach (Piece y in board.getPieces())
                        {
                            if (y.getPanel() == x)
                            {
                                if (getType().Substring(0, 1) !=
                                    y.getType().Substring(0, 1))
                                {
                                    possibleMoves.Add(x);
                                }
                            }
                        }
                    }
                    else
                    {
                        possibleMoves.Add(x);
                    }
                }
            }

            /*This part just gets all of the panels with the same x or y value as
             * the rook in use*/

            List <Panel> panelsRemove = new List <Panel>();

            foreach (Panel x in board.getPanels())
            {
                if (getPanel().Location.X == x.Location.X &&
                    board.getPanelsInUse().Contains(x))
                {
                    if (x.Location.Y > getPanel().Location.Y)
                    {
                        foreach (Panel g in possibleMoves)
                        {
                            if (g.Location.Y > x.Location.Y)
                            {
                                panelsRemove.Add(g);
                            }
                        }
                    }
                    else if (x.Location.Y < getPanel().Location.Y)
                    {
                        foreach (Panel g in possibleMoves)
                        {
                            if (g.Location.Y < x.Location.Y)
                            {
                                panelsRemove.Add(g);
                            }
                        }
                    }
                }
                if (getPanel().Location.Y == x.Location.Y &&
                    board.getPanelsInUse().Contains(x))
                {
                    if (x.Location.X > getPanel().Location.X)
                    {
                        foreach (Panel g in possibleMoves)
                        {
                            if (g.Location.X > x.Location.X)
                            {
                                panelsRemove.Add(g);
                            }
                        }
                    }
                    else if (x.Location.X < getPanel().Location.X)
                    {
                        foreach (Panel g in possibleMoves)
                        {
                            if (g.Location.X < x.Location.X)
                            {
                                panelsRemove.Add(g);
                            }
                        }
                    }
                }
            }

            /*This part adds any moves that aren't possible due to a piece blocking
             * the move to an array that is removed from possible moves*/


            foreach (Panel x in panelsRemove)
            {
                possibleMoves.Remove(x);
            }

            foreach (Panel x in possibleMoves)
            {
                foreach (Piece p in board.getPieces())
                {
                    if (x == p.getPanel())
                    {
                        capturePossible = true;
                    }
                }
            }

            if (checkUp && !suicide) //if checking for check and this is not suicide chess (as chess doesn't exist in suicide chess)
            {
                Piece toRem   = null;
                bool  removed = false;
                tempPan = getPanel();
                foreach (Panel x in possibleMoves)
                {
                    if (board.getPanelsInUse().Contains(x))
                    {
                        foreach (Piece z in board.getPieces().ToList())
                        {
                            if (z.getPanel() == x)
                            {
                                toRem   = z;
                                removed = true;
                                board.RemovePiece(z);
                            }
                        }
                    }

                    setPanel(x);

                    board.setPanelsInUse();

                    foreach (Piece y in board.getPieces().ToList())
                    {
                        if (!y.getType().Contains(getType()))
                        {
                            y.setMoves(board, false, suicide);
                        }
                    }

                    if (checkCheck(board) && checkType() ==
                        getType().Substring(0, 1))
                    {
                        panelsRemove.Add(x);
                    }

                    setPanel(tempPan);

                    if (removed)
                    {
                        board.AddPiece(toRem);
                        removed = false;
                    }

                    board.setPanelsInUse();
                }

                foreach (Panel x in panelsRemove)
                {
                    possibleMoves.Remove(x);
                }
            }

            /* Exactly like all other pieces, this part checks all of the current
             * possible moves for the the bisop to see if any would leave the player
             * in check, if it would, it is not a valid move and is removed. */

            if (capturePossible && suicide) //if it is suicide chess and there is a capture possible
            {
                List <Panel> newPossibleMoves = new List <Panel>();
                foreach (Panel x in possibleMoves)
                {
                    foreach (Piece y in board.getPieces())
                    {
                        if (x == y.getPanel())
                        {
                            newPossibleMoves.Add(x);
                        }
                    }
                }
                possibleMoves = newPossibleMoves;
                //captures are the only possible moves if a capture is possible
            }
            else if (!capturePossible && suicide) //if there no captures possible in suicide chess
            {
                foreach (Piece x in board.getPieces())
                {
                    if (x.capture() && x.getType().Substring(0, 1) == getType().Substring(0, 1))
                    {
                        possibleMoves = new List <Panel>();
                        break;
                        //if there are no possible captures, but there are possible captures from other pieces, this piece cannot move
                    }
                }
            }
        }
Пример #7
0
        private void panel_MouseDown(object sender, MouseEventArgs e)
        {
            Panel actionPanel = (Panel)sender;
            bool  castle      = false;

            //This section is for when no piece has been clicked yet
            if (timer1.Enabled) //if the game hasn't ended
            {
                if (movingPiece == null)
                {
                    pieces = generation.getPieces();

                    //Gets the piece that was clicked
                    foreach (Piece p in pieces)
                    {
                        if (p.getPanel() == actionPanel)
                        {
                            movingPiece      = p;
                            movingPiecePanel = actionPanel;
                            break;
                        }
                    }

                    //If the panel that was clicked actually contains a piece
                    try
                    {
                        //And it's that peice's colours turn
                        if ((WhiteMove &&
                             movingPiece.getType().Substring(0, 1).Equals("W")) ||
                            (!WhiteMove &&
                             movingPiece.getType().Substring(0, 1).Equals("B")))
                        {
                            movingPiece.setMoves(generation, true, suicide);
                            //Get that piece's moves

                            foreach (Panel x in movingPiece.getMoves())
                            {
                                x.BackColor = ColorTranslator.FromHtml("#FFFC7F");
                                //And display them
                            }
                        }
                    }
                    catch (NullReferenceException)
                    {
                        //Could notify the player they clicked an empty sqaure here
                    }
                }

                //This section is for when a piece has already been clicked
                else
                {
                    movingPiece.setMoves(generation, true, suicide);
                    //Update the moves of that piece for their new position

                    //Get the colours of the board back to normal
                    for (int k = 0; k <= 7; k++)
                    {
                        for (int s = 0; s <= 7; s++)
                        {
                            if (k % 2 == 0)
                            {
                                generation.getPanels()[k, s].BackColor =
                                    s % 2 != 0 ? ColorTranslator.FromHtml("#80A83E") : ColorTranslator.FromHtml("#D9DD76");
                            }
                            else
                            {
                                generation.getPanels()[k, s].BackColor =
                                    s % 2 != 0 ? ColorTranslator.FromHtml("#D9DD76") : ColorTranslator.FromHtml("#80A83E");
                            }
                        }
                    }

                    //If that panel clicked was not the same as the first panel the person clicked
                    if (actionPanel != movingPiecePanel && movingPiece.getType().Substring(0, 1) == (WhiteMove ? "W" : "B"))
                    {
                        //And the panel is valid
                        try
                        {
                            if (movingPiece.getMoves().Contains(actionPanel))
                            {
                                if (generation.getPanelsInUse().Contains(actionPanel))
                                {
                                    foreach (Piece z in generation.getPieces().ToList())
                                    {
                                        if (z.getPanel() == actionPanel)
                                        {
                                            generation.RemovePiece(z);
                                            if (z.getType().Substring(0, 1) == "W")
                                            {
                                                pictureBoxesB[bPiecesTaken].BackgroundImage = z.getPanel().BackgroundImage;
                                                bPiecesTaken++;
                                            }
                                            else
                                            {
                                                pictureBoxesW[wPiecesTaken].BackgroundImage = z.getPanel().BackgroundImage;
                                                wPiecesTaken++;
                                            }
                                        }
                                    }
                                    actionPanel.BackgroundImage = null;

                                    /*If the panel was a possible move and contains a
                                     * piece, the piece that it already contains needs
                                     * to be disposed of and stored in the interface where
                                     * taken pieces are displayed*/
                                }
                                if (movingPiece.getType().Contains("King"))
                                {
                                    if ((actionPanel == generation.getPanels()[6, movingPiece.getType().Substring(0, 1) == "W" ? 7 : 0] || actionPanel == generation.getPanels()[2, movingPiece.getType().Substring(0, 1) == "W" ? 7 : 0]) && !movingPiece.getMoved())
                                    {
                                        castle = true;
                                    }
                                }
                                //Recognises when the king is trying to castle


                                if ((WhiteMove &&
                                     movingPiece.getType().Substring(0, 1).Equals("W")) ||
                                    (!WhiteMove &&
                                     movingPiece.getType().Substring(0, 1).Equals("B")))
                                {
                                    actionPanel.BackgroundImage =
                                        movingPiece.getPanel().BackgroundImage;

                                    undoPiece.Add(movingPiece);
                                    undoPanel.Add(movingPiece.getPanel());
                                    noUndos++;

                                    movingPiece.setPanel(actionPanel);

                                    if (updateReq && movingPiece.getPanel() != updatePiece.getPanel())
                                    {
                                        updatePiece.setPanel(toUpdate);
                                        generation.RemovePiece(piecePosRemove);
                                        updateReq = false;
                                        //if a pawn has moved foward two last move, it can no longer be taken as if it were on the first sqaure, so don't allow that to happen.
                                    }
                                    else if (updateReq)
                                    {
                                        if (movingPiece.getType().Substring(0, 1) == "W")
                                        {
                                            pictureBoxesW[wPiecesTaken - 1].BackgroundImage = Resources.BPawn;
                                        }
                                        else
                                        {
                                            pictureBoxesB[bPiecesTaken - 1].BackgroundImage = Resources.WPawn;
                                        }
                                        updatePiece.getPanel().BackgroundImage    = movingPiece.getPanel().BackgroundImage;
                                        piecePosRemove.getPanel().BackgroundImage = null;
                                        generation.RemovePiece(piecePosRemove);
                                        updatePiece.setPanel(null);

                                        updateReq = false;

                                        //If a pawn has moved foward two last move, and a pawn has taken it as if it were on the first square, this allows it to be taken.
                                    }
                                    if (movingPiece.getType().Contains("Pawn"))
                                    {
                                        if (!movingPiece.getMoved() && movingPiece.getPanel().Location.Y == movingPiecePanel.Location.Y + ((movingPiece.getType().Contains("W")) ? -80 : 80))
                                        {
                                            foreach (Panel x in generation.getPanels())
                                            {
                                                if (x.Location.Y + (movingPiece.getType().Contains("W") ? -40 : 40) == actionPanel.Location.Y && x.Location.X == actionPanel.Location.X)
                                                {
                                                    toUpdate    = actionPanel;
                                                    updatePiece = movingPiece;
                                                    movingPiece.setPanel(x);
                                                    updateReq      = true;
                                                    piecePosRemove = new Pawn(updatePiece.getType(), actionPanel, true);
                                                    generation.AddPiece(piecePosRemove);
                                                    break;
                                                }
                                            }
                                        }
                                    }

                                    generation.setPanelsInUse();
                                    movingPiecePanel.BackgroundImage = null;
                                    movingPiece.setMoved(true);
                                    movingPiece.increaseNoMoves();

                                    //As long as the right person (whose turn it is) is
                                    //moving then this bit above moves it

                                    if (castle) //if the king is attempting to castle
                                    {
                                        int action = -1;
                                        if (actionPanel == generation.getPanels()[6, movingPiece.getType().Substring(0, 1) == "W" ? 7 : 0])
                                        {
                                            foreach (Piece x in generation.getPieces())
                                            {
                                                if (x.getPanel() == generation.getPanels()[7, movingPiece.getType().Substring(0, 1) == "W" ? 7 : 0])
                                                {
                                                    movingPiece = x;
                                                    action      = 5;
                                                }
                                            }
                                        }
                                        if (actionPanel == generation.getPanels()[2, movingPiece.getType().Substring(0, 1) == "W" ? 7 : 0])
                                        {
                                            foreach (Piece x in generation.getPieces())
                                            {
                                                if (x.getPanel() == generation.getPanels()[0, movingPiece.getType().Substring(0, 1) == "W" ? 7 : 0])
                                                {
                                                    movingPiece = x;
                                                    action      = 3;
                                                }
                                            }
                                        }
                                        actionPanel                 = generation.getPanels()[action, movingPiece.getType().Substring(0, 1) == "W" ? 7 : 0];
                                        movingPiecePanel            = movingPiece.getPanel();
                                        actionPanel.BackgroundImage =
                                            movingPiece.getPanel().BackgroundImage;

                                        undoPiece.Add(movingPiece);
                                        undoPanel.Add(movingPiece.getPanel());
                                        noUndos++;


                                        movingPiece.setPanel(actionPanel);

                                        generation.setPanelsInUse();
                                        movingPiecePanel.BackgroundImage = null;
                                        movingPiece.setMoved(true);
                                        movingPiece.increaseNoMoves();

                                        //moves the castle to thing other side of the king
                                    }



                                    if (movingPiece.getType() == "WPawn" ^
                                        movingPiece.getType() == "BPawn")
                                    {
                                        if ((movingPiece.getPanel().Location.Y == 0 &&
                                             movingPiece.getType() == "WPawn") ^
                                            (movingPiece.getPanel().Location.Y == 280 &&
                                             movingPiece.getType() == "BPawn"))
                                        {
                                            generation.RemovePiece(movingPiece);
                                            newQueen = new Queen
                                                           (movingPiece.getType().Substring(0, 1) +
                                                           "Queen", movingPiece.getPanel(), true);
                                            generation.AddPiece(newQueen);
                                        }
                                    }
                                    //If a pawn reaches the end, it becoms a queen

                                    int totalPossibleMoves = 0;
                                    foreach (Piece y in generation.getPieces().ToList())
                                    {
                                        y.setMoves(generation, true, suicide);
                                        if ((WhiteMove &&
                                             y.getType().Substring(0, 1) == "B") ^
                                            (!WhiteMove &&
                                             y.getType().Substring(0, 1) == "W"))
                                        {
                                            totalPossibleMoves += y.getMoves().Count;
                                        }
                                    }
                                    //Make sure there are some possible moves

                                    if (!(gameModes == "M3S") && movingPiece.checkCheck(generation))
                                    {
                                        MessageBox.Show("Check!");
                                        //Check check, if it is check, tell the players
                                        if (totalPossibleMoves == 0)
                                        {
                                            //There are no possible moves, it's checkemate
                                            timer1.Stop();
                                            MessageBox.Show("Check mate! " + (movingPiece.checkType() == "B" ? "White" : "Black") + " wins!");
                                            //EndGame()
                                        }
                                    }

                                    double val = moveCalc.getBoardValue(generation);
                                    WhiteMove   = !WhiteMove;
                                    movingPiece = null;
                                    //Next players move and a piece has not been clicked
                                    if (gameModes == "S1S")
                                    {
                                        generation.setPanelsInUse();
                                        actionPanel      = moveCalc.bestMove(generation, -10000, 10000);
                                        movingPiece      = moveCalc.getMovingPiece();
                                        movingPiecePanel = moveCalc.getMovingPiecePanel();

                                        if (generation.getPanelsInUse().Contains(actionPanel))
                                        {
                                            foreach (Piece z in generation.getPieces().ToList())
                                            {
                                                if (z.getPanel() == actionPanel)
                                                {
                                                    generation.RemovePiece(z);
                                                    if (z.getType().Substring(0, 1) == "W")
                                                    {
                                                        pictureBoxesB[bPiecesTaken].BackgroundImage = z.getPanel().BackgroundImage;
                                                        bPiecesTaken++;
                                                    }
                                                    else
                                                    {
                                                        pictureBoxesW[wPiecesTaken].BackgroundImage = z.getPanel().BackgroundImage;
                                                        wPiecesTaken++;
                                                    }
                                                }
                                            }
                                            actionPanel.BackgroundImage = null;

                                            /*If the panel was a possible move and contains a
                                             * piece, the piece that it already contains needs
                                             * to be disposed of and stored in the interface where
                                             * taken pieces are displayed*/
                                        }
                                        if (movingPiece.getType().Contains("King"))
                                        {
                                            if ((actionPanel == generation.getPanels()[6, movingPiece.getType().Substring(0, 1) == "W" ? 7 : 0] || actionPanel == generation.getPanels()[2, movingPiece.getType().Substring(0, 1) == "W" ? 7 : 0]) && !movingPiece.getMoved())
                                            {
                                                castle = true;
                                            }
                                        }
                                        //Recognises when the king is trying to castle


                                        if ((WhiteMove &&
                                             movingPiece.getType().Substring(0, 1).Equals("W")) ||
                                            (!WhiteMove &&
                                             movingPiece.getType().Substring(0, 1).Equals("B")))
                                        {
                                            actionPanel.BackgroundImage =
                                                movingPiece.getPanel().BackgroundImage;

                                            undoPiece.Add(movingPiece);
                                            undoPanel.Add(movingPiece.getPanel());
                                            noUndos++;

                                            movingPiece.setPanel(actionPanel);

                                            if (updateReq && movingPiece.getPanel() != updatePiece.getPanel())
                                            {
                                                updatePiece.setPanel(toUpdate);
                                                generation.RemovePiece(piecePosRemove);
                                                updateReq = false;
                                                //if a pawn has moved foward two last move, it can no longer be taken as if it were on the first sqaure, so don't allow that to happen.
                                            }
                                            else if (updateReq)
                                            {
                                                if (movingPiece.getType().Substring(0, 1) == "W")
                                                {
                                                    pictureBoxesW[wPiecesTaken - 1].BackgroundImage = Resources.BPawn;
                                                }
                                                else
                                                {
                                                    pictureBoxesB[bPiecesTaken - 1].BackgroundImage = Resources.WPawn;
                                                }
                                                updatePiece.getPanel().BackgroundImage    = movingPiece.getPanel().BackgroundImage;
                                                piecePosRemove.getPanel().BackgroundImage = null;
                                                generation.RemovePiece(piecePosRemove);
                                                updatePiece.setPanel(null);

                                                updateReq = false;

                                                //If a pawn has moved foward two last move, and a pawn has taken it as if it were on the first square, this allows it to be taken.
                                            }
                                            if (movingPiece.getType().Contains("Pawn"))
                                            {
                                                if (!movingPiece.getMoved() && movingPiece.getPanel().Location.Y == movingPiecePanel.Location.Y + ((movingPiece.getType().Contains("W")) ? -80 : 80))
                                                {
                                                    foreach (Panel x in generation.getPanels())
                                                    {
                                                        if (x.Location.Y + (movingPiece.getType().Contains("W") ? -40 : 40) == actionPanel.Location.Y && x.Location.X == actionPanel.Location.X)
                                                        {
                                                            toUpdate    = actionPanel;
                                                            updatePiece = movingPiece;
                                                            movingPiece.setPanel(x);
                                                            updateReq      = true;
                                                            piecePosRemove = new Pawn(updatePiece.getType(), actionPanel, true);
                                                            generation.AddPiece(piecePosRemove);
                                                            break;
                                                        }
                                                    }
                                                }
                                            }

                                            generation.setPanelsInUse();
                                            movingPiecePanel.BackgroundImage = null;
                                            movingPiece.setMoved(true);
                                            movingPiece.increaseNoMoves();

                                            //As long as the right person (whose turn it is) is
                                            //moving then this bit above moves it

                                            if (castle) //if the king is attempting to castle
                                            {
                                                int action = -1;
                                                if (actionPanel == generation.getPanels()[6, movingPiece.getType().Substring(0, 1) == "W" ? 7 : 0])
                                                {
                                                    foreach (Piece x in generation.getPieces())
                                                    {
                                                        if (x.getPanel() == generation.getPanels()[7, movingPiece.getType().Substring(0, 1) == "W" ? 7 : 0])
                                                        {
                                                            movingPiece = x;
                                                            action      = 5;
                                                        }
                                                    }
                                                }
                                                if (actionPanel == generation.getPanels()[2, movingPiece.getType().Substring(0, 1) == "W" ? 7 : 0])
                                                {
                                                    foreach (Piece x in generation.getPieces())
                                                    {
                                                        if (x.getPanel() == generation.getPanels()[0, movingPiece.getType().Substring(0, 1) == "W" ? 7 : 0])
                                                        {
                                                            movingPiece = x;
                                                            action      = 3;
                                                        }
                                                    }
                                                }
                                                actionPanel                 = generation.getPanels()[action, movingPiece.getType().Substring(0, 1) == "W" ? 7 : 0];
                                                movingPiecePanel            = movingPiece.getPanel();
                                                actionPanel.BackgroundImage =
                                                    movingPiece.getPanel().BackgroundImage;

                                                undoPiece.Add(movingPiece);
                                                undoPanel.Add(movingPiece.getPanel());
                                                noUndos++;


                                                movingPiece.setPanel(actionPanel);

                                                generation.setPanelsInUse();
                                                movingPiecePanel.BackgroundImage = null;
                                                movingPiece.setMoved(true);
                                                movingPiece.increaseNoMoves();

                                                //moves the castle to thing other side of the king
                                            }



                                            if (movingPiece.getType() == "WPawn" ^
                                                movingPiece.getType() == "BPawn")
                                            {
                                                if ((movingPiece.getPanel().Location.Y == 0 &&
                                                     movingPiece.getType() == "WPawn") ^
                                                    (movingPiece.getPanel().Location.Y == 280 &&
                                                     movingPiece.getType() == "BPawn"))
                                                {
                                                    generation.RemovePiece(movingPiece);
                                                    newQueen = new Queen
                                                                   (movingPiece.getType().Substring(0, 1) +
                                                                   "Queen", movingPiece.getPanel(), true);
                                                    generation.AddPiece(newQueen);
                                                }
                                            }
                                            //If a pawn reaches the end, it becoms a queen

                                            totalPossibleMoves = 0;
                                            foreach (Piece y in generation.getPieces().ToList())
                                            {
                                                y.setMoves(generation, true, suicide);
                                                if ((WhiteMove &&
                                                     y.getType().Substring(0, 1) == "B") ^
                                                    (!WhiteMove &&
                                                     y.getType().Substring(0, 1) == "W"))
                                                {
                                                    totalPossibleMoves += y.getMoves().Count;
                                                }
                                            }
                                            //Make sure there are some possible moves

                                            if (!(gameModes == "M3S") && movingPiece.checkCheck(generation))
                                            {
                                                MessageBox.Show("Check!");
                                                //Check check, if it is check, tell the players
                                                if (totalPossibleMoves == 0)
                                                {
                                                    //There are no possible moves, it's checkemate
                                                    timer1.Stop();
                                                    MessageBox.Show("Check mate! " + (movingPiece.checkType() == "B" ? "White" : "Black") + " wins!");
                                                    //EndGame()
                                                }
                                            }

                                            WhiteMove   = !WhiteMove;
                                            movingPiece = null;
                                        }
                                        else
                                        {
                                            movingPiece = null;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                movingPiece = null;
                            }
                        }
                        catch (NullReferenceException)
                        {
                            movingPiece = null;
                        }
                        undos.Add(noUndos);
                        noUndos = 0;
                    }
                }
            }
        }
Пример #8
0
        public override void setMoves(BoardGen board, bool checkUp, bool suicide)
        {
            possibleMoves = new List <Panel>();
            Panel tempPan = null;

            capturePossible = false;

            /*Queens move like a combination of a rook and bishop. Along a diagnol or
             * in a straight line*/

            foreach (Panel x in board.getPanels())
            {
                if ((getPanel().Location.Y == x.Location.Y ||
                     getPanel().Location.X == x.Location.X))
                {
                    if (board.getPanelsInUse().Contains(x))
                    {
                        foreach (Piece y in board.getPieces())
                        {
                            if (y.getPanel() == x)
                            {
                                if (getType().Substring(0, 1) !=
                                    y.getType().Substring(0, 1))
                                {
                                    possibleMoves.Add(x);
                                }
                            }
                        }
                    }
                    else
                    {
                        possibleMoves.Add(x);
                    }
                }
            }

            //Gets all the moves a queen could make if the board were empty

            List <Panel> panelsRemove = new List <Panel>();

            foreach (Panel x in board.getPanels())
            {
                if (getPanel().Location.X == x.Location.X &&
                    board.getPanelsInUse().Contains(x))
                {
                    if (x.Location.Y > getPanel().Location.Y)
                    {
                        foreach (Panel g in possibleMoves)
                        {
                            if (g.Location.Y > x.Location.Y)
                            {
                                panelsRemove.Add(g);
                            }
                        }
                    }
                    else if (x.Location.Y < getPanel().Location.Y)
                    {
                        foreach (Panel g in possibleMoves)
                        {
                            if (g.Location.Y < x.Location.Y)
                            {
                                panelsRemove.Add(g);
                            }
                        }
                    }
                }
                if (getPanel().Location.Y == x.Location.Y &&
                    board.getPanelsInUse().Contains(x))
                {
                    if (x.Location.X > getPanel().Location.X)
                    {
                        foreach (Panel g in possibleMoves)
                        {
                            if (g.Location.X > x.Location.X)
                            {
                                panelsRemove.Add(g);
                            }
                        }
                    }
                    else if (x.Location.X < getPanel().Location.X)
                    {
                        foreach (Panel g in possibleMoves)
                        {
                            if (g.Location.X < x.Location.X)
                            {
                                panelsRemove.Add(g);
                            }
                        }
                    }
                }
            }
            Piece piece = null;

            foreach (Panel x in board.getPanels())
            {
                for (int i = 0; i < 8; i++)
                {
                    foreach (Piece c in board.getPieces())
                    {
                        if (c.getPanel() == x)
                        {
                            piece = c;
                        }
                    }

                    if ((getPanel().Location.X == x.Location.X + (40 * i) ||
                         getPanel().Location.X == x.Location.X - (40 * i)) &&
                        (getPanel().Location.Y == x.Location.Y + (40 * i) ||
                         getPanel().Location.Y == x.Location.Y - (40 * i)))
                    {
                        if (board.getPanelsInUse().Contains(x))
                        {
                            foreach (Piece y in board.getPieces())
                            {
                                if (y.getPanel() == x)
                                {
                                    if (getType().Substring(0, 1) !=
                                        y.getType().Substring(0, 1))
                                    {
                                        possibleMoves.Add(x);
                                    }
                                }
                            }
                        }
                        else
                        {
                            possibleMoves.Add(x);
                        }
                    }
                }
            }

            foreach (Panel x in board.getPanels())
            {
                for (int i = 0; i < 8; i++)
                {
                    if ((getPanel().Location.X == x.Location.X + (40 * i) ||
                         getPanel().Location.X == x.Location.X - (40 * i)) &&
                        (getPanel().Location.Y == x.Location.Y + (40 * i) ||
                         getPanel().Location.Y == x.Location.Y - (40 * i)) &&
                        board.getPanelsInUse().Contains(x))
                    {
                        if (x.Location.Y < getPanel().Location.Y&&
                            x.Location.X < getPanel().Location.X)
                        {
                            foreach (Panel g in possibleMoves)
                            {
                                if (g.Location.Y < x.Location.Y &&
                                    g.Location.X < x.Location.X)
                                {
                                    panelsRemove.Add(g);
                                }
                            }
                        }
                        else if (x.Location.Y < getPanel().Location.Y&&
                                 x.Location.X > getPanel().Location.X)
                        {
                            foreach (Panel g in possibleMoves)
                            {
                                if (g.Location.Y < x.Location.Y &&
                                    g.Location.X > x.Location.X)
                                {
                                    panelsRemove.Add(g);
                                }
                            }
                        }
                        else if (x.Location.Y > getPanel().Location.Y&&
                                 x.Location.X < getPanel().Location.X)
                        {
                            foreach (Panel g in possibleMoves)
                            {
                                if (g.Location.Y > x.Location.Y &&
                                    g.Location.X < x.Location.X)
                                {
                                    panelsRemove.Add(g);
                                }
                            }
                        }
                        else if (x.Location.Y > getPanel().Location.Y&&
                                 x.Location.X > getPanel().Location.X)
                        {
                            foreach (Panel g in possibleMoves)
                            {
                                if (g.Location.Y > x.Location.Y &&
                                    g.Location.X > x.Location.X)
                                {
                                    panelsRemove.Add(g);
                                }
                            }
                        }
                    }
                }
            }

            foreach (Panel x in panelsRemove)
            {
                possibleMoves.Remove(x);
            }

            foreach (Panel x in possibleMoves)
            {
                foreach (Piece p in board.getPieces())
                {
                    if (x == p.getPanel())
                    {
                        capturePossible = true;
                    }
                }
            }


            //Removes any moves blocked by another piece.

            if (checkUp && !suicide) //if checking for check and this is not suicide chess (as chess doesn't exist in suicide chess)
            {
                Piece toRem   = null;
                bool  removed = false;
                tempPan = getPanel();
                foreach (Panel x in possibleMoves)
                {
                    if (board.getPanelsInUse().Contains(x))
                    {
                        foreach (Piece z in board.getPieces().ToList())
                        {
                            if (z.getPanel() == x)
                            {
                                toRem   = z;
                                removed = true;
                                board.RemovePiece(z);
                            }
                        }
                    }

                    setPanel(x);

                    board.setPanelsInUse();

                    foreach (Piece y in board.getPieces().ToList())
                    {
                        if (!y.getType().Contains(getType()))
                        {
                            y.setMoves(board, false, suicide);
                        }
                    }

                    if (checkCheck(board) && checkType() == getType().Substring(0, 1))
                    {
                        panelsRemove.Add(x);
                    }

                    setPanel(tempPan);

                    if (removed)
                    {
                        board.AddPiece(toRem);
                        removed = false;
                    }

                    board.setPanelsInUse();
                }

                foreach (Panel x in panelsRemove)
                {
                    possibleMoves.Remove(x);
                }
            }

            /* This part checks all of the current possible moves for the
             * the bisop to see if any would leave the player in check, if it
             * would, it is not a valid move and is removed. */

            if (capturePossible && suicide) //if it is suicide chess and there is a capture possible
            {
                List <Panel> newPossibleMoves = new List <Panel>();
                foreach (Panel x in possibleMoves)
                {
                    foreach (Piece y in board.getPieces())
                    {
                        if (x == y.getPanel())
                        {
                            newPossibleMoves.Add(x);
                        }
                    }
                }
                possibleMoves = newPossibleMoves;
                //captures are the only possible moves if a capture is possible
            }
            else if (!capturePossible && suicide) //if there no captures possible in suicide chess
            {
                foreach (Piece x in board.getPieces())
                {
                    if (x.capture() && x.getType().Substring(0, 1) == getType().Substring(0, 1))
                    {
                        possibleMoves = new List <Panel>();
                        break;
                        //if there are no possible captures, but there are possible captures from other pieces, this piece cannot move
                    }
                }
            }
        }