public void StartTree() { foreach (ConnectedTile neighbour in marble.GetCurrentTile().connectedTiles) { if (!neighbour.tile.Occupied) { MiniMaxNode node = CreateInstance(); node.Init(this, marble, GM, false, neighbour.tile); allMoves.Add(node); continue; } else { foreach (ConnectedTile potentialJump in neighbour.tile.connectedTiles) { if (neighbour.direction == potentialJump.direction) { if (!potentialJump.tile.Occupied) { MiniMaxNode node = CreateInstance(); node.Init(this, marble, GM, true, potentialJump.tile); allMoves.Add(node); break; } } } } } if (allMoves.Count == 0) { this.value = 0f; done = true; } else GM.CreateInitialNodes(this); } public IEnumerator CreateNodes() //Gjord som en coroutine för att köra en nod i taget och undvika stack overflow { foreach (MiniMaxNode node in allMoves) { nextNode = false; node.CreateChildren(); yield return new WaitUntil(() => nextNode == true); } } public void ReceiveReport(MiniMaxNode node, float newValue) { if ((this.path == null || value < newValue) && newValue != 0f) { this.path = node.GetPath(); value = newValue; finalNode = node; } doneNodes++; node.Done = true; if (doneNodes >= allMoves.Count) { foreach(MiniMaxNode destroyMe in allMoves) { destroyMe.Destruct(); } done = true; } else { nextNode = true; } }