当前位置: 首页>>代码示例>>Python>>正文


Python Engine.place_token方法代码示例

本文整理汇总了Python中Engine.Engine.place_token方法的典型用法代码示例。如果您正苦于以下问题:Python Engine.place_token方法的具体用法?Python Engine.place_token怎么用?Python Engine.place_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Engine.Engine的用法示例。


在下文中一共展示了Engine.place_token方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from Engine import Engine [as 别名]
# 或者: from Engine.Engine import place_token [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.place_token方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。