Commits

larry committed 3a2c59a

Now using new scoring object!

Comments (0)

Files changed (1)

 
 class Score:
 
-	miles = 0
+	mileage = 0
 	safeties = 0
 	coups_fourres = 0
 
 
 		if (
 			  as_if_won
-			  or ((mileage == 700) and (not hand.extended))
-			  or (mileage == 1000)
+			  or (self.mileage == (1000 if hand.extended else 700))
 			):
 			self.trip_complete = True
 			self.extension = self.mileage == 1000
 			self.safe_trip = not player.hand.two_hundreds()
 			self.shutout = not player.others[0].hand.mileage()
 
+	def __repr__(self):
+		return " ".join((str(x) for x in (
+			"<Score",
+			self.mileage,
+			"safeties",
+			self.safeties, self.coups_fourres,
+			"complete",
+			"NY"[self.trip_complete],
+			"da", "NY"[self.delayed_action],
+			"st", "NY"[self.safe_trip],
+			"so", "NY"[self.shutout],
+			))) + ">"
+
 	def render(self):
 		array = []
 		def score(points, *a):
 			if not points:
 				return
 			s = ' '.join(str(x) for x in a)
-			array.append(s.rjust(19) + ' ... ' + str(points).rjust(4))
-
-		score(self.miles, self.miles, "miles")
-
-		score(self.safeties * 100, cardinal(self.safeties), "safet" + ("y" if safeties == 1 else "ies"))
+			array.append((points, s.rjust(19) + ' ... ' + str(points).rjust(4)))
+
+		score(self.mileage, self.mileage, "miles")
+
+		safeties = self.safeties 
+		score(safeties * 100, cardinal(safeties), "safet" + ("y" if safeties == 1 else "ies"))
 		if safeties == 4:
 			score(300, "all four safeties")
-		score(self.coupes_fourres * 300, cardinal(self.coupes_fourres), "coup{s} fourré{s}".format(s="" if coupes == 1 else "s"))
+		coups = self.coups_fourres
+		score(coups * 300, cardinal(coups), "coup{s} fourré{s}".format(s="" if coups == 1 else "s"))
 
 		if self.trip_complete:
 			score(400, "trip complete")
-			if self.miles == 1000:
+			if self.mileage == 1000:
 				score(200, "extension")
 			if self.delayed_action:
 				score(300, "delayed action")
 		return sum((x[0] for x in self.render()))
 
 	def __str__(self):
-		return "\n".join(self.render())
+		return "\n".join((x[1] for x in self.render()))
 
 	@property
 	def statistics(self):
 		return {
-			"miles": self.miles,
+			"mileage": self.mileage,
 			"0 safeties": self.safeties == 0,
 			"1 safeties": self.safeties == 1,
 			"2 safeties": self.safeties == 2,
 			"3 coups fourrés": self.coups_fourres == 3,
 			"4 coups fourrés": self.coups_fourres == 4,
 			"trips_completed": self.trip_complete,
-			"extensions": self.trip_complete and (self.miles == 1000),
+			"extensions": self.trip_complete and (self.mileage == 1000),
 			"delayed_actions": self.delayed_action,
 			"safe_trips": self.safe_trip,
 			"shutouts": self.shutout,
 			array.append(s.rjust(19) + ' ... ' + str(points).rjust(4))
 
 		score(self.mileage(), str(self.mileage()), "miles")
-		if as_if_won or (total in {700, 1000}):
+		if as_if_won or (total == (1000 if hand.extended else 700)):
 			score(400, "trip complete")
-			if total > 700:
+			if total == 1000:
 				score(200, "extension")
 			if not len(hand.draw_pile):
 				score(300, "delayed action")
 			score(safeties * 100, safeties, "safet" + ("y" if safeties == 1 else "ies"))
 			if safeties == 4:
 				score(300, "all four safeties")
-			coupes = len(self.coups_fourres)
-			if coupes:
-				score(coupes * 300, coupes, "coup{s} fourré{s}".format(s="" if coupes == 1 else "s"))
+			coups = len(self.coups_fourres)
+			if coups:
+				score(coups * 300, coups, "coup{s} fourré{s}".format(s="" if coups == 1 else "s"))
 		return self.ScoreTuple(total, array)
 
 
 			winner.series.shutouts += 1
 
 		for p in series.players:
-			p.game.score += p.hand.calculate_score().score
-		
+			score = Score(p)
+			score2 = p.hand.calculate_score()
+			assert score.total == score2.score, "score " + str(score) + " != score2 " + str(score2)
+			p.game.score += score.total
+
 		return winner
 
 	ScoresResult = namedtuple("ScoresResult", "winner lost_by_points")
 		winner = None
 		divider = "--------------------------------"
 		for p in series.players:
-			score, comments = p.hand.calculate_score(as_if_won)
-			comments = ["    " + x for x in comments]
+			score = Score(p, as_if_won)
+			comments = score.render()
+			score = score.total
+			comments = ["    " + x[1] for x in comments]
 			comments.insert(0, divider)
 			comments.insert(0, p.name)
 			totals = [divider]
 			strings = [player.name.ljust(8)[:8]]
 			add = strings.append
 
-			score = player.hand.calculate_score()[0]
+			score = Score(player).total
 
 			add(" ")
 			add(str(score + player.game.score).rjust(5))
 		if winner:
 			add(winner.name + " wins the hand!")
 			loser = winner.others[0]
-			lost_by_points = winner.hand.calculate_score() < loser.hand.calculate_score()
+			lost_by_points = Score(winner).total < Score(loser).total
 			if lost_by_points:
 				add("(Which is weird, because " + loser.name + " got more points.)")
 			if not loser.hand.mileage():