private Node MakeTree() { GameGrid realGrid = GameBoard.gameGrid; GameGrid virtualGrid = new GameGrid(); virtualGrid.Grid = GameGrid.CloneGrid(realGrid.Grid); Vector3Int opponentPos = opponent.CurrentTilePos; PlayerNum nextMovesBelongsTo; Queue <Node> list = new Queue <Node>(); Node root = new Node(virtualGrid, new List <Node>(), HeuristicManager.Heuristic(availableMoves.Count, opponent.availableMoves.Count), 0, availableMoves, CurrentTilePos, opponentPos, PlayerNum.Player2); list.Enqueue(root); while (list.Count > 0) { Node node = list.Dequeue(); if (node.depth % 2 == 0) { nextMovesBelongsTo = PlayerNum.Player1; } else { nextMovesBelongsTo = PlayerNum.Player2; } if (node.depth <= GameManager.Instance.treeDepth && node.moves.Count > 0) { foreach (Vector3Int item in node.moves) { GameGrid newGameGrid = new GameGrid(); newGameGrid.Grid = GameGrid.CloneGrid(node.gameGrid.Grid); Vector3Int activePlayerPos = item; newGameGrid.Grid[item.x, item.y].isExplored = true; List <Vector3Int> nextMoves = GetAvailableMoves(newGameGrid, node.opponentPos); List <Vector3Int> thisMoves = GetAvailableMoves(newGameGrid, activePlayerPos); Node child = new Node(newGameGrid, new List <Node>(), HeuristicManager.Heuristic(thisMoves.Count, nextMoves.Count), node.depth + 1, nextMoves, node.opponentPos, activePlayerPos, nextMovesBelongsTo); node.children.Add(child); list.Enqueue(child); } } } return(root); }