public GameState(GameState currGs, GameState parent_)
 {
     Piece[,] data = new Piece[puzzleSize, puzzleSize];
     for (int i = 0; i < puzzleSize; i++)
         for (int j = 0; j < puzzleSize; j++)
             data[i, j] = new Piece(currGs.data[i, j].val);
     this.parent = parent_;
     this.children = new GameState[maxNumChildren];
 }
 public void addChild(GameState node_)
 {
     node_.parent = this;
     children[numChildren] = node_;
     numChildren++;
 }
 public static void ConstructGameTreeRecursive(GameState node, int currDepth)
 {
     int j;
     int temp;
     bool breakFlag = false;
     int[] s = new int[] { -1, -1 };
     //temp = node.getUtilVal();
     if (currDepth >= maxDepth)
     {
         node.getVal();
         return;
     }
     int[] possibleMoveInd;
     //GameState next = new GameState();
     //GameState next = (GameState)node.MemberwiseClone();
     possibleMoveInd = node.getPossibleMoves();
     GameState[] next = new GameState[possibleMoveInd.Length];
     GameState grandParent = node.parent;
     for (int i = 0; i < possibleMoveInd.Length; i++)
     {
         next[i] = node.cloneTurnAndData();
         s = ind2sub(possibleMoveInd[i]);
         if (next[i].makeMove(s[0], s[1]) == -1)
             return;
         next[i].nextMove();
         node.addChild(next[i]);
         ConstructGameTreeRecursive(next[i], currDepth + 1);
         next[i].dumpData(currDepth + 1);
         if (GameState.useAlphaBetaPr)
         {
             // alpha-beta control
             if (node.isComputersTurn())
             {
                 
                 breakFlag = false;
                 if (grandParent != null)
                 {
                     for (j = 0; j < grandParent.numChildren; j++)
                         if (grandParent.children[j] == node)
                             break;
                     for (int k = 0; k < j; k++)
                     {
                         if ((grandParent.children[k].val == Inf) || (grandParent.children[k].val == -Inf) || (next[i].val == Inf) || (next[i].val == -Inf))
                             break;
                         if (grandParent.children[k].val < next[i].val)
                         {
                             node.val = next[i].val;
                             // prune!
                             breakFlag = true;
                             break;
                         }
                     }
                 }
                 if (breakFlag)
                     // daha fazla cocuk ekleme, cik
                     break;
             }
             else
             {
                 breakFlag = false;
                 if (grandParent != null)
                 {
                     for (j = 0; j < grandParent.numChildren; j++)
                         if (grandParent.children[j] == node)
                             break;
                     for (int k = 0; k < j; k++)
                     {
                         if ((grandParent.children[k].val == Inf) || (grandParent.children[k].val == -Inf) || (next[i].val == Inf) || (next[i].val == -Inf))
                             break;
                         if (grandParent.children[k].val > next[i].val)
                         {
                             node.val = next[i].val;
                             // prune!
                             breakFlag = true;
                             break;
                         }
                     }
                 }
                 if (breakFlag)
                     // daha fazla cocuk ekleme, cik
                     break;
             }
         }
     }
     // tum cocuklar eklendigine gore intervali guncelle
     int max = -Inf;
     int min = Inf;
     int currVal;
     GameState temp1 = node.parent;
     if (temp1 == null)
         temp = 1;
     for (int i = 0; i < node.numChildren; i++)
     {
         currVal = node.children[i].getVal();
         if (currVal > max)
             max = currVal;
         if (currVal < min)
             min = currVal;
     }
     if (node.isComputersTurn())
         // max node
         node.val = max;
     else
         node.val = min;
 }
        public GameState cloneTurnAndData()
        {
            GameState y = new GameState();
            // set data
            for (int i = 0; i < puzzleSize; i++)
                for (int j = 0; j < puzzleSize; j++)
                    y.data[i, j].val = this.data[i, j].val;
            y.turn = this.turn;
            return y;

        }
 public Form1()
 {
     InitializeComponent();
     currentState = new GameState();
     gridTextBoxes = new System.Windows.Forms.PictureBox[GameState.puzzleSize, GameState.puzzleSize];
 }