本文整理汇总了Python中DataManager.DataManager.closeConnection方法的典型用法代码示例。如果您正苦于以下问题:Python DataManager.closeConnection方法的具体用法?Python DataManager.closeConnection怎么用?Python DataManager.closeConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataManager.DataManager
的用法示例。
在下文中一共展示了DataManager.closeConnection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: playGames
# 需要导入模块: from DataManager import DataManager [as 别名]
# 或者: from DataManager.DataManager import closeConnection [as 别名]
def playGames( pDecisionMaker=None, pPlayerCodes=[], pNumRounds=1000, pOutPath='.' ):
outPath = pOutPath
DataManager.initSettings()
DataManager.settings['gameResultsDbPath'] = "%s/games.db"%(outPath)
DataManager.createGameDb()
game = Game()
if pDecisionMaker != None:
game.decisionMaker = pDecisionMaker
playerCodes = pPlayerCodes
if len(playerCodes) == 0:
for card in game.playerCardDeck:
playerCodes.append( card.code )
playerCodes = sorted(playerCodes)
scores = []
playerScores = {}
DataManager.clearGameLogDb()
for code in playerCodes:
playerScores[code] = []
for j in range(pNumRounds):
if j%10 == 0:
print "%s: Round %d"%(code,j)
game.resetGame()
game.addPlayer( code )
while game.isNextStep():
game.performNextStep( game.decisionMaker.makeDecision( game, game.nextStepAvailableActions() ) )
DataManager.insertGameLogIntoDb(game.gameLog)
scores.append( game.players[0].points() )
playerScores[code].append( game.players[0].points() )
DataManager.closeConnection("gameConn")
line = "Avg Score: %.2f"%( sum(scores) / float(len(scores) ) )
fileOut = open( "%s/results.txt"%(outPath), 'wb' )
fileOut.write( line+'\n' )
print line
for player in sorted(playerScores):
line = "%s Avg Score: %.2f"%(player, sum(playerScores[player]) / float(len(playerScores[player])))
print line
fileOut.write( line+'\n' )