Esempio n. 1
0
	def _p_i_win_save(self, depth, mine, opp):
		if depth <= 0: return 0
		save = 0.0
		fsum = 0.0
		for opp_new in range(opp, self.goal):
			f = self.p_opp_gets(opp, opp_new, mine)
			if f > 0:
				fsum += f
				save += f*self.p_i_win(depth-1, mine, mine, opp_new)
		if save > 1:
			m('p_i_win_save(%s) -> ' % ((depth, mine, opp),), save, fsum)
		return save
Esempio n. 2
0
	def play(self, beginner):
		m("----------")
		for p in self.p:
			p.beginGame()
		self.points = [0, 0]
		self.game_turns = [0, 0]
		p = beginner
		while self.turn(p):
			p = (p+1)%2
		m("%s won the game" % self.p[p].__class__.__name__)
		self.turns[p][0] += self.game_turns[0]
		self.turns[p][1] += self.game_turns[1]
		self.games[p] += 1
		return p
Esempio n. 3
0
	def play(self):
		score = 0
		round = 0
		self.p.beginGame()
		while True:
			round += 1
			old_score = score
			self.p.beginTurn(old_score, 0)
			m('BEGIN TURN')
			while self.p.decide():
				x = self.roll()
				if x == 6:
					score = old_score
					break
				self.p.thrown(x)
				score += x
				if score >= self.aim:
					return round
Esempio n. 4
0
	def _decide_(self, old, mine, opp):
		self.prepare_saved(old, opp)
		roll = self.p_i_win_roll(self.depth, old, mine, opp)
		save = self.p_i_win_save(self.depth, mine, opp)
		if abs(roll - save) < 0.001:
			m('close decision %f at %s' % (abs(roll - save), (old, mine, opp)))
		if old == mine and save >= roll:
			m('obviously wrong decision at %s' % ((old, mine, opp),))
			m('(%d -> %d) roll > save == %f > %f' % (old, mine, roll, save))
		return roll > save
Esempio n. 5
0
	def turn(self, p):
		self.game_turns[p] += 1
		player = self.p[p]
		opponent = self.p[(p+1)%2]
		m('begin turn of player "%s"' % player.__class__.__name__)
		m('current scores: %s' % self.points)
		player.beginTurn(self.points[p], self.points[(p+1)%2])
		n = 0
		s = self.points[p]
		while n != 6:
			s += n
			if s >= self.target:
				self.points[p] = s
				return False
			if not player.decide():
				m('SAVE')
				self.points[p] = s
				break
			n = self.roll()
			m('ROLL: %d -> %d' % (n, n+s))
			player.thrown(n)
			opponent.op_threw(n)
		return True
Esempio n. 6
0
	def beginTurn(self, my, o):
		Player.beginTurn(self, my, o)
		self.take = self.targets[self.aim - my]
		m('begin turn: difference to goal is %d so take is %d' % (self.aim - my, self.take))