示例#1
0
 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);
     }
 }
示例#2
0
 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);
             }
         }
     }
 }
示例#3
0
        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>());
        }