public Node(Node a, int dir)
 {
     pare = a;
     tau  = new Tauler(a.tau);
     tau.updateTauler(dir);
     cost     = tau.score;
     direccio = dir;
 }
    // Start is called before the first frame update
    void Start()
    {
        tauler = new Tauler();
        tauler.insertValue();

        arbre = new tree(tauler, depth);
        //InvokeRepeating("ia", 0.01f, 0.01f);
        //ia();
        showValues();
    }
 public Tauler(Tauler t)
 {
     m_tauler = new float[4][];
     for (int i = 0; i < 4; i++)
     {
         m_tauler[i] = new float[4];
         for (int j = 0; j < 4; j++)
         {
             m_tauler[i][j] = t.m_tauler[i][j];
         }
     }
     score = t.score;
 }
    public Tauler nextdir()
    {
        Node min   = selectNode();
        Node prev  = null;
        int  count = 0;

        while (count < depth)
        {
            prev = min;
            min  = min.pare;
            count++;
        }

        arrel      = prev.pare;
        arrel.pare = null;
        dirA       = prev.direccio;
        Tauler t      = new Tauler(prev.tau);
        bool   acabat = true;

        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                if (arrel.tau.m_tauler[i][j] != prev.tau.m_tauler[i][j])
                {
                    acabat = false;
                }
            }
        }
        if (acabat)
        {
            t.m_tauler[0][0] = t.m_tauler[0][0] + 10000;
        }

        return(t);// prev.direccio;
    }
 void ia()
 {
     arbre.construirArbre();
     tauler = arbre.nextdir();
     showValues();
 }
 public tree(Tauler t, int profunditat)
 {
     depth = profunditat;
     arrel = new Node(t);
 }
 public Node(Tauler t)
 {
     pare = null;
     tau  = t;
     cost = t.score;
 }