Ejemplo n.º 1
0
 private void UpdateTrickTracker(Label trickTracker, Label trickTrackerCount, IScopaPlayer player)
 {
     trickTracker.Text = TrickTrackerLabelBase + Environment.NewLine
                         + (player.SetteBello ? "Sette Bello" : "");
     trickTrackerCount.Text = player.CardCount + Environment.NewLine
                              + player.PrimieraValue + Environment.NewLine
                              + player.DenariCount + Environment.NewLine
                              + player.ScopaCount;
 }
Ejemplo n.º 2
0
        private void AddPoint(Func <IScopaPlayer, decimal> predicate)
        {
            IScopaPlayer player = Utilities.MaximumElement(players, predicate);

            if (player != null)
            {
                player.RoundScore += 1;
            }
        }
Ejemplo n.º 3
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);
             }
         }
     }
 }
Ejemplo n.º 4
0
        private void playerName_MouseHover(object sender, EventArgs e)
        {
            IScopaPlayer player = null;

            if (playerAName.Equals(sender))
            {
                player = computer;
            }
            else if (playerBName.Equals(sender))
            {
                player = humanPlayer;
            }
            if (player != null)
            {
                List <Card> trick = player.LastTrick;
                toolTip.SetToolTip(sender as Control, "Last Trick: " + Card.ToString(trick));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Take a trick of the given set of cards from the table using the given
        /// card from the current players hand.  This action can only be taken if
        /// the sum of the value of the cards from the table is equal to the value
        /// of the card being used to take the trick.  Also it is not valid to take
        /// a trick consisting of multiple cards when there is a card of equal value
        /// to the card from the hand on the table.
        /// If the action is successful play moves to the next player.
        /// </summary>
        /// <param name="fromHand">The card from the players hand played to take the trick</param>
        /// <param name="fromTable">The cards from the table that compose the trick</param>
        /// <param name="scopa">Flag indicating if the trick cleared the table (caled a Scopa)</param>
        /// <returns>Flag indicating success or failure of the action</returns>
        public bool TakeTrick(Card fromHand, List <Card> fromTable, out bool scopa)
        {
            if (ValidateTrick(fromHand, fromTable))
            {
                Current.Hand.Remove(fromHand);
                foreach (Card c in fromTable)
                {
                    table.Remove(c);
                }
                scopa = table.Count == 0 && !IsRoundOver;
                List <Card> trick = new List <Card>(fromTable);
                trick.Add(fromHand);
                Current.TakeTrick(trick, scopa);
                lastTrick = Current;

                currentPlayer = ++currentPlayer % players.Count;
                return(true);
            }
            scopa = false;
            return(false);
        }
Ejemplo n.º 6
0
        public WeightedTreeNode BuildTree(ScopaGame game, IScopaPlayer player, int maxDepth)
        {
            WeightedTreeNode root  = new WeightedTreeNode(null);
            GameState        state = new GameState();

            state.Table           = game.Table;
            state.PossibleActions = game.PossibleActions;
            state.Tracker         = player.GetPossibleScores(new List <Card>(), false);
            state.Hand            = new List <Card>(player.Hand);
            List <object[]> queue = new List <object[]>()
            {
                new object[] { root, state, 0, },
            };

            while (queue.Count > 0)
            {
                WeightedTreeNode currNode  = queue[0][0] as WeightedTreeNode;
                GameState        currState = queue[0][1] as GameState;
                int depth = (int)(queue[0][1] as int?);
                queue.RemoveAt(0);
                if (depth > 0 && depth < maxDepth)
                {
                    WeightedSelection selection = DoLevelSelection(currState);
                    List <Card>       trick     = new List <Card>(selection.SelectedTrick);
                    trick.Add((Card)selection.SelectedCard);
                    GameState childState = new GameState();
                    childState.Table = new List <Card>(game.Table);
                    childState.Table.RemoveAll(a => trick.Contains(a));
                    childState.PossibleActions = new PlayerActions(); // AbstractScopaGame.EnumerateAll(childState.Table, selection.SelectedCard);
                    childState.Tracker         = currState.Tracker.GetPossibleScores(trick, currState.Table.Count == selection.SelectedTrick.Count);
                    childState.Hand            = new List <Card>(currState.Hand);
                    childState.Hand.Remove((Card)selection.SelectedCard);
                    queue.Add(new object[] { new WeightedTreeNode(currNode), childState, depth + 1, });
                    currNode.Selection = selection;
                }
            }
            return(root);
        }
Ejemplo n.º 7
0
        private void StepGame(IScopaPlayer player)
        {
            game.TakeAction(player, eventHandler);

            if (game.IsRoundOver)
            {
                game.TakeLastTrick();
                UpdateScores();
                ShowCards();
                CompleteRound();
            }
            else
            {
                if (game.IsHandOver && !game.IsGameOver)
                {
                    game.DealHand();
                }

                ShowDealerImage();
                ShowTurnImage();
                ShowCards();
                UpdateScores();
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Add the provided player instance to the game if it is not currently in progress.
 /// </summary>
 /// <param name="player"></param>
 public void AddPlayer(IScopaPlayer player)
 {
     Debug.Assert(player != null && !IsInProgress);
     players.Add(player);
 }