public void PopulateActions() { if (!Current.Equals(possibleActions.Player)) { possibleActions.Player = Current; possibleActions.CardActions = new List <CardActions>(); foreach (Card c in Current.Hand) { CardActions cardActions = new CardActions(); cardActions.Card = c; cardActions.IsThrowable = ValidateThrow(c); cardActions.PossibleTricks = new List <List <Card> >(); if (!cardActions.IsThrowable) { List <List <Card> > possibles = ScopaGame.EnumerateAll(table, c); foreach (List <Card> possible in possibles) { if (ValidateTrick(c, possible)) { cardActions.PossibleTricks.Add(possible); } } } possibleActions.CardActions.Add(cardActions); } possibleActions.CanThrow = possibleActions.CardActions.Any <CardActions>(a => a.IsThrowable); possibleActions.CanTrick = possibleActions.CardActions.Any <CardActions>(a => !a.IsThrowable); } }
public void TakeAction(IScopaPlayer player, ScopaEventHandler eventHandler) { if (player.IsPly) { PopulateActions(); Card selectedCard = player.SelectCard(); List <Card> selectedTrick = player.SelectTrick(selectedCard); CardActions actions = possibleActions[selectedCard]; if (actions.IsThrowable) { if (selectedTrick.Count == 0) { if (ThrowCard(selectedCard)) { eventHandler.CardThrown(selectedCard); } else { eventHandler.UnableToThrow(selectedCard); } } else { eventHandler.MustThrowCard(selectedCard); } } else { if (selectedTrick.Count > 0) { bool scopa; if (TakeTrick(selectedCard, selectedTrick, out scopa)) { eventHandler.TrickTaken(selectedCard, selectedTrick); } else { eventHandler.UnableToTakeTrick(selectedCard, selectedTrick); } if (scopa) { eventHandler.Scopa(selectedCard, selectedTrick); } } else { eventHandler.MustTakeTrick(selectedCard); } } } }
public override List <Card> SelectTrick(Card card) { game.PopulateActions(); CardActions actions = game.PossibleActions[card]; if (!actions.IsThrowable) { if (actions.PossibleTricks != null) { if (actions.PossibleTricks.Count == 1) { return(actions.PossibleTricks[0]); } return(selector.SelectTrick(game, this, card)); } } return(new List <Card>()); }