//http://diehrstraits.com/2009/05/basic-dominion-strategy/ public static Instruction ChapelBuy(IGame game, AIPlayer player) { int coins = player.CoinCountThisRound; if (player.ActiveCount == 1) { if (coins <= 4) { return(GeneralAIHelper.GenerateBuyInstruction("Chapel")); } } if (coins >= 8 && GeneralAIHelper.CanBuyCard(game, "Province")) { return(GeneralAIHelper.GenerateBuyInstruction("Province")); } if (coins >= 6 && GeneralAIHelper.CanBuyCard(game, "Gold")) { return(GeneralAIHelper.GenerateBuyInstruction("Gold")); } if (coins >= 3 && GeneralAIHelper.CanBuyCard(game, "Silver")) { return(GeneralAIHelper.GenerateBuyInstruction("Silver")); } return(null); }
// http://diehrstraits.com/2009/05/basic-dominion-strategy/ public static Instruction GrandSmithyBuy(IGame game, AIPlayer player) { int coins = player.CoinCountThisRound; if (coins >= 8 && GeneralAIHelper.CanBuyCard(game, "Province")) { return(GeneralAIHelper.GenerateBuyInstruction("Province")); } if (coins >= 6 && GeneralAIHelper.CanBuyCard(game, "Gold")) { return(GeneralAIHelper.GenerateBuyInstruction("Gold")); } if (coins >= 4) { var smithyCards = player.GetAllPlayerCards().Where(card => card.Info.CardName == "Smithy"); if (smithyCards.Count() < 3 && GeneralAIHelper.CanBuyCard(game, "Smithy")) { return(GeneralAIHelper.GenerateBuyInstruction("Smithy")); } } if (coins >= 3 && GeneralAIHelper.CanBuyCard(game, "Silver")) { return(GeneralAIHelper.GenerateBuyInstruction("Silver")); } return(null); }
public override Instruction GenerateNextInstruction(IGame game) { if (buyStageActions.Count > 1) { if (this.ActiveCount > this.CurrentBuyStrategy.Round) { this.buyStageActions.Dequeue(); } } if (this.CanAction()) { var instruction = GeneralAIHelper.DoAction(this); if (instruction != null) { return(instruction); } } if (this.CanBuy()) { var instruction = this.CurrentBuyStrategy.Action.Invoke(game, this); if (instruction != null) { return(instruction); } } StringBuilder instructionString = new StringBuilder(); instructionString.Append(InstructionKeyWord.Next); return(Instruction.TryParse(instructionString.ToString())); }
// Normal level internal static string ResolveCardRemodelGainCardAI(IGame game, Player player, Card cardToTrash) { int coins = cardToTrash.Info.Cost + 2; if (coins == 8) { return("Province"); } // if gold not existed, not doing the remodel if (coins == 6) { // TODO: need to check card existed if (game.CardPiles["Gold"].IsEmpty) { return(cardToTrash.Info.CardName); } return("Gold"); } if (coins == 5) { if (player is AIPlayer && (player as AIPlayer).FirstVictoryBuyRound >= player.ActiveCount) { if (GeneralAIHelper.CanBuyCard(game, "Duchy")) { return("Duchy"); } } } var availalbeCards = game.GameInfo.ActionCards.Where(c => c.Value.Cost == coins).Select(c => c.Value); if (availalbeCards.Count() > 0) { var canBuyCards = availalbeCards.Where(cardInfo => GeneralAIHelper.CanBuyCard(game, cardInfo.CardName)); if (canBuyCards.Count() > 0) { var random = new Random(); return(EnumerableHelper.ElementAt(canBuyCards, random.Next(0, canBuyCards.Count() - 1)).CardName); } } availalbeCards = game.GameInfo.ActionCards.Where(c => c.Value.Cost == coins - 1).Select(c => c.Value); if (availalbeCards.Count() > 0) { var canBuyCards = availalbeCards.Where(cardInfo => GeneralAIHelper.CanBuyCard(game, cardInfo.CardName)); if (canBuyCards.Count() > 0) { var random = new Random(); return(EnumerableHelper.ElementAt(canBuyCards, random.Next(0, canBuyCards.Count() - 1)).CardName); } } //TODO: need to check card available return(cardToTrash.Info.CardName); }
public static Instruction WeightingBuy(IGame game, AIPlayer player) { var allCards = player.GetAllPlayerCards(); int allCardsCount = allCards.Count(); int allActionCardcsCount = allCards.Count(card => card.Info.IsActionCard); int allTreasureCardcsCount = allCards.Count(card => card.Info.IsTreasureCard); double actionCardWeight = (double)allActionCardcsCount * 100 / allCardsCount; double treasureCardWeight = (double)allTreasureCardcsCount * 100 / allCardsCount; var roundAction = player.CurrentBuyStrategy; bool actionCardOverWeight = actionCardWeight >= roundAction.ActionCardWeighting; bool treasureCardOverWeight = treasureCardWeight >= roundAction.TreasureCardWeighting; bool actionCardMaxmized = allActionCardcsCount >= roundAction.MaxActionCards; bool treasureCardMaxmized = allTreasureCardcsCount >= roundAction.MaxTreasureCards; Instruction instruction = null; instruction = GeneralAIHelper.BuyVictoryCard(game, player); if (instruction != null) { return(instruction); } if (!actionCardMaxmized && !treasureCardMaxmized) { if (!actionCardOverWeight && !treasureCardOverWeight) { var actionCardSS = (roundAction.ActionCardWeighting - actionCardWeight) / roundAction.ActionCardWeighting; var treasureCardSS = (roundAction.TreasureCardWeighting - treasureCardWeight) / roundAction.TreasureCardWeighting; if (actionCardSS > treasureCardSS) { instruction = GeneralAIHelper.BuyActionCard(game, player); } else { instruction = GeneralAIHelper.BuyTresureCard(game, player); } } else if (actionCardOverWeight && !treasureCardOverWeight) { instruction = GeneralAIHelper.BuyTresureCard(game, player); } else if (!actionCardOverWeight && treasureCardOverWeight) { instruction = GeneralAIHelper.BuyActionCard(game, player); } } else if (actionCardMaxmized && !treasureCardMaxmized) { if (!treasureCardOverWeight) { instruction = GeneralAIHelper.BuyTresureCard(game, player); } } else if (!actionCardMaxmized && treasureCardMaxmized) { if (!actionCardOverWeight) { instruction = GeneralAIHelper.BuyActionCard(game, player); } } if (instruction != null) { return(instruction); } //buy victory cards, ignore the earilest buy vicotry card return(null); }
public virtual Instruction GenerateNextInstruction(IGame game) { return(GeneralAIHelper.PerformAI(game, this)); }