Exemple #1
0
        public bool IsValidMove(Chessboard board, Tuple <int, int> position)
        {
            int YDIff = Math.Abs(this.Position.Item1 - position.Item1);
            int XDiff = Math.Abs(this.Position.Item2 - position.Item2);

            if (XDiff > 1 || YDIff > 1)
            {
                return(false);
            }
            if (board.GetPiece(position) != null && board.GetPiece(position).Color == this.Color)
            {
                return(false);
            }
            return(true);
        }
Exemple #2
0
        public bool IsValidMove(Chessboard board, Tuple <int, int> position)
        {
            int limit;
            int YDiff = position.Item1 - this.Position.Item1;
            int XDiff = position.Item2 - this.Position.Item2;

            switch (this.Color)
            {
            case Color.LIGHT:
                limit = 1;
                if (this.Position.Item1 == 1)
                {
                    limit = 2;
                }
                if (XDiff == 0 && (Math.Abs(YDiff) > 0 && Math.Abs(YDiff) <= limit) && board.GetPiece(position) == null)
                {
                    return(true);
                }

                if (this.Position.Item1 - position.Item1 == -1 && board.GetPiece(position) != null &&
                    board.GetPiece(position).Color != this.Color && (XDiff == 1 || XDiff == -1))
                {
                    return(true);
                }
                break;

            case Color.DARK:
                limit = -1;
                if (this.Position.Item1 == 6)
                {
                    limit = -2;
                }
                if (XDiff == 0 && (YDiff < 0 && YDiff >= limit) && board.GetPiece(position) == null)
                {
                    return(true);
                }

                if (this.Position.Item1 - position.Item1 == 1 && board.GetPiece(position) != null &&
                    board.GetPiece(position).Color != this.Color && (XDiff == 1 || XDiff == -1))
                {
                    return(true);
                }
                break;
            }


            return(false);
        }
Exemple #3
0
        public bool IsValidMove(Chessboard board, Tuple <int, int> position)
        {
            int YDiff = this.Position.Item1 - position.Item1;
            int XDiff = this.Position.Item2 - position.Item2;

            if (XDiff == 0 || YDiff == 0)
            {
                if (XDiff > 0)
                {
                    for (int i = 1; i < XDiff; i++)
                    {
                        if (board.GetPiece(new Tuple <int, int>(this.Position.Item1, this.Position.Item2 - XDiff + i)) != null)
                        {
                            return(false);
                        }
                    }
                }
                else if (XDiff < 0)
                {
                    for (int i = -1; i > XDiff; i--)
                    {
                        if (board.GetPiece(new Tuple <int, int>(this.Position.Item1, this.Position.Item2 - XDiff + i)) != null)
                        {
                            return(false);
                        }
                    }
                }
                else if (YDiff > 0)
                {
                    for (int i = 1; i < YDiff; i++)
                    {
                        if (board.GetPiece(new Tuple <int, int>(this.Position.Item1 - YDiff + i, this.Position.Item2)) != null)
                        {
                            return(false);
                        }
                    }
                }
                else if (YDiff < 0)
                {
                    for (int i = -1; i > YDiff; i--)
                    {
                        if (board.GetPiece(new Tuple <int, int>(this.Position.Item1 - YDiff + i, this.Position.Item2)) != null)
                        {
                            return(false);
                        }
                    }
                }

                if (board.GetPiece(position) != null && board.GetPiece(position).Color == this.Color)
                {
                    return(false);
                }
                return(true);
            }

            if (XDiff != 0 && YDiff != 0 && Math.Abs((float)XDiff / (float)YDiff) == 1)
            {
                if (board.GetPiece(position) != null && board.GetPiece(position).Color == this.Color)
                {
                    return(false);
                }

                if (XDiff > 0)
                {
                    if (YDiff > 0)
                    {
                        for (int i = 1; i < Math.Abs(XDiff); i++)
                        {
                            if (board.GetPiece(new Tuple <int, int>(this.Position.Item1 - i, this.Position.Item2 - i)) != null)
                            {
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        for (int i = 1; i < Math.Abs(XDiff); i++)
                        {
                            if (board.GetPiece(new Tuple <int, int>(this.Position.Item1 + i, this.Position.Item2 - i)) != null)
                            {
                                return(false);
                            }
                        }
                    }
                }
                else
                {
                    if (YDiff > 0)
                    {
                        for (int i = 1; i < Math.Abs(XDiff); i++)
                        {
                            if (board.GetPiece(new Tuple <int, int>(this.Position.Item1 - i, this.Position.Item2 + i)) != null)
                            {
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        for (int i = 1; i < Math.Abs(XDiff); i++)
                        {
                            if (board.GetPiece(new Tuple <int, int>(this.Position.Item1 + i, this.Position.Item2 + i)) != null)
                            {
                                return(false);
                            }
                        }
                    }
                }
                return(true);
            }
            return(false);
        }
Exemple #4
0
        public bool IsValidMove(Chessboard board, Tuple <int, int> position)
        {
            int YDiff = this.Position.Item1 - position.Item1;
            int XDiff = this.Position.Item2 - position.Item2;

            if (XDiff == 0 || YDiff == 0)
            {
                if (XDiff > 0)
                {
                    for (int i = 1; i < XDiff; i++)
                    {
                        if (board.GetPiece(new Tuple <int, int>(this.Position.Item1, this.Position.Item2 - XDiff + i)) != null)
                        {
                            return(false);
                        }
                    }
                }

                if (XDiff < 0)
                {
                    for (int i = -1; i > XDiff; i--)
                    {
                        if (board.GetPiece(new Tuple <int, int>(this.Position.Item1, this.Position.Item2 - XDiff + i)) != null)
                        {
                            return(false);
                        }
                    }
                }

                if (YDiff > 0)
                {
                    for (int i = 1; i < YDiff; i++)
                    {
                        if (board.GetPiece(new Tuple <int, int>(this.Position.Item1 - YDiff + i, this.Position.Item2)) != null)
                        {
                            return(false);
                        }
                    }
                }

                if (YDiff < 0)
                {
                    for (int i = -1; i > YDiff; i--)
                    {
                        if (board.GetPiece(new Tuple <int, int>(this.Position.Item1 - YDiff + i, this.Position.Item2)) != null)
                        {
                            return(false);
                        }
                    }
                }



                if (board.GetPiece(position) != null)
                {
                    if (board.GetPiece(position).Color == this.Color)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }