Commits

larry committed 5ac2bb6

Stdio UI now draws attention to cards recently played.

Comments (0)

Files changed (1)

 	def must_draw_first(self, player):
 		if not player.hand.deck:
 			return
-		if len(player.cards) < 6:
+		if len(player.cards) < 7:
 			self.illegal(" yet, must draw first")
 
 	def not_on_other(self, player, playee):
 		return (isinstance(last_card, Hazard)
 			and (last_card.safety is self)
 			and (last_playee is playee)
-			and (len(playee.cards) == 5)
+			and (len(playee.cards) == 6)
 			)
 
 	def is_legal(self, player, playee):
 			setattr(self, attr, unpickle_pile(state[attr]))
 
 	def draw(self, card=None):
-		assert len(self.cards) < 6
+		assert len(self.cards) < 7
 		if not self.hand.deck:
 			return None
 
 			self.hand.play()
 
 			p1, p2 = self.players
-			if p1.total_score == p2.total_score:
+			p1_score = p1.score().score
+			p2_score = p2.score().score
+			if p1_score == p2_score:
 				winner = None
-			elif p1.total_score > p2.total_score:
+			elif p1_score > p2_score:
 				winner = p1
 			else:
 				winner = p2
 
 		for player in self.game.players:
 			player.hand_start(self)
-			player.cards = self.deck[0:5]
+			player.cards = self.deck[0:6]
 			player.cards.sort(reverse=True)
-			del self.deck[0:5]
-		
+			del self.deck[0:6]
+
 		self.discard.hand_start(self)
 
 		self.plays = []
 
 		players = itertools.cycle(self.game.players)
 
-		allow_six = True
-		def check_cards(player, allow_six=False):
-			if allow_six:
+		allow_seven = True
+		def check_cards(player, allow_seven=False):
+			if allow_seven:
+				assert len(player.cards) <= 7
+			elif self.deck:
+				assert len(player.cards) == 6
+			else:
 				assert len(player.cards) <= 6
-			elif self.deck:
-				assert len(player.cards) == 5
-			else:
-				assert len(player.cards) <= 5
 
 		winner = None
 		if not self.current_player:
 
 			if not player.cards:
 				continue
-			check_cards(player, allow_six)
+			check_cards(player, allow_seven)
 			print()
 			print("[" + player.name + "]")
 			plays = len(self.plays)
 			#	* all other cards played should be safeties
 			cards_drawn = cards - len(self.deck)
 			plays_taken = len(self.plays) - plays
-			if self.deck and not allow_six:
+			if self.deck and not allow_seven:
 				assert cards_drawn
 				assert cards_drawn == plays_taken
 				for play in self.plays[-plays_taken:-1]:
 					assert isinstance(play.card, Safety)
 				assert not isinstance(self.plays[-1].card, Safety)
-			allow_six = False
+			allow_seven = False
 
 			if player.won():
 				winner = player
 		self.p2.cards = []
 
 	def draw_hand(self, player, *cards):
-		assert len(cards) in {5, 6}
+		assert len(cards) in {6, 7}
 		cards = [convert_card(card) for card in cards]
 		for card in cards:
 			self.hand.deck.remove(card)
 
 	def setUp(self):
 		super().setUp()
-		self.draw_hand(self.p1, 50, 100, roll, roll, roll)
-		self.draw_hand(self.p2, 50, 100, roll, roll, roll)
+		self.draw_hand(self.p1, 50, 75, 100, roll, roll, roll)
+		self.draw_hand(self.p2, 50, 75, 100, roll, roll, roll)
 		self.assertFalse(self.p1.rolling())
 		self.assertFalse(self.p2.rolling())
 
 	s = repr(pile[-1]) if pile else ''
 	return s.rjust(10)
 
-def safeties_repr(player):
+def safeties_repr(player, highlights=()):
 	array = []
 	for card in sorted(player.safeties, reverse=True):
 		s = card.abbreviation
 		if card in player.coup_fourres:
 			s = s.upper()
+		if card in highlights:
+			s = ">" + s + "<"
 		array.append(s)
 	return ' '.join(array)
 
 				return
 
 			while self.cards:
-				print("deck", str(len(hand.deck)).rjust(3) + "/" + str(len(hand.original_deck)), "       discard |" + pile_repr(hand.discard.pile) + "|")
+				if self.hand.plays and self.hand.plays[-1].playee is self.hand.discard:
+					discard_before = ">"
+					discard_after = "<"
+				else:
+					discard_before = discard_after = "|"
+				print("deck", str(len(hand.deck)).rjust(3) + "/" + str(len(hand.original_deck)), "       discard " + discard_before + pile_repr(hand.discard.pile) + discard_after)
 				print("         total|hand    miles|battlepile|speed pile|safeties")
 				def stats(player):
+					before_miles = " "
+					before_battle = between_piles = after_speed = "|"
+					highlights = set()
+					if self.hand.plays:
+						play = self.hand.plays[-1]
+						last_player = play.player
+						card = play.card
+						if play.playee == player:
+							if isinstance(play.card, Mileage):
+								before_miles = ">"
+								before_battle = "<"
+							elif play.card in {speed_limit, end_of_limit}:
+								between_piles = ">"
+								after_speed = "<"
+							elif isinstance(play.card, (Hazard, Remedy)):
+								before_battle = ">"
+								between_piles = "<"
+						for play in reversed(self.hand.plays):
+							if play.player != last_player:
+								break
+							if isinstance(play.card, Safety):
+								highlights.add(play.card)
+
 					strings = [player.name.ljust(8)[:8]]
 					add = strings.append
 
 					add("|")
 					add(str(score).rjust(4))
 
-					add("    ")
+					add("   ")
+					add(before_miles)
 					add(str(player.mileage()).rjust(4))
 
 					add(" .:"[player.two_hundreds()])
 
-					add("|")
+					add(before_battle)
 					add(pile_repr(player.battle_pile))
 
-					add("|")
+					add(between_piles)
 					add(pile_repr(player.speed_pile))
 
-					add("|")
-					add(safeties_repr(player))
+					add(after_speed)
+					add(safeties_repr(player, highlights))
 
 					print("".join(strings))
 
 					line2.append(after)
 
 				print()
-				print("   ", ''.join(line1))
-				print("   ", ''.join(line2))
+				print(" ", ''.join(line1))
+				print(" ", ''.join(line2))
 
 				c = None
-				valid_cards = "123456"[:len(self.cards)]
+				valid_cards = "1234567"[:len(self.cards)]
 				valid = valid_cards + '!' + chr(27)
 				prompt = "    play [1-" + str(len(self.cards)) + "]"
 
-				if hand.deck and (len(self.cards) < 6):
+				if hand.deck and (len(self.cards) < 7):
 					prompt += " or [d]raw?> "
 					valid += "d"
 				else: