public List<Card> CardsForSkill(Player player, Skill skill, Card fromCard) { bool targetAttacker = Attacker.Id == player.Id; string name = skill.Name.ToLower(); bool targetShelf = name == "barrier" || name == "empower" || name == "heal" || name == "legion" || name == "fervor"; targetAttacker = targetAttacker ? targetShelf : !targetShelf; return targetAttacker ? Attacker.CardsForSkill(skill, fromCard) : Defender.CardsForSkill(skill, fromCard); }
public DeckFinder(Game game, Player originalPlayer, List<Player> testOponents, List<Card> inventory, int repeticiones = 0) { this.simulator = game; this.attacker = originalPlayer; this.oponents = testOponents; this.cardVault = inventory; if (repeticiones > 0) repeatCombat = repeticiones; attacker.Init(); this.baseDeck = attacker.Deck.OrderBy(x=>x.Id).ToList(); if (inventory != null) this.cardVault = inventory.OrderBy(X => X.Id).ToList(); }
public TestEngine() { //Set initial Decks baseDeck = new List<Card>(); Card card; card = new Card() { Attack = 1, Defense = 10, Delay = 0 }; baseDeck.Add(card); card = new Card() { Attack = 2, Defense = 5, Delay = 1 }; baseDeck.Add(card); card = new Card() { Attack = 3, Defense = 2, Delay = 2 }; baseDeck.Add(card); game = new Game(); Player player; player = new Player() { HitPoints = 10, Name = "A", Id = 1 }; game.PlayerA = player; player = new Player() { HitPoints = 10, Name = "B", Id = 2 }; game.PlayerB = player; }
public Player Search(int maxVariations, int depth, int width) { int times = -1; Player bestPlayer = attacker; List<Result> resultados = null; Game game = new Game(oponents); long elapsed; int pos = 0; Result result = simulator.FightAll(attacker, repeatCombat); this.winRate = result.Wins; while (times < width) { if (winRate > 99.9999) break; FindCandidates(maxVariations, depth, pos); resultados = new List<Result>(); foreach(Player attacker in candidates) { elapsed = DateTime.Now.Ticks; resultados.Add(game.FightAll(attacker, repeatCombat)); Console.WriteLine(string.Format("Tiempo {0}:{1} ms {2:%#0.00}({3:%#0.00})", attacker.Name, (DateTime.Now.Ticks - elapsed) / 10000, resultados[resultados.Count - 1].Wins, resultados.Max(x => x.Wins))); } resultados = resultados.OrderByDescending(x => x.Wins).ThenByDescending(x => x.Id).ToList(); if (resultados[0].Attacker.Id != attacker.Id && resultados[0].Wins > winRate) { for(int i = 0; i < candidates.Count; i++) { if (resultados[0].Attacker.Id == candidates[i].Id) { pos = i; break; } } attacker = resultados[0].Attacker; winRate = resultados[0].Wins; Console.WriteLine(attacker.ToFullString()); times = 0; } else { if (times < 0) times = 0; times++; pos = 0; } } Console.WriteLine(string.Format("Wins: {0:%#0.00}", winRate)); return attacker; }
public DeadPlayerExeption(Player player) : base() { this.DeadPlayer = player; }
public bool BeginSteppedCombat(Player attacker, Player defender) { if (attacker==null || defender==null) return false; if (steppedCombat == null) { steppedCombat = new Combat(attacker, defender); steppedCombat.InitCombat(combatOptions); } return true; }
public void LoadFromFiles(String cardPath = null, String playersPath = null) { if (cardPath == null) cardPath = @"Cartas.csv"; if (playersPath == null) playersPath = @"Players.csv"; cards = new CardCollection(); cards.ReadFromFile(cardPath); HelperCsv fichero = new HelperCsv(playersPath); Player player; oponentes = new List<Player>(); for (int i = 0; i < fichero.Count; i++) { player = new Player(); player.LoadFromCsv(fichero, i, this.cards); oponentes.Add(player); } }
public Result FightAll(Player attacker, int repeatCombat) { Result resultado = new Result(); resultado.Attacker = attacker; foreach (Player defender in this.oponentes) { if (attacker.Id == defender.Id) continue; Combat combat = new Combat(attacker.Clone(), defender.Clone(), repeatCombat); resultado.Record(combat.Resolve(combatOptions)); } return resultado; }
public Player Clone() { Player newPlayer = new Player(Id, Hero,deckOriginal.Select(x=>x.Clone()).ToList()); newPlayer.Name = Name; return newPlayer; }
public void DoTurn(Player attacker, Player defender) { InitTurn(attacker, defender); #region Draw a Card if (attacker.Deck.Count > 0) { Random random = new Random(); int nextCard = random.Next(attacker.Deck.Count); attacker.Hand.Add(attacker.Deck[nextCard].Clone()); attacker.Deck.RemoveAt(nextCard); } #endregion #region Battleeffects foreach (Skill skill in combatOptions.BattleEffects) { foreach (Card card in attacker.CardsForHeroSkill(skill)) { card.TakeSkill(skill); } } #endregion #region Hero Skills foreach (Skill skill in attacker.Skills) { foreach (Card card in attacker.CardsForHeroSkill(skill)) { card.TakeSkill(skill); } } #endregion #region OpenTurn Skills foreach (Card card in attacker.Hand.Where(x => x.Delay < 1 && x.Defense > 0 && x.Skills.Where(s => s.Category == SkillCat.TurnActivated).Count() > 0)) { foreach (Skill skill in card.Skills.Where(s => s.Category == SkillCat.TurnActivated)) { foreach (Card target in this.CardsForSkill(attacker, skill, card)) { target.TakeSkill(skill); } } } #endregion #region Attack Skills & Attack for (int i = 0; i < attacker.Hand.Count; i++) { if (attacker.Hand[i].Delay > 0) continue; DoCardAttack(attacker, defender, i); if (attacker.Hand[i].Skills.Any(s => s.Name.ToLower() == "dualstrike")) { foreach (Skill skill in attacker.Hand[i].Skills.Where(s => s.Name.ToLower() == "dualstrike")) { if (skill.Aux == skill.Value) { skill.Aux = -1; DoCardAttack(attacker, defender, i); } } } } #endregion #region AfterAttack effects & dead recolection foreach (Card affectedCard in attacker.Hand) { if (affectedCard.Scorch > 0) { affectedCard.Defense -= affectedCard.Scorch; if (!affectedCard.Scorched) affectedCard.Scorch = 0; } affectedCard.Defense -= affectedCard.Poison; } for (int i = 14; i >= 0; i--) { if (attacker.Hand.Count <= i) continue; if (attacker.Hand[i].Defense < 1) attacker.Hand.RemoveAt(i); } for (int i = 14; i >= 0; i--) { if (defender.Hand.Count <= i) continue; if (defender.Hand[i].Defense < 1) defender.Hand.RemoveAt(i); } #endregion }
public Combat(Player att, Player def, int repeat) : this(att, def) { this.Repeat = repeat; }
protected void InitTurn(Player attacker, Player defender) { foreach (Card card in attacker.Hand) { card.Barrier = 0; card.AttackModifier = 0; if (card.Delay > 0) card.Delay--; card.Hex = 0; foreach (Skill skill in card.Skills) { skill.Enhance = 0; } } foreach (Card card in defender.Hand) { card.Scorched = false; foreach (Skill skill in card.Skills) { skill.Enhance = 0; } foreach (Skill skill in card.Skills.Where(x => x.Name.ToLower() == "invisibility")) { skill.Aux = skill.Value; } } }
protected void DoCardAttack(Player attacker, Player defender, int pos) { if (attacker.Hand[pos].Delay > 0) return; foreach (Skill skill in attacker.Hand[pos].Skills.Where(s => s.Category == SkillCat.Activated)) { foreach (Card card in this.CardsForSkill(attacker, skill, attacker.Hand[pos])) { card.TakeSkill(skill); } } if (defender.Hand.Count > pos) { defender.Hand[pos].TakeAttack(attacker.Hand[pos]); } else { defender.TakeAttack(attacker.Hand[pos]); } }
public Combat(Player att, Player def) { this.Attacker = att; this.Defender = def; }