1. 程式人生 > >龍珠激鬥大冒險擲篩子算法

龍珠激鬥大冒險擲篩子算法

code main pri spa blog turn ice end 進行

今天玩兒龍珠激鬥的大冒險時擲篩子的時候想了想擲篩子的算法,自己寫著玩兒。代碼如下:

‘‘‘
    龍珠大冒險擲篩子介紹:
        在地圖中擲篩子
        如果地圖剩余格子數大於6則默認進行十連擲
        十連擲不能超過剩余格子數否則進行最大次數連擲
        如果地圖剩余格子數小於等於6則進行單擲
        如果單次擲篩子結果大於剩余格子數則進入下一張地圖
    輸入:
        剩余格子數
    輸出:
        擲篩子的結果
‘‘‘
import random

def throw_once():
    
return random.randint(1,6) def throw_times(n,cells): ret = [] while n > 0: curr = throw_once() if curr <= cells: ret.append(curr) cells = cells-curr n -= 1 else: return ret else: return ret
def throw_dices(cells): if cells > 6: _ret = throw_times(10,cells) else: _ret = throw_once() return _ret if __name__ == __main__: cells = 33 print(throw_dices(cells))

龍珠激鬥大冒險擲篩子算法