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


Python DataManager.insertGameLogIntoDb方法代码示例

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


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

示例1: playGames

# 需要导入模块: from DataManager import DataManager [as 别名]
# 或者: from DataManager.DataManager import insertGameLogIntoDb [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' )
开发者ID:Shadhopson,项目名称:Friendship-for-Life,代码行数:47,代码来源:GameManager.py


注:本文中的DataManager.DataManager.insertGameLogIntoDb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。