Ejemplo n.º 1
0
    static public void ComputerPlay()
    {
        if (GameManager.Instance.currentState.BlackWin || GameManager.Instance.currentState.BlackScore >= 10 || GameManager.Instance.currentState.WhiteWin || GameManager.Instance.currentState.WhiteScore >= 10)
        {
            return;
        }
        GameStatus game;

        game.Board          = new int[GameManager.Instance.iHeightBoard * GameManager.Instance.iWidthBoard];
        game.bPlayerOneTurn = GameManager.Instance.currentState.bPlayerOneTurn;
        game.HasWon         = GameManager.Instance.currentState.hasWon;
        game.WhiteScore     = GameManager.Instance.currentState.WhiteScore;
        game.BlackScore     = GameManager.Instance.currentState.BlackScore;
        game.WinY           = GameManager.Instance.currentState.winY;
        game.WinX           = GameManager.Instance.currentState.winX;
        game.Depth          = PlayerPrefs.GetInt("Depth");
        game.Timer          = PlayerPrefs.GetFloat("Timer");
        game.Algo           = PlayerPrefs.GetInt("Algo");
        game.MaxMove        = PlayerPrefs.GetInt("Move");

        if (game.Depth < 2 || game.Depth > 30)
        {
            game.Depth = 2;
        }
        if (game.Timer < 0.5f || game.Timer > 10.0f)
        {
            game.Timer = 0.5f;
        }
        if (game.MaxMove < 3 || game.MaxMove > 100)
        {
            game.MaxMove = 3;
        }
        if (game.Algo < 0 || game.Algo > 7)
        {
            game.Algo = 0;
        }

        for (int i = 0; i < GameManager.Instance.iHeightBoard; i++)
        {
            for (int j = 0; j < GameManager.Instance.iWidthBoard; j++)
            {
                game.Board[i * GameManager.Instance.iWidthBoard + j] = GameManager.Instance.currentState.Board[i, j];
            }
        }
        CoordIA test = IAPlay(game);

        Debug.Log("y = " + test.y + " et x = " + test.x + " et Depth = " + test.Depth + " et Time = " + test.Timer + " et Value = " + test.Value);
        GameManager.Instance.DepthText.text = test.Depth.ToString();
        GameManager.Instance.ValueText.text = test.Value.ToString();
        GameManager.Instance.TimeText.text  = test.Timer.ToString();
        int        id   = test.x + test.y * GameManager.Instance.iWidthBoard + 1;
        GameObject box  = GameObject.Find("Stone (" + id + ")");
        PlayStone  Move = box.GetComponent <PlayStone>();

        if (!GameManager.Instance.currentState.bPlayerOneTurn)
        {
            Move.OnWhitePlay();
        }
        else
        {
            Move.OnBlackPlay();
        }
    }
Ejemplo n.º 2
0
        public void StoneCreation()
        {
            // creates all of the buttons / stones
            // uses the outer square as an orientation point
            int ox = 50;
            int oy = 50;
            int ol = 500;

            // creates all of the buttons in the respective positions in the array
            for (int z = 0; z <= 2; z++)
            {
                for (int y = 0; y <= 2; y++)
                {
                    for (int x = 0; x <= 2; x++)
                    {
                        if (start)
                        {
                            // if there would be an error the button would be created in the upper-right corner
                            int locx = 0;
                            int locy = 0;
                            // creates button
                            buttons[x, y, z] = new PlayStone();
                            // writes the coordinates in custom attributes
                            buttons[x, y, z].X = x;
                            buttons[x, y, z].Y = y;
                            buttons[x, y, z].Z = z;
                            // obviously the buttons start as not part of a mill
                            buttons[x, y, z].Mill = false;
                            // adds the on click event
                            buttons[x, y, z].Click += (s, e) =>
                            {
                                // will set the ibtn variables to the xyz position of the buttons and calls the game
                                PlayStone thisButton = s as PlayStone;
                                ibtnx = thisButton.X;
                                ibtny = thisButton.Y;
                                ibtnz = thisButton.Z;
                                GameProgression();
                            };
                            // sets the position of the buttons according to their location within the array
                            // left side
                            if (x == 0)
                            {
                                locx = ox - 15;
                            }
                            // middle
                            else if (x == 1)
                            {
                                locx = ox + ol / 2 - 15;
                            }
                            // right side
                            else if (x == 2)
                            {
                                locx = ox + ol - 25;
                            }
                            // top
                            if (y == 0)
                            {
                                locy = oy - 15;
                            }
                            // middle
                            else if (y == 1)
                            {
                                locy = oy + ol / 2 - 15;
                            }
                            // bottom
                            else if (y == 2)
                            {
                                locy = oy + ol - 15;
                            }
                            // sets button size, appearance and location (standard is transparent for all of them)
                            buttons[x, y, z].Size      = new Size(40, 40);
                            buttons[x, y, z].Location  = new Point(locx, locy);
                            buttons[x, y, z].FlatStyle = FlatStyle.Flat;
                            buttons[x, y, z].FlatAppearance.BorderSize = 0;
                            buttons[x, y, z].BackColor = Color.Transparent;
                            buttons[x, y, z].FlatAppearance.MouseOverBackColor = Color.Transparent;
                            buttons[x, y, z].FlatAppearance.MouseDownBackColor = Color.Transparent;
                            // sets the location of the button as a name... for no apparent reason
                            //buttons[x, y, z].Text = Convert.ToString(buttons[x, y, z].X) + Convert.ToString(buttons[x, y, z].Y) + Convert.ToString(buttons[x, y, z].Z);
                            // if the buttons are none of the inner buttons they will be placed on the board
                            if (!(x == 1 && y == 1))
                            {
                                this.Controls.Add(buttons[x, y, z]);
                            }

                            /*else
                             * {
                             *  buttons[x, y, z].BackColor = Color.Khaki;
                             * }*/
                        }
                    }
                }
                // after each square it will move closer to the middle
                ox += 50;
                oy += 50;
                ol -= 100;
            }
        }