Пример #1
0
    /// <summary>
    /// заполняем доску
    /// </summary>
    void filing_table()
    {
        for (int i = 0; i < 8; i++) // заполнение всей доски пустыми значениями
        {
            for (int j = 0; j < 8; j++)
            {
                empty emp = new empty();
                emp.figure_name = emp.name;
                board[i, j]     = emp;
            }
        }

        for (int i = 0; i < 8; i++) // заполнение первой строки белыми пешками
        {
            pawn pn = new pawn();
            pn.colors_of_figure = 0;
            pn.figure_name      = pn.name;
            pn.direction        = false;
            board[1, i]         = pn;
        }


        rook rk = new rook();

        rk.colors_of_figure = 0;    // белые ладьи
        rk.figure_name      = rk.name;
        board[0, 0]         = rk;
        board[0, 7]         = rk;


        rook rk_black = new rook();

        rk_black.colors_of_figure = 1;    // чёрные ладьи
        rk_black.figure_name      = rk_black.name;
        board[7, 0] = rk_black;
        board[7, 7] = rk_black;



        knight kn = new knight();

        kn.colors_of_figure = 0;    // белые кони
        kn.figure_name      = kn.name;
        board[0, 1]         = kn;
        board[0, 6]         = kn;

        knight kn_black = new knight();

        kn_black.colors_of_figure = 1;    // черные кони
        kn_black.figure_name      = kn_black.name;
        board[7, 1] = kn_black;
        board[7, 6] = kn_black;



        bishop bs = new bishop();

        bs.colors_of_figure = 0;    // белые слоны
        bs.figure_name      = bs.name;
        board[0, 2]         = bs;
        board[0, 5]         = bs;

        bishop bs_black = new bishop();

        bs_black.colors_of_figure = 1;    // черные слоны
        bs_black.figure_name      = bs_black.name;
        board[7, 2] = bs_black;
        board[7, 5] = bs_black;

        queen q = new queen();   // белая королева

        q.colors_of_figure = 0;
        q.figure_name      = q.name;
        board[0, 3]        = q;

        queen q_black = new queen();     // черная королева

        q_black.colors_of_figure = 1;
        q_black.figure_name      = q_black.name;
        board[7, 3] = q_black;

        king kg = new king();

        kg.colors_of_figure = 0;    // белый король
        kg.figure_name      = kg.name;
        board[0, 4]         = kg;

        king kg_black = new king();

        kg_black.colors_of_figure = 1;    // черный король
        kg_black.figure_name      = kg_black.name;
        board[7, 4] = kg_black;


        for (int i = 0; i < 8; i++) // заполнение 7ой строки черными пешками
        {
            pawn pn = new pawn();
            pn.colors_of_figure = 1;
            pn.figure_name      = pn.name;
            pn.direction        = true;
            board[6, i]         = pn;
        }
    }
