<commit_before>﻿using UnityEngine;

/// <summary>
/// This script goes on the same GameObject as the GlobalGameUI
/// Conditions for GameObject:
/// Has 9 children that have GameUIs
/// Each child has 9 children that are SpotUIs
/// Child 0 is top left
/// Children and grandchildren are ordered left to right, top to bottom
/// </summary>
class GameInitialization : MonoBehaviour
{
    GlobalGame globalGame;

    /// <summary>
    /// Create all scripts and set up their references to the UI
    /// </summary>
    private void Awake()
    {
        InitializeGames();
        InitializeButtons();

        Destroy(this);
    }

    void InitializeGames()
    {
        int spotUIIndex = 0;
        int localGameUIIndex = 1; // first component is global
        SpotUI[] spotUIs = GetComponentsInChildren<SpotUI>();
        GameUI[] gameUIs = GetComponentsInChildren<GameUI>();
        LocalGame[,] localGames = new LocalGame[3, 3];

        for (int boardRow = 0; boardRow < 3; boardRow++)
        {
            for (int boardCol = 0; boardCol < 3; boardCol++)
            {
                // a grid of spots represents each local board
                Spot[,] spots = new Spot[3, 3];

                for (int spotRow = 0; spotRow < 3; spotRow++)
                {
                    for (int spotCol = 0; spotCol < 3; spotCol++)
                    {
                        // each spot
                        SpotUI spotUI = spotUIs[spotUIIndex];
                        Spot spot = new Spot(
                            new Location(spotRow, spotCol), null, true);

                        spotUI.Spot = spot;

                        spots[spotRow, spotCol] = spot;
                        spotUIIndex++;
                    }
                }

                // each local game
                Location loc = new Location(boardRow, boardCol);
                LocalGame localGame = new LocalGame(spots, true, loc);
                localGames[boardRow, boardCol] = localGame;
                gameUIs[localGameUIIndex].Game = localGame;
                localGameUIIndex++;
            }
        }

        Player p1 = Settings.p1;
        Player p2 = Settings.p2;

        // initialize the global game, its view and its controller
        GlobalGame game = new GlobalGame(localGames, true, p1, p2, true);

        if(p1 is AI) { ((AI)p1).Game = game; }
        if(p2 is AI) { ((AI)p2).Game = game; }

        GetComponent<GameUI>().Game = game;
        GetComponent<GameController>().Game = game;
        globalGame = game;
    }

    void InitializeButtons()
    {
        // Confirm button
        {
            GameObject confirmButton = GameObject.Find("Confirm Button");
            if (confirmButton != null)
            {
                ButtonView confirmView = confirmButton.GetComponent<ButtonView>();
                globalGame.CanConfirmChanged += confirmView.OnValueChanged;
                confirmView.OnValueChanged(globalGame, new BoolEventArgs(false));
            }
        }

        // Undo button
        {
            GameObject undoButton = GameObject.Find("Undo Button");
            if (undoButton != null)
            {
                ButtonView undoView = undoButton.GetComponent<ButtonView>();
                globalGame.CanUndoChanged += undoView.OnValueChanged;
                undoView.OnValueChanged(globalGame, new BoolEventArgs(false));
            }
        }

        // Redo button
        {
            GameObject redoButton = GameObject.Find("Redo Button");
            if (redoButton != null)
            {
                ButtonView redoView = redoButton.GetComponent<ButtonView>();
                globalGame.CanRedoChanged += redoView.OnValueChanged;
                redoView.OnValueChanged(globalGame, new BoolEventArgs(false));
            }
        }

        // Reset button
        {
            GameObject resetButton = GameObject.Find("Reset Button");
            if (resetButton != null)
            {
                ButtonView resetView = resetButton.GetComponent<ButtonView>();
                globalGame.CanUndoChanged += resetView.OnValueChanged;
                resetView.OnValueChanged(globalGame, new BoolEventArgs(false));
            }
        }
    }
}
<commit_msg>Add menu bool: if true, runs a game with two random AIs, otherwise use players in settings<commit_after>﻿using UnityEngine;

