public MonteCarlo(Deck deck, Enemy enemy, Player player, int turnNumber = 0, List <string> firstHand = null) { _Deck = deck ?? throw new ArgumentNullException(nameof(deck)); _Enemy = enemy ?? throw new ArgumentNullException(); _Player = player ?? throw new ArgumentNullException(); _TurnNumber = turnNumber; if (firstHand == null) { //by default shuffle the deck at fight start. _Deck.Reshuffle(new EffectSet(), new List <string>()); } else { var cards = _Deck.FindSetOfCards(_Deck.GetDrawPile, firstHand); var firstAction = new FightAction(FightActionEnum.StartTurn, cardTargets: cards); _FirstAction = firstAction; } var fight = new Fight(_Deck, _Player, _Enemy); fight.TurnNumber = _TurnNumber; var root = new FightNode(fight); fight.FightNode = root; root.StartFight(); Root = root; if (_FirstAction != null) { root.ApplyAction(_FirstAction); } }
/// <summary> /// Returns the leaf node of a single mc run. /// </summary> public FightNode MC(FightNode fn) { if (fn.Depth == 1) { MCCount++; } var actions = fn.Fight.GetAllActions(); var ii = Rnd.Next(actions.Count()); //ii = 0; var action = actions[ii]; var childNode = fn.ApplyAction(action); switch (childNode.Fight.Status) { case FightStatus.Ongoing: return(MC(childNode)); case FightStatus.Won: return(childNode); case FightStatus.Lost: return(childNode); default: throw new Exception("Other status"); } }