コード例 #1
0
ファイル: main.py プロジェクト: Lonsdaleiter/Chess
def init():
    global running
    global window
    global clock

    pygame.init()
    running = True
    window = pygame.display.set_mode((config.WIDTH, config.HEIGHT))

    pygame.display.set_caption("Chess")

    clock = pygame.time.Clock()

    drawer.window = window

    board.init(window)
コード例 #2
0
def main():
    print('\nAlephT Ultimate Tic Tac Toe Engine by Geo')
    print('For information about the game type \'info\'')
    board.init()
    board.printb()
    while board.state == 0:
        while (not board.set_pos(1, get_move('X: '))):
            pass
        board.printb()
        if board.state != 0:
            return
        while (not board.set_pos(-1, get_move('O: '))):
            pass
        board.printb()
        if board.state != 0:
            return
コード例 #3
0
ファイル: game.py プロジェクト: drcjar/quantumTTT
def play():
    b = board.init()
    for round in range(1,9):
        b = turn(b)
        board.draw(b)
        c = state.find_cycle(b)
        if c:
            pass
        if state.won(b):
            break
コード例 #4
0
ファイル: game.py プロジェクト: kynan/quantumTTT
def play():
    b = board.init()
    for r in range(9):
        b = turn(r, b)
        board.draw(b)
        c = state.find_cycle(b)
        if c:
            pos, symbol = prompt_resolve(r, c)
            b = state.collapse(b, pos, symbol)
        if state.won(b):
            print "Player %d won!" % playernum(r)
            break
コード例 #5
0
def setgame():
    global mousedown, keydown
    mousedown, keydown = game.mousedown, game.keydown
    board.init(loadfrom='map/example')
    game.register()
コード例 #6
0
def setneweditor():
    global mousedown, keydown
    mousedown, keydown = editor.mousedown, editor.keydown
    board.init()
    editor.register()
コード例 #7
0
def seteditor():
    global mousedown, keydown
    mousedown, keydown = editor.mousedown, editor.keydown
    board.init(loadfrom='map/example')
    editor.register()
コード例 #8
0
ファイル: game.py プロジェクト: hedayaty/snake
def init(gametype):
	global players, items, remplayers
	global ucolors, udevs, devs, colors
	global numbersend, lives, netgame
	global blue, pink, green, red, orange,cyan
	global nlpr, cont

	blue = (0,0,255)
	pink = (255,20,147)
	green =(0,128,0)
	red = (255,0,0)
	orange = (255,165,0)
	cyan= (0,255,255)
	

	if gametype != "join" :
		list = os.listdir("maps")
		list.sort()
		mapname = menu.choose ("Select the map:",\
					[{ "label" : file, "value" : file} for file in list])
		if mapname == None :
			return False

		board.init ("maps/"+ mapname)
		items = {}
	
	# Get Game options
	boolean = [ { "label" : "On", "value": True }, 
							{ "label" : "Off", "value": False } 
						]
	multioptions = [																								\
			{ "description" : "NLPR: ", 																\
				"name" : "nlpr", 																					\
				"options" : boolean,																			\
				"default" : False,																				\
			}, 																													\
			{	"description" : "Continue: ",															\
				"name" : "cont", 																					\
				"options" : boolean,																			\
				"default" : False,																				\
			},																													\
			{ "description" : "End with numbers: ",											\
				"name" : "numbersend",																		\
				"options" : boolean,																			\
				"default" : True,																					\
			},																													\
			{	"description" : "Players: ",															\
				"name" : "nplayers",																			\
				"default" : 2,																						\
				"options" : [ { "label" : str(x), "value" : x} 						\
												for x in range(1,5)												\
										]																							\
			}]

	if gametype == "1p":
		multioptions = []

	options = menu.select ("Select Game Options",										\
			multioptions + 																							\
			[{	"description" : "Lives: ", 															\
					"name" : "lives", 																			\
					"default" : 5,																					\
					"options" : [ { "label" : str(x), "value" : x }					\
						for x in [1, 2, 3, 4, 5, 10, 20, 50, 64, 100, 256]]} 	\
			])
	if options == None:
		return False
	if gametype == "1p":
		nlpr = False
		cont = False
		nplayers = 1
		numbersend = True
	else:
		nlpr = options["nlpr"]["value"]
		cont = options["cont"]["value"]
		nplayers = options["nplayers"]["value"]
		numbersend = options["numbersend"]["value"]
	lives = options["lives"]["value"]

	# Get Players
	ucolors = set()
	udevs = set()
	colors = [blue, pink, green, red, orange, cyan]
	devs = [("Keypad", "keypad"),												\
					("Computer", "ai"), 												\
					("Keyboard (wasd)", "keyboard"),						\
					("Vim Keys (hjkl)", "vim"), 								\
					("Netwrok", "net")													\
					]

	players = []
	netgame = False
	for i in range(nplayers):
		player = getplayer(str(i+1))
		if player == None:
			return None
		players.append(player)

	if netgame:
#		network.startserver()
		for player in players:
			if player.dev == "net":
				if network.waitfor(player) == None:
					network.sendinfo (player, board.dim, board.obstacles)
					return None
			
	renderer.updateboard()
	remplayers = nplayers
	return True
コード例 #9
0
    if sudoku.get(x, y) != 0:  # if cell is not empty
        return solve(sudoku, x + 1, y)  # go to next cell
    else:
        for nr in range(1, 10):  # go through all the options
            if sudoku.canPut(x, y, nr):  # if the nr can be put
                sudoku.set(x, y, nr)  # set value
                solved = solve(sudoku, x + 1, y)  # go to next cell
                if solved:  # if solved
                    return True  # sudoku is solved, return
                else:  # otherwise
                    sudoku.set(x, y, 0)  # make the cell empty again
    # if we went through all the values it's a dead end
    return False  # go back to previous cell


board.init()

help = TextBox(x=board.width + 2, y=1, width=16, height=board.height)
help.message("")

sudoku = readFromFile('test.sdk')
board.show(sudoku)

start = time()
solve(sudoku, 0, 0)
end = time()
board.show(sudoku)

board.end()
print("time = {0}".format(end - start))