internal RicksNode(POGame _game, PlayerTask _task = null, RicksNode _parent = null) { game = _game; parent = _parent; task = _task; score = 0; }
internal void GetNext(RicksNode node) { IEnumerable <KeyValuePair <PlayerTask, POGame> > validOpts = node.game.Simulate(node.game.CurrentPlayer.Options()).Where(x => x.Value != null); int count = validOpts.Count(); foreach (KeyValuePair <PlayerTask, POGame> opt in validOpts) { if (opt.Key.PlayerTaskType == PlayerTaskType.END_TURN) { var newNode = new RicksNode(opt.Value, opt.Key, node); newNode.CalcScore(); if (newNode.score >= BestEndNode.score) { BestEndNode = newNode; } } else { int p = rnd.Next(10); if (count < 4 || ((opt.Key.PlayerTaskType == PlayerTaskType.HERO_ATTACK && p < weights[0] * 10) || (opt.Key.PlayerTaskType == PlayerTaskType.PLAY_CARD && p < weights[1] * 10) || (opt.Key.PlayerTaskType == PlayerTaskType.MINION_ATTACK && p < weights[2] * 10))) { nextLevel.Add(new RicksNode(opt.Value, opt.Key, node)); } } } }
internal Tree(POGame poGame, double[] _weights) { //calculate whole turn only once nextLevel = new List <RicksNode>(); currentLevel = new List <RicksNode>(); BestEndNode = new RicksNode(); root = new RicksNode(poGame); weights = _weights; }
internal Stack <PlayerTask> GetTaskList() { var result = new Stack <PlayerTask>(); //result.Push(this.task); RicksNode next = parent; while (next?.parent != null) { result.Push(next.task); next = next.parent; } return(result); }
internal void GetNext() { StartWatch(); currentLevel.Add(root); while (currentLevel.Any() && CheckTime()) { GetNext(currentLevel.Last()); currentLevel.RemoveAt(currentLevel.Count() - 1); if (!currentLevel.Any()) { currentLevel.AddRange(nextLevel); nextLevel.Clear(); } } foreach (RicksNode nextnode in nextLevel) { if (watch.ElapsedMilliseconds <= 25 * 1000) { nextnode.CalcScore(); if (nextnode.score >= BestEndNode.score) { BestEndNode = nextnode; } } } foreach (RicksNode nextnode in currentLevel) { if (watch.ElapsedMilliseconds <= 27 * 1000) { nextnode.CalcScore(); if (nextnode.score >= BestEndNode.score) { BestEndNode = nextnode; } } } StopWatch(); }