public IEnumerable <GameAction> GetAllSummonActions(GameState gameState, Player player) { var charsCount = gameState.Of(player).Minions.Count; if (charsCount == MaxOnboardCount) { return(Enumerable.Empty <SummonAction>()); } var possibleBoardPositions = Enumerable.Range(0, charsCount + 1); var playableMinionCards = GetManaPlayableCards(gameState, player).OfType <MinionCard>().ToArray(); var playableAsTargetable = playableMinionCards .OfType <BattlecryMinionCard>() .Where(card => ValidBattlecryTargets(card, gameState, player).Any()).ToArray(); var targetableSummonActions = playableAsTargetable.SelectMany( card => ValidBattlecryTargets(card, gameState, player) .CartesianProduct(possibleBoardPositions, (target, position) => new SummonBattlecryTargetable(player, card, target, position))); var otherSummonActions = playableMinionCards.Except(playableAsTargetable) .SelectMany(card => possibleBoardPositions.Select(position => new SummonAction(player, card, position))); return(targetableSummonActions.Concat(otherSummonActions)); }
public IEnumerable <GameAction> GetAllAttackActions(GameState gameState, Player player) { var validPlayerAttackers = gameState.Of(player).Minions.Where(x => x.CanAttack); var opponentChars = gameState.OfOpponent(player).AllTargets; var validOpponentTargets = GetValidAttackTargets(opponentChars); return(validPlayerAttackers.SelectMany(attacker => validOpponentTargets.Select(target => new AttackAction(player, attacker, target)))); }
private static GameState CardPlayUpdateHandMana(GameState gameState, Card card, Player owner) { var currentPlayerState = gameState.Of(owner); var newPlayerState = currentPlayerState.With( hand: x => x.RemoveCard(card), remainingMana: x => x - card.ManaCost); return(gameState.With(newPlayerState)); }
public IEnumerable <Character> GetValidTargets(GameState gameState, Player player, Minion caster) { if (Target.HasFlag(Target.Adjacent)) { return(GetAdjacentMinions(gameState.Of(player).Minions, caster)); } return(Target.HasFlag(Target.Self) ? GetValidTargets(gameState, player).Concat(caster.Yield()).Distinct() : GetValidTargets(gameState, player).Except(caster.Yield())); }
public override GameState ApplyOn(GameState gameState, Player player, Minion caster) { var playerGameState = gameState.Of(player); if (playerGameState.Minions.Count == GameEngine.MaxOnboardCount) { return(gameState); } var summonAt = caster == null ? playerGameState.Minions.Count : playerGameState.Minions.IndexOf(caster) + 1; return(gameState.With(playerGameState.With(minions: x => x.Insert(summonAt, new Minion(_card))))); }
public IEnumerable <Character> GetValidTargets(GameState gameState, Player player) { var returnValue = new List <Character>(); if (Target.HasFlag(Target.FriendlyMinions)) { returnValue.AddRange(gameState.Of(player).Minions); } if (Target.HasFlag(Target.FriendlyFaces)) { returnValue.Add(gameState.Of(player).Face); } if (Target.HasFlag(Target.EnemyMinions)) { returnValue.AddRange(gameState.OfOpponent(player).Minions); } if (Target.HasFlag(Target.EnemyFaces)) { returnValue.Add(gameState.OfOpponent(player).Face); } return(returnValue.Where(x => _isTargetValid(x)).Where(x => !x.IsDead)); }
private static IEnumerable <Card> GetManaPlayableCards(GameState gameState, Player player) { return(gameState.Of(player).Hand.Where(card => card.ManaCost <= gameState.Of(player).RemainingMana)); }