Exemplo n.º 1
0
        } //end of main

        //turns


        static bool Move_WPawn(square start_sq, square end_sq, int start_ind, int end_ind)//works except at taking edges
        {
            bool success = true;

            if ((start_ind - 8 == end_ind) && end_sq.IsEmpty())
            {
            }

            else if (((start_ind - 9 == end_ind) || (start_ind - 7 == end_ind)) && end_sq.IsBlack())
            {
            }                                                                                            //taking pieces

            else
            {
                return(false);
            }

            start_sq.State = "__";
            end_sq.State   = "WP";
            return(success);
        }
Exemplo n.º 2
0
        static bool Move_WQueen(square start_sq, square end_sq, int start_ind, int end_ind, board classic)
        {
            bool        success  = true;
            List <Char> Let_list = new List <Char> {
                'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'
            };

            int let_diff = Let_list.IndexOf(end_sq.Position[0]) - Let_list.IndexOf(start_sq.Position[0]); //calc difference in number(row)

            int num_diff = Convert.ToInt32(end_sq.Position[1]) - Convert.ToInt32(start_sq.Position[1]);   //calc difference in letter(col)

            if (end_sq.IsEmpty() || end_sq.IsBlack())
            {
                if (let_diff == num_diff) //if difference between letter(col) and row(num) are equal, end is diag from start (pos slope)
                {                         //used for up right and down left movement, (pos=pos, neg=neg)
                    if (num_diff > 0)     //up right
                    {
                        for (int i = start_ind - 7; i != end_ind; i -= 7)
                        {
                            if (classic.total_board[i].IsEmpty() == false)
                            {
                                return(false);
                            }
                        }
                    }


                    if (num_diff < 0)//down left
                    {
                        for (int i = start_ind + 7; i != end_ind; i += 7)
                        {
                            if (classic.total_board[i].IsEmpty() == false)
                            {
                                return(false);
                            }
                        }
                    }
                }

                else if (let_diff == -1 * num_diff) //if diff between letter(col) and row(num) are opposites, end is diag from start (neg slope)
                {
                    if (num_diff < 0)               //down right
                    {
                        for (int i = start_ind + 9; i != end_ind; i += 9)
                        {
                            if (classic.total_board[i].IsEmpty() == false)
                            {
                                return(false);
                            }
                        }
                    }


                    if (num_diff > 0)//up left
                    {
                        for (int i = start_ind - 9; i != end_ind; i -= 9)
                        {
                            if (classic.total_board[i].IsEmpty() == false)
                            {
                                return(false);
                            }
                        }
                    }
                }

                else if ((start_sq.Position[0] == end_sq.Position[0]) && (end_ind - start_ind < 0))//if moving up
                {
                    for (int i = start_ind - 8; i != end_ind; i -= 8)
                    {
                        if (classic.total_board[i].IsEmpty() == false)
                        {
                            return(false);
                        }
                    }
                }

                else if ((start_sq.Position[0] == end_sq.Position[0]) && (end_ind - start_ind > 0))//if moving down
                {
                    for (int i = start_ind + 8; i != end_ind; i += 8)
                    {
                        if (classic.total_board[i].IsEmpty() == false)
                        {
                            return(false);
                        }                                                               //if not empty
                    }
                }

                else if ((start_sq.Position[1] == end_sq.Position[1]) && (start_ind > end_ind)) // if moving left
                {
                    for (int i = start_ind - 1; i != end_ind; i -= 1)
                    {
                        if (classic.total_board[i].IsEmpty() == false)
                        {
                            return(false);
                        }
                    }
                }


                else if ((start_sq.Position[1] == end_sq.Position[1]) && (end_ind > start_ind)) // if moving right
                {
                    for (int i = start_ind + 1; i != end_ind; i += 1)
                    {
                        if (classic.total_board[i].IsEmpty() == false)
                        {
                            return(false);
                        }
                    }
                }

                else
                {
                    return(false);
                }
            }

            else
            {
                return(false);
            }

            end_sq.State   = "WQ";
            start_sq.State = "__";

            return(success);
        }
Exemplo n.º 3
0
        static bool Move_WKing(square start_sq, square end_sq, int start_ind, int end_ind)
        {
            bool success = true;

            if (((Math.Abs(end_ind - start_ind) == 1) || (Math.Abs(end_ind - start_ind) == 7) || (Math.Abs(end_ind - start_ind) == 8) || (Math.Abs(end_ind - start_ind) == 9)) && (end_sq.IsEmpty() || end_sq.IsBlack()))
            {
            }

            else
            {
                return(false);
            }

            start_sq.State = "__";
            end_sq.State   = "WK";
            return(success);
        }
Exemplo n.º 4
0
        static bool Move_WRook(square start_sq, square end_sq, int start_ind, int end_ind, board classic)//move White Rook
        {
            bool success = true;

            if (end_sq.IsBlack() || end_sq.IsEmpty())
            {
                if ((start_sq.Position[0] == end_sq.Position[0]) && (end_ind - start_ind < 0))//if moving up
                {
                    for (int i = start_ind - 8; i != end_ind; i -= 8)
                    {
                        if (classic.total_board[i].IsEmpty() == false)
                        {
                            return(false);
                        }
                    }
                }

                if ((start_sq.Position[0] == end_sq.Position[0]) && (end_ind - start_ind > 0))//if moving down
                {
                    for (int i = start_ind + 8; i != end_ind; i += 8)
                    {
                        if (classic.total_board[i].IsEmpty() == false)
                        {
                            return(false);
                        }                                                               //if not empty
                    }
                }

                if ((start_sq.Position[1] == end_sq.Position[1]) && (start_ind > end_ind)) // if moving left
                {
                    for (int i = start_ind - 1; i != end_ind; i -= 1)
                    {
                        if (classic.total_board[i].IsEmpty() == false)
                        {
                            return(false);
                        }
                    }
                }


                if ((start_sq.Position[1] == end_sq.Position[1]) && (end_ind > start_ind)) // if moving right
                {
                    for (int i = start_ind + 1; i != end_ind; i += 1)
                    {
                        if (classic.total_board[i].IsEmpty() == false)
                        {
                            return(false);
                        }
                    }
                }
            }

            else
            {
                return(false);
            }

            end_sq.State   = "WR";
            start_sq.State = "__";

            return(success);
        }
Exemplo n.º 5
0
        static bool Move_WKnight(square start_sq, square end_sq, int start_ind, int end_ind)
        {
            bool success = true;

            if (((Math.Abs(start_ind - end_ind) == 6) || (Math.Abs(start_ind - end_ind) == 10) || (Math.Abs(start_ind - end_ind) == 15) || (Math.Abs(start_ind - end_ind) == 17)) && (end_sq.IsEmpty() || end_sq.IsBlack()))
            {
            }

            else
            {
                return(false);
            }

            start_sq.State = "__";
            end_sq.State   = "WN";
            return(success);
        }