How to use the ppb.WIN function in ppb

To help you get started, we’ve selected a few ppb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GamesCrafters / GamesmanClassic / misc / ppb / 10-to-0.py View on Github external
# if current position is game over state
	if game_over(p):
		CACHE[p] = ppb.LOSE
		REMOTE_CACHE[p] = 0
		return (ppb.LOSE, 0)

	# figure out outcomes of next possible moves
	possible_m = generate_moves(p)
	new_p = [do_move(p, m) for m in possible_m]
	outcomes = [solve(np) for np in new_p]
	outcomes_w = [x for x in outcomes if x[0] == 0]
	outcomes_l = [x for x in outcomes if x[0] == 1]

	# if losing state exists for opposing player
	if outcomes_l:
		CACHE[p] = ppb.WIN
		REMOTE_CACHE[p] = 1 + min(outcomes_l, key=lambda x: x[1])[1]
		return (CACHE[p], REMOTE_CACHE[p])

	CACHE[p] = ppb.LOSE
	REMOTE_CACHE[p] = 1 + max(outcomes_w, key=lambda x: x[1])[1]
	return (CACHE[p], REMOTE_CACHE[p])

ppb

An Event Driven Python Game Engine

Artistic-2.0
Latest version published 11 months ago

Package Health Score

70 / 100
Full package analysis