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


Python GameOfLife.tick方法代码示例

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


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

示例1: test_tick_with_one_birth

# 需要导入模块: from game_of_life import GameOfLife [as 别名]
# 或者: from game_of_life.GameOfLife import tick [as 别名]
 def test_tick_with_one_birth(self):
     seed = set([(1, 0), (2, 2), (0, 1)])
     game = GameOfLife(seed)
     
     game.tick()
     
     self.assertEqual(game.alive_cells, set([(1, 1)]))
开发者ID:ealvarez,项目名称:Katas,代码行数:9,代码来源:game_of_life_tests.py

示例2: test_tick_with_one_death

# 需要导入模块: from game_of_life import GameOfLife [as 别名]
# 或者: from game_of_life.GameOfLife import tick [as 别名]
 def test_tick_with_one_death(self):
     seed = set([(0,0)])
     game = GameOfLife(seed)
     
     game.tick()
     
     self.assertEqual(game.alive_cells, set())
开发者ID:ealvarez,项目名称:Katas,代码行数:9,代码来源:game_of_life_tests.py

示例3: test_tick_with_all_survivors

# 需要导入模块: from game_of_life import GameOfLife [as 别名]
# 或者: from game_of_life.GameOfLife import tick [as 别名]
 def test_tick_with_all_survivors(self):
     
     seed = set([(1, 0), (2, 0), (1, 1), (2, 1)])
     game = GameOfLife(seed)
     
     game.tick()
     
     self.assertEqual(game.alive_cells, seed)
开发者ID:ealvarez,项目名称:Katas,代码行数:10,代码来源:game_of_life_tests.py

示例4: test_tick

# 需要导入模块: from game_of_life import GameOfLife [as 别名]
# 或者: from game_of_life.GameOfLife import tick [as 别名]
 def test_tick(self):
     
     seed = set()
     game = GameOfLife(seed)
     
     self.assertEqual(game.tick(), set())
开发者ID:ealvarez,项目名称:Katas,代码行数:8,代码来源:game_of_life_tests.py

示例5: GameOfLife

# 需要导入模块: from game_of_life import GameOfLife [as 别名]
# 或者: from game_of_life.GameOfLife import tick [as 别名]
from game_of_life import GameOfLife

life = GameOfLife()

for generation in range(5):
    print "Generation %d" % generation
    life.prettyPrint()
    life.tick()
开发者ID:zgthompson,项目名称:fa14,代码行数:10,代码来源:game_of_life_test.py

示例6: GameOfLifeGui

# 需要导入模块: from game_of_life import GameOfLife [as 别名]
# 或者: from game_of_life.GameOfLife import tick [as 别名]
class GameOfLifeGui(plt.Axes):
    def __init__(self, cube=None,
                 interactive=True,
                 view=(0, 0, 10),
                 fig=None, rect=[0, 0.16, 1, 0.84],
                 max_ticks=100,
                 simulation_interval_msecs=500,
                 callback=None,
                 **kwargs):
        # Game of Life simulation controls.
        self.t = 0
        self._max_ticks = max_ticks
        self._simulation_interval_msecs = simulation_interval_msecs
        self._init_simulation()

        # Optional call-back that receives the cube state whenever it is updated.
        self.callback = callback
        if cube is None:
            self.cube = Cube(3)
        elif isinstance(cube, Cube):
            self.cube = cube
        else:
            self.cube = Cube(cube)

        self._view = view
        self._start_rot = Quaternion.from_v_theta((1, -1, 0),
                                                  - np.pi / 6)

        if fig is None:
            fig = plt.gcf()

        # disable default key press events
        callbacks = fig.canvas.callbacks.callbacks
        del callbacks['key_press_event']

        # add some defaults, and draw axes
        kwargs.update(dict(aspect=kwargs.get('aspect', 'equal'),
                           xlim=kwargs.get('xlim', (-2.0, 2.0)),
                           ylim=kwargs.get('ylim', (-2.0, 2.0)),
                           frameon=kwargs.get('frameon', False),
                           xticks=kwargs.get('xticks', []),
                           yticks=kwargs.get('yticks', [])))
        super(GameOfLifeGui, self).__init__(fig, rect, **kwargs)
        self.xaxis.set_major_formatter(plt.NullFormatter())
        self.yaxis.set_major_formatter(plt.NullFormatter())

        self._start_xlim = kwargs['xlim']
        self._start_ylim = kwargs['ylim']

        # Define movement for up/down arrows or up/down mouse movement
        self._ax_UD = (1, 0, 0)
        self._step_UD = 0.01

        # Define movement for left/right arrows or left/right mouse movement
        self._ax_LR = (0, -1, 0)
        self._step_LR = 0.01

        self._ax_LR_alt = (0, 0, 1)

        # Internal state variable
        self._active = False  # true when mouse is over axes
        self._button1 = False  # true when button 1 is pressed
        self._button2 = False  # true when button 2 is pressed
        self._event_xy = None  # store xy position of mouse event
        self._shift = False  # shift key pressed
        self._digit_flags = np.zeros(10, dtype=bool)  # digits 0-9 pressed

        self._current_rot = self._start_rot  # current rotation state
        self._face_polys = None
        self._sticker_polys = None

        self._draw_cube()
        self._execute_cube_callback()

        # connect some GUI events
        self.figure.canvas.mpl_connect('button_press_event',
                                       self._mouse_press)
        self.figure.canvas.mpl_connect('button_release_event',
                                       self._mouse_release)
        self.figure.canvas.mpl_connect('motion_notify_event',
                                       self._mouse_motion)
        self.figure.canvas.mpl_connect('key_press_event',
                                       self._key_press)
        self.figure.canvas.mpl_connect('key_release_event',
                                       self._key_release)
        self._simulation_id = None
        self.figure.canvas.mpl_connect('draw_event',
                                       self._start_simulation_timer)
        self._initialize_widgets()

        # write some instructions
        self.figure.text(0.05, 0.05,
                         "Mouse/arrow keys adjust view\n"
                         "Up/Down keys to adjust simulation speed",
                         size=10)

    def _initialize_widgets(self):
        self._ax_quit = self.figure.add_axes([0.8, 0.05, 0.15, 0.075])
        self._btn_quit = widgets.Button(self._ax_quit, 'Quit')
        self._btn_quit.on_clicked(self._quit)
#.........这里部分代码省略.........
开发者ID:johan--,项目名称:rubik-1,代码行数:103,代码来源:cube_game_of_life.py


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