public override PlayerAction GetNextAction() { NetworkMessage message = new NetworkMessage(); message.MessageCategory = GameMessages.GamePrefix; message.MessageType = GameMessages.RequestAction; this.connection.SendMessage(message); this.resetEvent.Reset(); this.resetEvent.WaitOne(); PlayerAction nextAction = new PlayerAction(); switch (this.gameMessage.MessageType) { case GameMessages.PlayCard: { ActionCardInfo playCardInfo = NetworkSerializer.Deserialize<ActionCardInfo>(this.gameMessage.MessageContent); nextAction.ActionType = ActionType.PlayCard; nextAction.Card = this.Player.Hand.First(c => c.ID == playCardInfo.Card); } break; case GameMessages.BuyCard: { ActionCardInfo buyCardInfo = NetworkSerializer.Deserialize<ActionCardInfo>(this.gameMessage.MessageContent); nextAction.ActionType = ActionType.BuyCard; nextAction.Pile = this.GameModel.SupplyPiles.First(p => p.Card.ID == buyCardInfo.Card); } break; case GameMessages.CleanupCard: { ActionCardInfo cleanupCardInfo = NetworkSerializer.Deserialize<ActionCardInfo>(this.gameMessage.MessageContent); nextAction.ActionType = ActionType.CleanupCard; nextAction.Card = this.Player.Cleanup.First(c => c.ID == cleanupCardInfo.Card); } break; case GameMessages.EndTurn: { nextAction.ActionType = ActionType.EndTurn; } break; case GameMessages.BuyPhase: { nextAction.ActionType = ActionType.EnterBuyPhase; } break; case GameMessages.PlayBasicTreasure: { nextAction.ActionType = ActionType.PlayBasicTreasures; } break; case GameMessages.PlayCoinTokens: { nextAction.ActionType = ActionType.PlayCoinTokens; } break; } return nextAction; }
static void EvaulateBestStrategyForFirstGame() { //FindBestStrategy currently finds the following, which is better than BigMoneySimple, but not as good as BigMoney //Province(1), Province, Gold, Market(1), Duchy(2), Militia(2), Silver, Estate(1),Workshop(1), Cellar(1), var player1 = new PlayerAction("Player 1", 1, new CardPickByPriority( CardAcceptance.For(Cards.Province), CardAcceptance.For(Cards.Gold), CardAcceptance.For(Cards.Market, gameState => Strategies.CountAllOwned(Cards.Market, gameState) < 1), CardAcceptance.For(Cards.Duchy, gameState => Strategies.CountAllOwned(Cards.Duchy, gameState) < 2), CardAcceptance.For(Cards.Militia, gameState => Strategies.CountAllOwned(Cards.Militia, gameState) < 2), CardAcceptance.For(Cards.Silver), CardAcceptance.For(Cards.Estate, gameState => Strategies.CountAllOwned(Cards.Militia, gameState) < 1) )); Program.ComparePlayers(player1, Strategies.BigMoneySimple.Player(2), showVerboseScore: true); Program.ComparePlayers(player1, Strategies.BigMoney.Player(2), showVerboseScore: true); Program.ComparePlayers(player1, Strategies.BigMoneySingleSmithy.Player(2), showVerboseScore: true); }
public void HandlePlayerAction(PlayerAction action) { switch (action.ActionType) { case ActionType.PlayCard: if (action.Card != null) { this.Play(action.Card); } if (this.CurrentPhase == GamePhase.Action && this.CurrentPlayer.Actions == 0) { this.AdvancePhase(); } break; case ActionType.PlayBasicTreasures: if (this.CurrentPhase == GamePhase.Action) { this.AdvancePhase(); } this.PlayBasicTreasures(); break; case ActionType.PlayCoinTokens: string[] choices = new string[this.CurrentPlayer.CoinTokens + 1]; for (int i = 0; i <= this.CurrentPlayer.CoinTokens; i++) { choices[i] = (i).ToString(); } int choice = this.CurrentPlayer.Chooser.ChooseOneEffect(EffectChoiceType.PlayCoinTokens, "Choose number of coin tokens to play", choices, choices); this.CurrentPlayer.PlayCoinTokens(choice); break; case ActionType.CleanupCard: if (action.Card != null) { this.CurrentPlayer.DoCleanup(action.Card); } else // cleanup all { foreach (CardModel card in this.CurrentPlayer.Cleanup.ToArray()) { card.OnCleanup(this); } } if (this.CurrentPlayer.Cleanup.Count == 0) { this.AdvancePhase(); } break; case ActionType.BuyCard: this.Buy(action.Pile); if (this.CurrentPlayer.Buys == 0) { this.AdvancePhase(); } break; case ActionType.EnterBuyPhase: if (this.CurrentPhase == GamePhase.Action) { this.AdvancePhase(); } break; case ActionType.EndTurn: if (this.CurrentPhase == GamePhase.CleanUp) { this.AdvancePhase(); } else { if (this.CurrentPhase == GamePhase.Action) { this.AdvancePhase(); } if (this.CurrentPhase == GamePhase.Buy) { this.AdvancePhase(); } } break; default: break; } if (this.PileBuyStatusChanged != null) { this.PileBuyStatusChanged(this, EventArgs.Empty); } }
public GameModel CloneAndPlay(PlayerAction playerAction, bool keepHandInfo, Func<GameModel, GameModel, Player, BaseAIStrategy> strategyFactory) { GameModel clone = this.Clone(keepHandInfo, strategyFactory); PlayerAction clonedAction = new PlayerAction(); clonedAction.ActionType = playerAction.ActionType; switch (playerAction.ActionType) { case ActionType.BuyCard: clonedAction.Pile = clone.SupplyPiles.First(p => p.Name == playerAction.Pile.Name); break; case ActionType.CleanupCard: clonedAction.Card = clone.CurrentPlayer.Cleanup.First(c => c.Name == playerAction.Card.Name); break; case ActionType.PlayCard: clonedAction.Card = clone.CurrentPlayer.Hand.First(c => c.Name == playerAction.Card.Name); break; } clone.HandlePlayerAction(clonedAction); return clone; }
public void PerformUIPlayerAction(ActionType actionType, CardViewModel card, PileViewModel pile) { this.uiRequestAction = new PlayerAction(); this.uiRequestAction.ActionType = actionType; this.uiRequestAction.Card = card != null ? card.CardModel : null; this.uiRequestAction.Pile = pile != null ? pile.PileModel : null; this.state = ClientState.WaitingForOpponent; this.uiPlayerActionWaitHandle.Set(); }
private bool TryBuyCard(Player player, Type cardType, out PlayerAction playerAction) { Pile pile = null; if (this.GameModel.PileMap.TryGetValue(cardType, out pile)) { if (player.Coin >= pile.GetCost() && (player.Potions > 0 || !pile.CostsPotion) && pile.Count > 0) { playerAction = new PlayerAction() { ActionType = ActionType.BuyCard, Pile = pile }; return true; } } playerAction = null; return false; }