Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need some help in python I have coded a Card game program having the following Classes: Card() : Simple class to represent a Comparable
I need some help in python
I have coded a Card game program having the following Classes:
Card() :
Simple class to represent a Comparable playing card, Inherits from Comparable, but number of compares are not kept Instance variables are rank and suit: Both are private integers Here Aces are low and Kings are high Only Rank is used for comparison
Deck() is a list having (rank, suit, compare and str) methods, Node() having (data, size), LinkedList() Class
is an implementation of the Singly LinkedList ADT where both a head pointer and a tail pointer are used. The number of Nodes in the list is kept and updated as Nodes are added and removed. Protected instance variables are used, so that the child classes can get direct access.
having the methods(add_first, add_last, remove_first, str).
Hand() Class:represents a player's Hand in the card game It inherits from the Linked List class. This Hand is controlled by the Player The Player holds the Hand as an instance variable
Player() class:
represents a Player of the card game The Player holds his Hand as an instance variable, The Hand is a Linked List of Cards When a player is dealt a card from the Deck, the Card is added first in his Hand When a player adds a Pile after becoming the winner, the Pile of Cards are added last to the Hand. Cards are only played from the front of the Hand
Pile() Class:
Represents a pile of Cards on the Table Inherits from Linked List Cards are added at the front of the Pile
in the Pile class, I have add_card() method : Add the Card to the front of the list
top_two_card ()method: Find the first two nodes and
return the Node data containing the Cards Return Player1 Card, Player2 Card
I need to know how to code the top_two_card method
from card import Card from linkedList import LinkedList class Pile(LinkedList): """ Represents a pile of Cards on the Table Inherits from Linked List Cards are added at the front of the Pile """ def __init__(self): super().__init__() def add_card(self, card): self.add_card(card) def top_two_cards(self): """ Find the first two nodes and return the Node data containing the Cards Return Player1 Card, Player2 Card """ def __str__(self): """ Return the Cards in the pile as a string starting with the first Card as: Rank-Suit Rank-Suit Rank-Suit etc """ txt = "" curr = self._head for i in range(self._size()): txt = txt + curr.data curr = curr.next return txt
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started