Commits

Larry Hastings  committed 5f55346

Added highlight around most-recently-drawn card.

  • Participants
  • Parent commits 5866f3b

Comments (0)

Files changed (1)

 		debug("no possible plays.")
 
 
+card_to_string = {
+	mileage_25  : "mileage_25",
+	mileage_50  : "mileage_50",
+	mileage_75  : "mileage_75",
+	mileage_100 : "mileage_100",
+	mileage_200 : "mileage_200",
+
+	accident : "accident",
+	repair : "repair",
+	driving_ace : "driving_ace",
+
+	flat_tire : "flat_tire",
+	spare_tire : "spare_tire",
+	puncture_proof : "puncture_proof",
+
+	out_of_gas : "out_of_gas",
+	gasoline : "gasoline",
+	extra_tank : "extra_tank",
+
+	stop : "stop",
+	roll : "roll",
+	right_of_way : "right_of_way",
+
+	speed_limit : "speed_limit",
+	end_of_limit : "end_of_limit",
+}
+
+string_to_card = { string: card for card, string in card_to_string.items() }
+
+
+class Scenario:
+
+	mileage_25  = 1
+	mileage_50  = 1
+	mileage_75  = 1
+	mileage_100 = 1
+	mileage_200 = 1
+	mileage_repetition_multiplier = 0.5
+
+	accident = flat_tire = out_of_gas = 1
+	hazard_repetition_multiplier = 0.5
+
+	speed_limit = 1
+	speed_limit_repetition_multiplier = 0.5
+
+	repair = spare_tire = gasoline = 1
+	remedy_repetition_multiplier = 0.5
+
+	end_of_limit = 1
+	end_of_limit_repetition_multiplier = 0.5
+
+	stop = 1
+	stop_repetition_multiplier = 0.5
+
+	roll = 1
+	roll_repetition_multiplier = 0.5
+
+	driving_ace = 1
+	puncture_proof = 1
+	extra_tank = 1
+	right_of_way = 1
+	safety_repetition_multiplier = 1
+
+	repetition_multiplier = 0.5
+
+	def weight(self, card):
+		if isinstance(card, Card):
+			card = card_to_string[card]
+		return getattr(self, card)
+
+	card_repetition_multiplier_map = {
+		mileage_25  : "mileage_repetition_multiplier",
+		mileage_50  : "mileage_repetition_multiplier",
+		mileage_75  : "mileage_repetition_multiplier",
+		mileage_100 : "mileage_repetition_multiplier",
+		mileage_200 : "mileage_repetition_multiplier",
+
+		accident   : "hazard_repetition_multiplier",
+		flat_tire  : "hazard_repetition_multiplier",
+		out_of_gas : "hazard_repetition_multiplier",
+
+		speed_limit : "speed_limit_repetition_multiplier",
+
+		repair     : "remedy_repetition_multiplier",
+		spare_tire : "remedy_repetition_multiplier",
+		gasoline   : "remedy_repetition_multiplier",
+
+		end_of_limit : "end_of_limit_repetition_multiplier",
+
+		stop : "stop_repetition_multiplier",
+
+		roll : "roll_repetition_multiplier",
+
+		driving_ace    : "safety_repetition_multiplier",
+		puncture_proof : "safety_repetition_multiplier",
+		extra_tank     : "safety_repetition_multiplier",
+		right_of_way   : "safety_repetition_multiplier",
+		
+	}
+
+	def card_repetition_multiplier(self, card):
+		return getattr(self, self.card_repetition_multiplier_map[card])
+
+	def drew(card):
+		pass
+
+	def played(card):
+		pass
+
+	def discarded(card):
+		pass
+
+
 class SmartComputerPlayer(AverageComputerPlayer):
 	"""
 	Moriarty is as smart as I can make him.
 
 class StdioPlayer(Player):
 
+	def __init__(self, *a, **kw):
+		super().__init__(*a, **kw)
+		self.last_drawn = None
+
 	def keep_playing(self):
 		return yes_no("Keep playing?")
 
 
 			line1 = []
 			line2 = []
+			highlight = self.last_drawn
+			after = " "
 			for i, card in enumerate(self.cards, 1):
-				line1.append(("[" + str(i) + "]").rjust(11))
-				line2.append(repr(card).rjust(11))
+				line1.append(after)
+				line2.append(after)
+				after = " "
+				if card == highlight:
+					before = after = "|"
+					highlight = None
+				else:
+					before = " "
+
+				line1.append(before)
+				line2.append(before)
+				line1.append(("[" + str(i) + "]").rjust(9))
+				line2.append(repr(card).rjust(9)[:9])
+
+			if after:
+				line1.append(after)
+				line2.append(after)
 
 			print()
 			print("   ", ''.join(line1))
 				card = hand.deck.pop()
 				self.cards.append(card)
 				self.cards.sort(reverse=True)
+				self.last_drawn = card
 				print()
 				print("    drew", card)
 				print()
 			# print("    Playing", card, "on", playee.name)
 			try:
 				player.play(card, playee)
+				self.last_drawn = None
 			except IllegalMove as response:
 				bangs = "!" * len(str(response))
 				print()