當前位置: 首頁>>代碼示例>>Python>>正文


Python GameOfLife.get_living_count方法代碼示例

本文整理匯總了Python中game_of_life.GameOfLife.get_living_count方法的典型用法代碼示例。如果您正苦於以下問題:Python GameOfLife.get_living_count方法的具體用法?Python GameOfLife.get_living_count怎麽用?Python GameOfLife.get_living_count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在game_of_life.GameOfLife的用法示例。


在下文中一共展示了GameOfLife.get_living_count方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: from game_of_life import GameOfLife [as 別名]
# 或者: from game_of_life.GameOfLife import get_living_count [as 別名]
 def run(self):
     for i in range(0, self.iters):
         coverage = rnd.random()
         gol = GameOflife(50, 50, coverage)
         cycle_detected_flag = False
         grids_saved = {} 
         iterations = 0
         initial_grid_state = str(gol.get_as_tuple())
         living_cells_count = gol.get_living_count()
         all_dead = False
         
         while not cycle_detected_flag and iterations < self.MAX_CYCLES:
             current_grid_state = hash(gol.get_as_tuple())
             if current_grid_state not in grids_saved:
                 grids_saved[current_grid_state] = iterations
                 iterations += 1
             else:
                 cycle_detected_flag = True
                 final_living_cells_count = gol.get_living_count()
                 if final_living_cells_count == 0:
                     all_dead = True
                 entry = Dataset(percent_fill = coverage,
                                 intial_fill = living_cells_count, 
                                 final_fill = final_living_cells_count,
                                 is_empty = all_dead,
                                 generations = iterations,
                                 generation_loop = grids_saved[current_grid_state],
                                 loop_length = iterations - grids_saved[current_grid_state],
                                 initial_generation = initial_grid_state)
                 self.db_session.add(entry)
                 self.db_session.commit()
             gol.run_rules()
         print(self.thread_name, i)
開發者ID:eraserpeel,項目名稱:Game-of-Life,代碼行數:35,代碼來源:main.py


注:本文中的game_of_life.GameOfLife.get_living_count方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。