15.12.2022 Views

Python Eficaz

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

grid = Grid(5, 9)

grid.assign(0, 3, ALIVE)

# ...

print(grid)

>>>

---*-----

----*----

--***----

---------

---------

Agora, posso avançar a grade no tempo, uma geração por vez. Como podemos

notar, o glider move-se em diagonal, para baixo e para a direita. Esse

comportamento é ditado exclusivamente pelo seu formato e pelas regras simples

da função game_logic.

class ColumnPrinter(object):

# ...

columns = ColumnPrinter()

sim = simulate(grid.height, grid.width)

for i in range(5):

columns.append(str(grid))

grid = live_a_generation(grid, sim)

print(columns)

>>>

0 | 1 | 2 | 3 | 4

---*----- | --------- | --------- | --------- | ---------

----*---- | --*-*---- | ----*---- | ---*----- | ----*----

--***---- | ---**---- | --*-*---- | ----**--- | -----*---

--------- | ---*----- | ---**---- | ---**---- | ---***---

--------- | --------- | --------- | --------- | ---------

A melhor característica desse tipo de implementação é que podemos mudar a

www.full-ebook.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!