Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- class Gambling_Model (object):
- def __init__(self):
- self.bag = ['Red', 'Yellow', 'Blue']
- self.cache = []
- self.turns, self.player, self.comp = 0, 0, 0
- self.playerguess = None
- def start_game(self, maxturns):
- self.maxturns = maxturns
- Gambling_Model.player_turn(self)
- def draw_ball(self):
- self.cache.append(self.bag[random.randrange(0, 3)])
- if self.cache[len(self.cache) - 1] == self.playerguess:
- self.player += 1
- self.turns += 1
- if self.turns == self.maxturns:
- Gambling_Model.gameover(self)
- else:
- Gambling_Model.player_turn(self)
- else:
- self.comp += 1
- self.turns += 1
- if self.turns == self.maxturns:
- Gambling_Model.gameover(self)
- else:
- Gambling_Model.player_turn(self)
- def player_turn(self):
- if self.cache == []:
- self.playerguess = self.bag[random.randrange(0, 3)]
- Gambling_Model.draw_ball(self)
- else:
- frequency = {self.cache.count(x):x for x in self.cache}
- self.playerguess = frequency[max(frequency.keys())]
- Gambling_Model.draw_ball(self)
- def gameover(self):
- print "Final Score: player = %d, computer = %d" %(self.player, self.comp)
- self.turns, self.player, self.comp = 0, 0, 0
- self.playerguess = None
- self.cache = []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement