public double simulation(Node node) { var validOpts = node.state.Simulate(node.state.CurrentPlayer.Options()).Where(x => x.Value != null); var choosenAction = validOpts.RandomElement(Rnd); int reward = 0; int panic = 0; while (choosenAction.Key.PlayerTaskType != PlayerTaskType.END_TURN && reward != int.MaxValue && reward != int.MinValue) { panic += 1; if (panic >= 100) { //Console.Write("panic!!!!! sim\n"); break; } validOpts = choosenAction.Value.Simulate(choosenAction.Value.CurrentPlayer.Options()).Where(x => x.Value != null); choosenAction = validOpts.RandomElement(Rnd); MidRangeScore rater = new MidRangeScore { Controller = choosenAction.Value.CurrentPlayer }; reward = rater.Rate(); if (_watch.ElapsedMilliseconds >= MAX_TURN_TIME_MS) { break; } } return((double)reward); }
public void expansion(Node node) { if (!node.childNodes.Any()) { var possibleActions = node.state.Simulate(node.state.CurrentPlayer.Options()).Where(x => x.Value != null); foreach (KeyValuePair <PlayerTask, POGame> actionState in possibleActions) { if (actionState.Key.PlayerTaskType == PlayerTaskType.END_TURN) { continue; } Node appnode = new Node(); appnode.state = actionState.Value; appnode.nodeAction = actionState.Key; appnode.parent = node; MidRangeScore rater = new MidRangeScore { Controller = actionState.Value.CurrentPlayer }; appnode.Q = rater.Rate(); node.childNodes.Add(appnode); } } }