本文整理汇总了Python中Engine.run方法的典型用法代码示例。如果您正苦于以下问题:Python Engine.run方法的具体用法?Python Engine.run怎么用?Python Engine.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Engine
的用法示例。
在下文中一共展示了Engine.run方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import Engine [as 别名]
# 或者: from Engine import run [as 别名]
def main():
"""Run the engine and start the game"""
if len(sys.argv) < 3:
print("Usage: multiplegames.py player1,player2(,playerx)? games_per_pairing [config_file]")
sys.exit(0)
players = sys.argv[1].split(",")
rrPlay = abs(int(sys.argv[2]))
if len(players) != 2:
print("Exactly 2 players are required")
sys.exit(0)
# Get config
if len(sys.argv) < 4:
cfg = Config(GlobalConfig.DEFAULT_CFG)
else:
cfg = Config(sys.argv[3])
cfg.data['UI'] = False
cfg.data['STDOUT_LOGGING'] = False
# build player win dictionary
playerWins = {}
for player in players:
if player.strip()in playerWins.keys():
print("Player names must be unique. Clone your player module to play against yourself.")
sys.exit(0)
playerWins[player.strip()] = 0
# round-robin the players
game = 1
# play all pairings the players
while game <= rrPlay:
pairings = []
for pairing in itertools.permutations(playerWins.keys(), 2):
pairings.append(pairing)
random.shuffle(pairings)
for pairing in pairings:
if game <= rrPlay:
print ("Game: %s Pairing: %s" % (game, pairing))
cfg.data['PLAYER_MODULES'] = pairing
s = time.clock()
winningPlayer, valid = Engine.run(cfg)
if winningPlayer != False:
print ("\tWinner: %s" % (cfg.data['PLAYER_MODULES'][winningPlayer - 1]))
playerWins[cfg.data['PLAYER_MODULES'][winningPlayer - 1]] += 1
else:
print ("\tNo winner.")
print ("\tValid players: " + str(valid))
print ("\tTime: %s seconds." % (time.clock() - s))
game += 1
# sort dictionary by wins and display rankings
rank = 1
for item in sorted(playerWins.items(), key=operator.itemgetter(1), reverse=True):
print("Rank", rank, "is player", item[0], "with", item[1], "wins.")
rank += 1
示例2: main
# 需要导入模块: import Engine [as 别名]
# 或者: from Engine import run [as 别名]
def main():
"""Run the engine and start the game"""
sys.setcheckinterval(500)
if len(sys.argv) == 1:
sys.argv.append("cablecar.cfg")
wins = {}
scores = {}
games = abs(int(raw_input("Enter number of games: ")))
# Get config
cfg = Config(sys.argv[1])
cfg.data['UI'] = False
cfg.data['STDOUT_LOGGING'] = False
for game in xrange(1, games + 1):
startTime = time.clock()
winningPlayer, score, eliminated, moves = Engine.run(cfg)
endTime = time.clock()
if len(eliminated) > 0:
print "Players errored: %s" % eliminated
print "Game %s time: %s seconds" % (game, endTime - startTime)
if winningPlayer != []:
for player in winningPlayer:
if player not in wins.keys():
wins[player] = 1
scores[player] = [score[player]]
else:
wins[player] += 1
scores[player].append(score[player])
print "Player %s won the game with %s points!" % (winningPlayer, score)
else:
print "No winner."
for player,wins in wins.iteritems():
print "Player %s won %s times" % (player, wins)
score = 0
for num in scores[player]:
score += num
print "Total Score: %s" % score
示例3: Menu
# 需要导入模块: import Engine [as 别名]
# 或者: from Engine import run [as 别名]
import pygame
pygame.mixer.init(44100, 16, 2, 1024)
pygame.init()
first_state = 'menu'
first_state_parameters = {}
states = {'menu' : Menu([(u"Эргэж орох", 'game', {'new': False}),
(u"Тоглоом эхлүүлэх", 'game', {'new': True}),
(u"Оноо",'score',{'totalScore':0,'edit':False}),
(u"Тохиргоо", [( u"fps", (False, True)),
( u"Хөгжим", (True, False))]),
(u"Тухай",'about',{}),
(u"Гарах", Menu.MENU_QUIT) ]),
'game' : Game(),
'win' : Win(),
'death': Death(),
'score': Score(),
'about': About()}
if __name__ == '__main__':
try:
game = Engine(states,
first_state,
first_state_parameters,
screen_size,
window_title=u"Cyber Boyz Games - Little PyBall Game")
game.run()
except:
pass