//-------------------------------------------------------------------- //Updates this Node and it's parents Value and number of visits public void Update(byte Winner) { if (Winner == 0) { Value += 5; } else if (Winner == Action.player) { Value += 10; } NumberOfVisits += 1; if (parent != null) { parent.Update(Winner); } }
//-------------------------------------------------------------------- //Make a random simulation of the game private void Simulate(Node selected) { simulationState.ImportState(selected.State); if (selected.Action.Move != null) { simulationState.Change(selected.Action); } //So that we know which player comes next byte currPlayer = NextPlayer(selected.Action.player); while (!simulationState.isOver) { IAction[] possActions = simulationState.PossMoves(currPlayer); simulationState.Change(possActions[rnd.Next(0, possActions.Length)]); currPlayer = NextPlayer(currPlayer); } //Updates the Value of the Node selected.Update(simulationState.whoWon); }