當前位置: 首頁>>代碼示例>>Python>>正文


Python Engine.winner方法代碼示例

本文整理匯總了Python中Engine.Engine.winner方法的典型用法代碼示例。如果您正苦於以下問題:Python Engine.winner方法的具體用法?Python Engine.winner怎麽用?Python Engine.winner使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Engine.Engine的用法示例。


在下文中一共展示了Engine.winner方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from Engine import Engine [as 別名]
# 或者: from Engine.Engine import winner [as 別名]
def main(arguments):
	if len(arguments) > 4:
		print "Sorry, there were too many arguments."
		print "You only need to include the number of rows, columns and the required length to win."
		print "In that order."
		return 0		
	elif len(arguments) < 4:
		print "Sorry, there were not enough arguments"
		print "You need to include number of rows, columns and the required length to win the game."
		print "In that order."
		return 0

	try:
		num_rows = int(arguments[1])
		num_cols = int(arguments[2])
		length_to_win = int(arguments[3])
	except ValueError:
		print "Please input only numbers"
		return 0

	print "Welcome to Connect 4 in python!"
	load_or_save = str(raw_input("Would you like to continue your old game? Yes or no? :"))
	if load_or_save.lower() == 'yes':
		board = Board(0,0)
		board.load_board()
	else:
		board = Board(num_rows, num_cols)
		board.create_board()
	engine = Engine(num_rows, num_cols, length_to_win, board)
	board.print_board()
	while(1):
		try:
			player_number = int(raw_input("Enter the number of players: "))
			if player_number < 1:
				print "Please use a number larger than 0!"
			else:
				break
		except ValueError:
			print "Please use a number!"
	print "If at any time you would like to save your game, simply type save."
	while (True):
		for player in range(player_number):
			column = -1
			input = raw_input("Pick a column for your token player %d: " % (player))
			if input.lower() == 'save':
				board.save_board()
				print "Your game has been saved."
				return 0
				break
			try:
				column = int(input)
				print engine.place_token(column, player)
			except ValueError:
				print "You didn't save or use an acceptable number. You're turn is over."
			board.print_board()
			if engine.winner() != -1:
				print "Congratulations player %d!!\nYou won conncect 4!" %(player)
				return 0
開發者ID:BenCommet,項目名稱:connect4_python,代碼行數:60,代碼來源:python_connect4.py


注:本文中的Engine.Engine.winner方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。