Beispiel #1
0
        //This method MUST be called by all children in their playCard method.
        public Boolean isLegalMove(Trick currentTrick, Card attemptedPlay)
        {
            Boolean isLegal = true;

            //If this card is not already onsuit, must check tobe sure hand has no onsuit cards in it
            if (!currentTrick.onSuitCheck(attemptedPlay))
            {
                for (int i = 0; i < hand.Count; i++)
                {
                    //So, one of the cards in the hand is the attemptedPlay, and we need to ignore that one
                    //Otherwise, as soon as you find an onsuit card elsewhere, this play is illegal
                    if (currentTrick.onSuitCheck((Card)hand[i]) == true && hand[i] != attemptedPlay)
                    {
                        isLegal = false;
                    }
                }
            }
            return(isLegal);
        }
Beispiel #2
0
        public void nextTrick()
        {
            if (currentTrick != null)    //only the first trick should move past this
            {
                pastTricks.Add(currentTrick);
                foreach (Player p in seats)
                {
                    p.updatedCardCount(currentTrick);
                }
            }
            currentTrick = new Trick(seats, trump);
            //Leader plays, then rotate around whole table
            Card played = seats[leader].leadCard(this);

            currentTrick.leadPlay(played, leader);

            for (int i = 1; i <= 3; i++)
            {
                played = seats[(leader + i) % 4].playCard(this);
                currentTrick.addPlay(played, ((leader + i) % 4));
            }
            //update next leader as winner of trick
            int winner = currentTrick.winner();

            leader = winner;
            //Update cumulative trick-winning total
            if (winner == 0 || winner == 2)
            {
                team02Tricks++;
            }
            else if (winner == 1 || winner == 3)
            {
                team13Tricks++;
            }
            else
            {
                Console.WriteLine("ERROR: Problem determining trick winner in Hand");
            }
        }
Beispiel #3
0
        //Finds the best onsuit play, which is win with the worst of the best, or just go with the worst
        //It's given that there's at least two valid moves. Must return a valid move
        public int findOnsuitPlay(Trick currentTrick, ArrayList validMoves)
        {
            int  index    = 0;
            bool winnable = false;

            for (int i = 0; i < validMoves.Count; i++)
            {
                //If we can beat the current card
                if (isBetterCard(currentTrick.getMoves()[currentTrick.currentWinner], (Card)validMoves[i], currentTrick.trumpSuit))
                {
                    //There was no previous winning card
                    if (!winnable)
                    {
                        winnable = true;
                        index    = i;
                    }
                    //There is already a winnable card
                    else
                    {
                        //If the old card can beat the new card, we want to use the new one to save the better
                        if (isBetterCard((Card)validMoves[i], (Card)validMoves[index], currentTrick.trumpSuit))
                        {
                            index = i;
                        }
                    }
                }
                //This card can't beat the current card, and there isn't yet a card that can
                else if (!winnable)
                {
                    //If the old card can beat the new card, we want to use the new to save our better one
                    if (isBetterCard((Card)validMoves[i], (Card)validMoves[index], currentTrick.trumpSuit))
                    {
                        index = i;
                    }
                }
            }
            return(index);
        }
Beispiel #4
0
 public void updatedCardCount(Trick pastTrick)
 {
     counter.removeGroup(new ArrayList(pastTrick.getMoves()));
 }