Пример #2
0
    /// <summary>
    /// вызывается если активны уже 2 фигуры и проверяется что с ними делать
    /// </summary>
    /// <param name="name"> Имя фигуры </param>
    /// <param name="color"> Цвет фигуры </param>
    public void isMoveCanBe(string name, int color)
    {
        if (State == 0)
        {
            if (name == "pawn")
            {
                // Debug.Log("nameCorrect");
                if (color == 0)
                {
                    //  Debug.Log("colorCorrect");
                    pawn pn = new pawn();
                    if (board[z, x].first_move == false)
                    {
                        pn.first_move = false;
                    }

                    pn.PossibleMoves(z, x);

                    for (int i = 0; i < pn.P_Moves.Count; i++)
                    {
                        if (pn.P_Moves[i].z == second_z & pn.P_Moves[i].x == second_x)
                        {
                            board[z, x].first_move = false;
                            MoveFigure();
                        }
                    }
                }
                else // color == 1
                {
                    pawn pn = new pawn();
                    pn.PossibleMoves(z, x);

                    for (int i = 0; i < pn.Attack_Moves.Count; i++)
                    {
                        if (pn.Attack_Moves[i].z == second_z & pn.Attack_Moves[i].x == second_x)
                        {
                            AttackFigure();
                        }
                    }
                }
            }


            if (name == "queen")
            {
                // Debug.Log("nameCorrect");


                //  Debug.Log("colorCorrect");
                queen q = new queen();

                q.PossibleMoves(z, x);

                for (int i = 0; i < q.P_Moves_Up.Count; i++)
                {
                    if (q.P_Moves_Up[i].z == second_z & q.P_Moves_Up[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < q.P_Moves_Down.Count; i++)
                {
                    if (q.P_Moves_Down[i].z == second_z & q.P_Moves_Down[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < q.P_Moves_Left.Count; i++)
                {
                    if (q.P_Moves_Left[i].z == second_z & q.P_Moves_Left[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < q.P_Moves_Right.Count; i++)
                {
                    if (q.P_Moves_Right[i].z == second_z & q.P_Moves_Right[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < q.P_Moves_LeftUp.Count; i++)
                {
                    if (q.P_Moves_LeftUp[i].z == second_z & q.P_Moves_LeftUp[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < q.P_Moves_RightUp.Count; i++)
                {
                    if (q.P_Moves_RightUp[i].z == second_z & q.P_Moves_RightUp[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }


                for (int i = 0; i < q.P_Moves_RightDown.Count; i++)
                {
                    if (q.P_Moves_RightDown[i].z == second_z & q.P_Moves_RightDown[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < q.P_Moves_LeftDown.Count; i++)
                {
                    if (q.P_Moves_LeftDown[i].z == second_z & q.P_Moves_LeftDown[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }
            }

            if (name == "king")
            {
                king k = new king();

                k.PossibleMoves(z, x);

                for (int i = 0; i < k.P_Moves.Count; i++)
                {
                    if (k.P_Moves[i].z == second_z & k.P_Moves[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < k.P_Moves_r.Count; i++)
                {
                    if (k.P_Moves_r[i].z == second_z & k.P_Moves_r[i].x == second_x)
                    {
                        RokirovkaMove();
                        MoveFigure();
                    }
                }
            }


            if (name == "rook")
            {
                rook rk = new rook();

                rk.PossibleMoves(z, x);

                for (int i = 0; i < rk.P_Moves_Up.Count; i++)
                {
                    if (rk.P_Moves_Up[i].z == second_z & rk.P_Moves_Up[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < rk.P_Moves_Down.Count; i++)
                {
                    if (rk.P_Moves_Down[i].z == second_z & rk.P_Moves_Down[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < rk.P_Moves_Left.Count; i++)
                {
                    if (rk.P_Moves_Left[i].z == second_z & rk.P_Moves_Left[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < rk.P_Moves_Right.Count; i++)
                {
                    if (rk.P_Moves_Right[i].z == second_z & rk.P_Moves_Right[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }
            }


            if (name == "bishop")
            {
                bishop q = new bishop();

                q.PossibleMoves(z, x);

                for (int i = 0; i < q.P_Moves_LeftUp.Count; i++)
                {
                    if (q.P_Moves_LeftUp[i].z == second_z & q.P_Moves_LeftUp[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < q.P_Moves_RightUp.Count; i++)
                {
                    if (q.P_Moves_RightUp[i].z == second_z & q.P_Moves_RightUp[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }


                for (int i = 0; i < q.P_Moves_RightDown.Count; i++)
                {
                    if (q.P_Moves_RightDown[i].z == second_z & q.P_Moves_RightDown[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }

                for (int i = 0; i < q.P_Moves_LeftDown.Count; i++)
                {
                    if (q.P_Moves_LeftDown[i].z == second_z & q.P_Moves_LeftDown[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            MoveFigure();
                        }
                        else
                        {
                            AttackFigure();
                        }
                    }
                }
            }


            if (name == "knight")
            {
                knight q = new knight();

                q.PossibleMoves(z, x);

                for (int i = 0; i < q.P_Moves.Count; i++)
                {
                    if (q.P_Moves[i].z == second_z & q.P_Moves[i].x == second_x)
                    {
                        if (color == 0)
                        {
                            if (color == 0)
                            {
                                MoveFigure();
                            }
                            else
                            {
                                AttackFigure();
                            }
                        }
                        else
                        {
                            if (color == 0)
                            {
                                MoveFigure();
                            }
                            else
                            {
                                AttackFigure();
                            }
                        }
                    }
                }
            }
        }
    }
Пример #3
0
    /// <summary>
    /// Сборка всех ходов
    /// </summary>
    public void checkForMovement()      // собирает все возможные ходы
    {
        Core scriptToAccess = Core_object.GetComponent <Core>();

        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 8; j++)
            {
                if (scriptToAccess.board[i, j].figure_name == "bishop")
                {
                    if (scriptToAccess.board[i, j].colors_of_figure == 1)
                    {
                        bishop b = new bishop();
                        b.colors_of_figure = 1;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.All_moves.Count; x++)
                        {
                            Debug.Log("bishops");

                            All_mv.Add(b.All_moves[x]);
                        }
                    }
                    else // иначе мы смотрим ход для игрока
                    {
                        bishop b = new bishop();
                        b.colors_of_figure = 0;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.All_moves.Count; x++)
                        {
                            //    Debug.Log("bishops");

                            //       P_All_mv.Add(b.All_moves[x]);
                        }
                    }
                }

                if (scriptToAccess.board[i, j].figure_name == "king")
                {
                    if (scriptToAccess.board[i, j].colors_of_figure == 1)
                    {
                        king b = new king();
                        b.colors_of_figure = 1;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.P_Moves.Count; x++)
                        {
                            Debug.Log("king");

                            All_mv.Add(b.P_Moves[x]);
                        }
                    }
                    else // иначе мы смотрим ход для игрока
                    {
                        king b = new king();
                        b.colors_of_figure = 1;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.P_Moves.Count; x++)
                        {
                            //        P_All_mv.Add(b.P_Moves[x]);
                        }
                    }
                }

                if (scriptToAccess.board[i, j].figure_name == "knight")
                {
                    if (scriptToAccess.board[i, j].colors_of_figure == 1)
                    {
                        knight b = new knight();
                        b.colors_of_figure = 1;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.P_Moves.Count; x++)
                        {
                            Debug.Log("knight");
                            Debug.Log(b.P_Moves[x].z);
                            Debug.Log(b.P_Moves[x].x);

                            All_mv.Add(b.P_Moves[x]);

                            //  Debug.Log(All_mv.Count);
                            //  Debug.Log(scriptToAccess.board[0, 6].colors_of_figure);
                        }
                    }
                    else
                    {
                        knight b = new knight();
                        b.colors_of_figure = 0;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.P_Moves.Count; x++)
                        {
                            //       Debug.Log("knight");
                            //         P_All_mv.Add(b.P_Moves[x]);
                            //     //  Debug.Log(scriptToAccess.board[0, 6].colors_of_figure);
                        }
                    }
                }

                if (scriptToAccess.board[i, j].figure_name == "pawn")
                {
                    if (scriptToAccess.board[i, j].colors_of_figure == 1)
                    {
                        pawn b = new pawn();
                        b.colors_of_figure = 1;
                        b.PossibleMovesAI(i, j);
                        for (int x = 0; x < b.P_Moves.Count; x++)
                        {
                            Debug.Log("pawn");
                            All_mv.Add(b.P_Moves[x]);
                        }

                        for (int x = 0; x < b.Attack_Moves.Count; x++)
                        {
                            Debug.Log("pawn");
                            All_mv.Add(b.Attack_Moves[x]);
                        }
                    }
                    else
                    {
                        pawn b = new pawn();
                        b.colors_of_figure = 0;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.P_Moves.Count; x++)
                        {
                            //    P_All_mv.Add(b.P_Moves[x]);
                        }

                        for (int x = 0; x < b.Attack_Moves.Count; x++)
                        {
                            //     P_All_mv.Add(b.Attack_Moves[x]);
                        }
                    }
                }

                if (scriptToAccess.board[i, j].figure_name == "queen")
                {
                    if (scriptToAccess.board[i, j].colors_of_figure == 1)
                    {
                        queen b = new queen();
                        b.colors_of_figure = 1;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.All_moves.Count; x++)
                        {
                            Debug.Log("queen");

                            All_mv.Add(b.All_moves[x]);
                        }
                    }
                    else // иначе мы смотрим ход для игрока
                    {
                        queen b = new queen();
                        b.colors_of_figure = 0;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.All_moves.Count; x++)
                        {
                            //       Debug.Log("queen");

                            //    P_All_mv.Add(b.All_moves[x]);
                        }
                    }
                }


                if (scriptToAccess.board[i, j].figure_name == "rook")
                {
                    if (scriptToAccess.board[i, j].colors_of_figure == 1)
                    {
                        rook b = new rook();
                        b.colors_of_figure = 1;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.All_moves.Count; x++)
                        {
                            Debug.Log("rook");

                            All_mv.Add(b.All_moves[x]);
                        }
                    }
                    else // иначе мы смотрим ход для игрока
                    {
                        rook b = new rook();
                        b.colors_of_figure = 0;
                        b.PossibleMoves(i, j);
                        for (int x = 0; x < b.All_moves.Count; x++)
                        {
                            //       Debug.Log("rook");

                            //   P_All_mv.Add(b.All_moves[x]);
                        }
                    }
                }
            }
        }
    }