模拟与设计 - basic studies in computing science.pptVIP

  • 13
  • 0
  • 约8.46千字
  • 约 62页
  • 2016-05-24 发布于山西
  • 举报

模拟与设计 - basic studies in computing science.ppt

模拟与设计 - basic studies in computing science

* * 第三层设计 simOneGame: 整个模拟程序的关键 得分初始化为0 发球方置为A 当本局未结束就循环: 模拟一次发球 修改比赛状态 返回比分 * 第三层设计(续) 结束条件用函数gameOver * 第三层设计(续) 结束条件用函数gameOver def simOneGame(probA, probB): scoreA = 0 scoreB = 0 serving = A while not gameOver(scoreA, scoreB): if serving == A: if random() probA: scoreA = scoreA + 1 else: serving = B else: if random() probB: scoreB = scoreB + 1 else: serving = A return scoreA, scoreB * 第三层设计(续) 函数gameOver def gameOver(a,b): # a and b represent scores for # a racquetball game # RETURNS true if the game is over, false #

文档评论(0)

1亿VIP精品文档

相关文档