Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- class Player(object):
- def __init__(self, name, hold):
- self.name = name
- self.hold_limit = hold
- self.total_score = 0
- self.score = 0
- def take_turn(self, printing):
- self.score = 0
- ship = 0
- captain = 0
- crew = 0
- if printing:
- print "\n" + self.name
- for i in range(3):
- num_dice = 5 - sum((ship, captain, crew))
- dice = [randint(1, 6) for x in range(num_dice)]
- if printing:
- print dice
- if not ship and 6 in dice:
- ship = 1
- dice.remove(6)
- if ship and not captain:
- if 5 in dice:
- captain = 1
- dice.remove(5)
- if captain and not crew:
- if 4 in dice:
- crew = 1
- dice.remove(4)
- if crew:
- cargo = sum(dice)
- if cargo >= self.hold_limit:
- self.score = cargo
- if printing:
- print "{} held with {}".format(self.name, self.score)
- return
- if crew:
- self.score = cargo
- if printing:
- print "{} scored {} points".format(self.name, self.score)
- def ship():
- players = [Player("Re-Roller", 12), Player("Aggressive", 10),
- Player("Average", 9), Player("Conservative", 8),
- Player("Timid", 7), Player("Never-Roller", 2)]
- num_rounds = int(raw_input("How many rounds?"))
- printing = True
- if num_rounds > 50:
- printing = False
- for i in range(num_rounds):
- for player in players:
- player.take_turn(printing)
- player.total_score += player.score
- players = players[1:] + players[:1]
- print "\n"
- for final in sorted(players, key=lambda x: x.total_score)[::-1]:
- print "{:15} {}".format(final.name, final.total_score)
- if __name__ == "__main__":
- ship()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement