Commits

larry committed c68d6ea

Fixed Norman!

Comments (0)

Files changed (1)

 
 	def hand_start(self):
 		super().hand_start()
-		self.safety_countdown = 0
-		self.play_safety = False
-		self.discardables = set()
+		self.hand.safety_countdown = 0
+		self.hand.play_safety = False
+		self.hand.discardables = set()
 
 	def check_for_coup_fouree(self, debug):
 		if not hand.plays:
 		if safety in self.hand.hand:
 			self.print("coup fourré!")
 			self.play(safety)
-			self.draw()
+			self.hand.draw()
 			return True
 		return False
 
 	def card_to_get_moving(self):
-		if self.rolling():
+		if self.hand.rolling():
 			return None
 
 		if not self.hand.battle_pile:
 	def _decide_to_extend(self):
 		# shutout?  hot damn!
 		# don't chance the extend, take the points!
-		if not self.other().mileage():
+		if not self.other().hand.mileage():
 			return True
 
 		other_safeties = self.other().hand.safeties
 		return extend_if
 
 	def decide_to_extend(self):
-		if self.won() and self.mileage() == 700:
+		if self.hand.won() and self.hand.mileage() == 700:
 			if self._decide_to_extend():
 				print()
 				print("    ----------------------")
 		if not cards:
 			return None
 
-		mileage = self.mileage()
+		mileage = self.hand.mileage()
 		limit = 1000 if hand.extended else 700
 
 		# if we're not near winning, play biggest card.
 			if playee == self.other():
 				addendum = "on you"
 		print("    hmm,", verb, card, addendum)
-		super().play(card, playee)
+		self.hand.play(card, playee)
 		self.decide_to_extend()
 
+	def discard(self, card):
+		self.play(card, series.discard)
+
 	def turn(self):
 		debug = self.debug
 
 		self.check_for_coup_fouree(debug)
-		drew = self.draw()
+		drew = self.hand.draw()
 		debug("drew", drew)
 
-		safety_countdown = self.safety_countdown
-		self.safety_countdown = 0
-		play_safety = self.play_safety
-		self.play_safety = False
+		safety_countdown = self.hand.safety_countdown
+		self.hand.safety_countdown = 0
+		play_safety = self.hand.play_safety
+		self.hand.play_safety = False
 
 		preferred_hazards = []
 		hazards = []
 		debug("cards", " ".join([card.abbreviation for card in self.hand.hand]))
 		debug("limit", limit, "mileage", mileage, "maxed_out_200s", maxed_out_200s)
 		for card in self.hand.hand:
-			if card in self.discardables:
+			if card in self.hand.discardables:
 				debug(card, "-> preferred_discards (in discardables)")
 				preferred_discards.append(card)
 			elif isinstance(card, Hazard):
 				debug(card, "-> safeties")
 				safeties.append(card)
 
-		self.discardables.update(preferred_discards)
+		self.hand.discardables.update(preferred_discards)
 
 		mileage.sort(key=lambda x: x.distance)
 		safeties.sort()
 		## we probably want to win right now.
 		##
 
-		they_can_win = other.rolling()
+		they_can_win = other.hand.rolling()
 		if they_can_win:
-			other_mileage = other.mileage()
+			other_mileage = other.hand.mileage()
 			if other_mileage >= 700:
 				other_mileage -= 300
 			possibles = {25, 50}
 		# are we moving?
 		safeties_needed_to_win = set()
 		card_to_win = None
-		we_can_win = self.rolling()
+		we_can_win = self.hand.rolling()
 		debug("P0.a", we_can_win)
 
 		if not we_can_win:
 				for safety in safeties_to_play:
 					debug("P0.f")
 					self.play(safety)
-					drew = self.draw()
+					drew = self.hand.draw()
 					debug("drew", drew)
 					if extending and isinstance(drew, Safety):
 						next.add(drew)
 			debug("P0.g")
 			was_unextended = not hand.extended
 			self.play(card_to_win)
-			assert self.won() or (was_unextended and hand.extended)
+			assert self.hand.won() or (was_unextended and hand.extended)
 			return
 
 		################################################################
 		## and to get more cards so we can try to stop them.
 		##
 
-		if other.rolling():
+		if other.hand.rolling():
 			for cards in (preferred_hazards, hazards, stops):
 				if cards:
 					randomly_play_one(cards, "P1.a", other)
 				self.play(speed_limit, other)
 				return
 
-			other_mileage = other.mileage()
+			other_mileage = other.hand.mileage()
 			if other_mileage >= 700:
 				other_mileage -= 300
 			possibles = {25, 50}
 		## priority 2: if we are not rolling, get rolling.
 		##
 
-		if not self.rolling():
+		if not self.hand.rolling():
 			needed = self.card_to_get_moving()
 			assert needed
 			debug("P2:", needed)
 		## play any viable mileage card so as to prevent shut-out.
 		##
 
-		if self.rolling() and not self.mileage() and mileage:
+		if self.hand.rolling() and not self.hand.mileage() and mileage:
 			if self.hand.autobahn():
 				debug("P3.a")
 				self.play(mileage[-1])
 		## priority 5: play mileage
 		##
 
-		if mileage and self.rolling():
+		if mileage and self.hand.rolling():
 			play_from = mileage
 			if not self.hand.autobahn():
 				low_mileage = [x for x in mileage if x.distance <= 50]
 					debug("P6.c")
 					self.play(right_of_way)
 					return self.turn()
-			self.play_safety = True
+			self.hand.play_safety = True
 		elif safety_countdown:
 			safety_countdown -= 1
 			if not safety_countdown:
-				self.play_safety = True
+				self.hand.play_safety = True
 			else:
-				self.safety_countdown = safety_countdown
+				self.hand.safety_countdown = safety_countdown
 		else:
 			cards_remaining = len(hand.draw_pile)
-			self.safety_countdown = random.randint(int(cards_remaining * 0.05), int(cards_remaining * 0.1))
+			self.hand.safety_countdown = random.randint(int(cards_remaining * 0.05), int(cards_remaining * 0.1))
 
 		###################################################
 		###################################################
 		# discard remedies and play safeties
 		# for hazards that have all been played
 		needed = self.card_to_get_moving()
-		assert needed not in self.discardables
+		assert needed not in self.hand.discardables
 
 		def remedy_unneeded(remedy):
-			if remedy not in self.discardables:
+			if remedy not in self.hand.discardables:
 				self.debug("[:] ah!  we no longer have a use for", remedy)
-				self.discardables.add(remedy)
+				self.hand.discardables.add(remedy)
 
 		def coup_fouree_impossible_for(safety):
 			self.obsolete_safeties.add(safety)
 					card = hand.draw_pile.pop()
 					self.hand.hand.append(card)
 					self.hand.hand.sort(reverse=True)
-					self.last_drawn = card
+					self.hand.last_drawn = card
 					print()
 					print("    drew", card)
 					print()
 			help()
 			series = Series()
 			series.add_player(StdioPlayer())
-			series.add_player(DumbComputerPlayer())
+			series.add_player(AverageComputerPlayer())
 
 	series.play()