Python coding please. Also if you could add comments that would be greatly appri
ID: 3851773 • Letter: P
Question
Python coding please. Also if you could add comments that would be greatly appriciated. This is my fourth time asking this question. Please use the files in the link, escpecially proj06.py. Comments and indentation would help a lot too. The print statement needs to reflect that of the one above. All files that are to bu used are in that link. I would appreciate any help.
PLEASE indent and comment because I am very confused on what is goig on. PLEASE use the links in the description. PLEASE follow the requirements above. I am struggling a lot and need some help and would greatly appriciate all the help I can get.
There are base python codes that are used for this. They are found in the link below:
http://www.cse.msu.edu/~cse231/Online/Projects/Project06/
CSE 231 Summer 2017 Programming Project #6 Edit on 6/19/17 a skeleton file is has been available on Mirmir and is now available in the same directory as this document (posted on 6/18) Edit on 6/20/17 we provide a cannonical function in the skeleton file to order cards so your output can more easily match the Mimir tests for Testl and Test2 Assignment Overview This assignment focuses on the design, implementation and testing of a Python program which uses classes to solve the problem described below. Note: you are using a class we provide; you are not designing a class It is worth 95 points (9.5% of course grade) and must be completed no later than 11:59 PM on Monday, June 26 Assignment Deliverable The deliverable for this assignment is the following file proj06.py -the source code for your Python program Be sure to use the specified file name and to submit it for grading via the Mirmir system before the project deadline. Assignment Background The goal of this project is to gain practice with use of classes and creating functions. You will design and implement a Python program which plays simplified Texas Hold'em Poker The program should deal two cards to two players (one card to each player, then a second card to each player), and then five community cards which players share to make their hands. A poker hand is the best five cards from the community cards plus the player's cards (i.e., best 5 out of 7 cards total). The goal of this assignment is to find the category of each player's hand and determine the winner The rules of this game are relatively simple and you can find information about the game and about the poker hands in the links below. Keep in mind that you will only find the category of the hands and all nine cards can be dealt at once (a real poker game deals cards in stages to allow for betting, but we aren't betting). http://en.wikipedia.org/wiki/Texas_holdem http://en.wikipedia.org/wiki/Poker_handsExplanation / Answer
class Game:
playerOnesHand = []
playerTwosHand = []
playerOneScore = 0
playerTwoScore = 0
result = 0
def __init__(self, cards):
cards = cards.split()
self.playerOnesHand = Hand(cards[0:5])
self.playerTwosHand = Hand(cards[5:10])
self.play();
def play(self):
self.playerOneScore = self.playerOnesHand.getScore();
self.playerTwosCore = self.playerTwosHand.getScore();
if (self.playerOneScore > self.playerTwoScore):
result = 1
else:
result = 2
class Hand:
cards = []
values = []
def setValues(self):
for card in self.cards:
self.values.append(card.value)
self.values.sort()
print len(self.values)
def isFlush(self):
currentSuit = self.cards[0].suit
for card in self.cards:
if card.suit != currentSuit:
return False
currentSuit = card.suit
return True
def isRoyalFlush(self):
for card in self.cards:
self.values.append(card.value)
low = min(self.values)
if low == 10 and (low + 1 in self.values) and (low + 2 in self.values) and (low + 3 in self.values) and (low + 4 in self.values):
return True
else:
return False
def isFourOfAKind(self):
cardOneCount = self.values.count(self.values[0])
cardTwoCount = self.values.count(self.values[len(self.values) - 1])
if cardOneCount == 4 | cardTwoCount == 4:
return True
else:
return False
def isThreeOfAKind(self):
cardOneCount = self.values.count(self.values[0])
cardTwoCount = self.values.count(self.values[len(self.values) - 1])
if cardOneCount == 3 | cardTwoCount == 3:
return True
else:
return False
def isStraight(self):
low = min(self.values)
if low == 10 and (low + 1 in self.values) and (low + 2 in self.values) and (low + 3 in self.values) and (low + 4 in self.values):
return True;
def isFullHouse(self):
self.values = []
for card in self.cards:
self.values.append(card.value)
self.values.sort()
cardOneCount = self.values.count(self.values[0])
cardTwoCount = self.values.count(self.values[len(self.values) - 1])
if (cardOneCount == 2 and cardTwoCount == 3 ) | (cardOneCount == 3 and cardTwoCount == 2):
return True
else:
return False
def isTwoPair(self):
cardOneCount = self.values.count(self.values[0])
cardTwoCount = self.values.count(self.values[4])
cardThreeCount = self.values.count(self.values[2])
if(cardOneCount == 2 and cardTwoCount == 2) | (cardOneCount == 2 and cardThreeCount == 2) | (cardTwoCount == 2 and cardThreeCount == 2):
return True;
return False;
def isPair(self):
cardOneCount = self.values.count(self.values[0])
cardTwoCount = self.values.count(self.values[4])
cardThreeCount = self.values.count(self.values[2])
if(cardOneCount == 2 ^ cardTwoCount == 2 ^ cardTwoCount == 3):
return True;
return False;
def __init__(self, cards):
for c in cards:
self.cards.append(Card(c))
self.setValues()
def getScore(self):
score = 0
if self.isRoyalFlush(): score = 140000
elif self.isFlush() and self.isStraight(): score = 130000
elif self.isFourOfAKind(): score = 120000
elif self.isFullHouse(): score = 110000
elif self.isFlush(): score = 100000
elif self.isStraight(): score = 90000
elif self.isThreeOfAKind(): score = 80000
elif self.isTwoPair(): score = 70000
elif self.isTwoPair(): score = 60000
else: score = 0
return score
class Card:
# value = 0
# suit = 0
def __init__(self, card):
self.value = self.determineValue(card[0])
self.suit = card[1]
def determineValue(x,y):
return {
'2':2,
'3':3,
'4':4,
'5':6,
'6':6,
'7':7,
'8':8,
'9':9,
'T':10,
'J':11,
'Q':12,
'K':13,
'A':14
}.get(y)
def playGames():
player1Score = 0;
player2Score = 0;
file = open("poker-small.txt")
for line in file:
game = Game(line)
if game.result == 1:
player1Score += 1
else:
player2Score += 1
print "Player one has won " + str(player1Score) + " games! "
print "Player two has won " + str(player2Score) + " games! "
if (player1Score > player2Score):
print "Player 1 wins!"
else:
print "Player 2 wins!"
def main():
playGames();
if __name__ == "__main__":
main()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.