/// <summary> /// The thread that will control the montecarlo execution /// </summary>s /// <param name="info">TGame with the current state of the game (the simullation will continue from there)</param> private void MotherThread(System.Object info) { maxNodo = 0; tree = new MontecarloTree((TGame)info, id); M_Node aux; currentActiveSimulations = 0; while (!stop) { // Debug.Log("Entra bucle"); //security check /*if (maxNodo > 150000) * break;*/ if (currentActiveSimulations <= maxSimulations) { aux = tree.SearchForNextNode(); if (aux.Position > maxNodo) { maxNodo = aux.Position; } mMutex.WaitOne(); currentActiveSimulations++; mMutex.ReleaseMutex(); ThreadPool.QueueUserWorkItem(Simulate, aux); } else { Debug.Log("No hay threads libres"); Thread.Sleep(40); } } }
private void Pause_Continue() { if (paused) { paused = false; Clock.Instance.Continue(); Time.timeScale = 1f; } else { paused = true; Clock.Instance.Stop(); Time.timeScale = 0f; //PRUEBAS ARBOL MONTECARLO MontecarloTree tree = new MontecarloTree(currentGame.GetSnapshot(), 0); M_Node aux; for (int i = 0; i < 200; i++) { aux = tree.SearchForNextNode(); aux.Score += Random.Range(-10, 10); Debug.Log("El nodo " + aux.Position + " tiene ahora " + aux.Score + " puntos"); tree.BackpropagateScore(aux); } //DebugSnapshot(currentGame.GetSnapshot()); // DebugSnapshot(currentGame.GetSnapshot().TakeAndGetSnapshot()); //TestAdvanceTurnAndExecuteAction(); } }