/// <summary>
/// This script goes on the same GameObject as the GlobalGameUI
/// Conditions for GameObject:
/// Has 9 children that have GameUIs
/// Each child has 9 children that are SpotUIs
/// Child 0 is top left
/// Children and grandchildren are ordered left to right, top to bottom
/// </summary>
class GameInitialization : MonoBehaviour
{
    GlobalGame globalGame;

    public bool menu;

    /// <summary>
    /// Create all scripts and set up their references to the UI
    /// </summary>
    private void Awake()
    {
        InitializeGames();
        InitializeButtons();

        Destroy(this);
    }

    void InitializeGames()
    {
        int spotUIIndex = 0;
        int localGameUIIndex = 1; // first component is global
        SpotUI[] spotUIs = GetComponentsInChildren<SpotUI>();
        GameUI[] gameUIs = GetComponentsInChildren<GameUI>();
        LocalGame[,] localGames = new LocalGame[3, 3];

        for (int boardRow = 0; boardRow < 3; boardRow++)
        {
            for (int boardCol = 0; boardCol < 3; boardCol++)
            {
                // a grid of spots represents each local board
                Spot[,] spots = new Spot[3, 3];

                for (int spotRow = 0; spotRow < 3; spotRow++)
                {
                    for (int spotCol = 0; spotCol < 3; spotCol++)
                    {
                        // each spot
                        SpotUI spotUI = spotUIs[spotUIIndex];
                        Spot spot = new Spot(
                            new Location(spotRow, spotCol), null, true);

                        spotUI.Spot = spot;

                        spots[spotRow, spotCol] = spot;
                        spotUIIndex++;
                    }
                }

                // each local game
                Location loc = new Location(boardRow, boardCol);
                LocalGame localGame = new LocalGame(spots, true, loc);
                localGames[boardRow, boardCol] = localGame;
                gameUIs[localGameUIIndex].Game = localGame;
                localGameUIIndex++;
            }
        }

        Player p1 = menu ? Settings.RandomAI(true) : Settings.p1;
        Player p2 = menu ? Settings.RandomAI(false) : Settings.p2;
        
        // initialize the global game, its view and its controller
        GlobalGame game = new GlobalGame(localGames, true, p1, p2, true);

        if(p1 is AI) { ((AI)p1).Game = game; }
        if(p2 is AI) { ((AI)p2).Game = game; }

        GetComponent<GameUI>().Game = game;
        GetComponent<GameController>().Game = game;
        globalGame = game;
    }

    void InitializeButtons()
    {
        // Confirm button
        {
            GameObject confirmButton = GameObject.Find("Confirm Button");
            if (confirmButton != null)
            {
                ButtonView confirmView = confirmButton.GetComponent<ButtonView>();
                globalGame.CanConfirmChanged += confirmView.OnValueChanged;
                confirmView.OnValueChanged(globalGame, new BoolEventArgs(false));
            }
        }

        // Undo button
        {
            GameObject undoButton = GameObject.Find("Undo Button");
            if (undoButton != null)
            {
                ButtonView undoView = undoButton.GetComponent<ButtonView>();
                globalGame.CanUndoChanged += undoView.OnValueChanged;
                undoView.OnValueChanged(globalGame, new BoolEventArgs(false));
            }
        }

        // Redo button
        {
            GameObject redoButton = GameObject.Find("Redo Button");
            if (redoButton != null)
            {
                ButtonView redoView = redoButton.GetComponent<ButtonView>();
                globalGame.CanRedoChanged += redoView.OnValueChanged;
                redoView.OnValueChanged(globalGame, new BoolEventArgs(false));
            }
        }

        // Reset button
        {
            GameObject resetButton = GameObject.Find("Reset Button");
            if (resetButton != null)
            {
                ButtonView resetView = resetButton.GetComponent<ButtonView>();
                globalGame.CanUndoChanged += resetView.OnValueChanged;
                resetView.OnValueChanged(globalGame, new BoolEventArgs(false));
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.09541411574448423, 'fraction_numerical': 0.006237726695159986, 'mean_word_length': 1.6356164383561644, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1213937', 'n_tokens_mistral': 2305, 'n_tokens_neox': 2152, 'n_words': 591}