Dojo #28: Jogo da Vida Exemplo de uso de Tabela de Decisões para o Kata Jogo da Vida realizado em 12 de agosto de 2009 na Reunião #28 do Dojo Rio
1. Problema

You start with a two dimensional grid of cells, where each cell is either alive or dead. In this version of the problem, the grid is finite, and no life can exist off the edges. When calculating the next generation of the grid, follow these rules:

  1. Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
  2. Any live cell with more than three live neighbours dies, as if by overcrowding.
  3. Any live cell with two or three live neighbours lives on to the next generation.
  4. Any dead cell with exactly three live neighbours becomes a live cell.

You should write a program that can accept an arbitrary grid of cells, and will output a similar grid showing the next generation.

2. Solução Repetir para cada célula:
tem 3 vizinhos ou
(está vivo e tem 2 vizinhos):  fica vivo
3. Solução usando Tabela de Decisões Repetir para cada linha e coluna:
Está vivo?
| Tem menos de 2 vizinhos?
| | Tem mais de 3 vizinhos?
| | | Tem 2 vizinhos?
| | | | Tem 3 vizinhos?
1 1 - - - * célula = 0 -- morre
1 - 1 - - * célula = 0 -- morre
1 - - 1 - * célula = 1 -- fica vivo
1 - - - 1 * célula = 1 -- fica vivo
0 - - - 1 * célula = 1 -- fica vivo
4. Simplificando a Tabela de Decisões Repetir para cada linha e coluna:
Está vivo?
| Tem 2 vizinhos?
| | Tem 3 vizinhos?
- - 1
1 1 -  * célula = 1 -- fica vivo
5. Esticando a prosa O componente "gerar" transforma a matriz "grid" na matriz "next"
gerar (grid(linhas, colunas)) => next(linhas, colunas):
Repetir para cada linha e coluna:
Está vivo?
| Tem menos de 2 vizinhos?
| | Tem mais de 3 vizinhos?
| | | Tem 2 vizinhos?
| | | | Tem 3 vizinhos?
1 1 - - - * célula = 0 -- morre
1 - 1 - - * célula = 0 -- morre
1 - - 1 - * célula = 1 -- fica vivo
1 - - - 1 * célula = 1 -- fica vivo
0 - - - 1 * célula = 1 -- fica vivo
---- regras impossíveis
- 1 1 -  -
- 1 - 1  -
- 1 - - 1
- - 1 1 -
- - 1 - 1
- - - 1 1
- 0 0 0 0 * ?!
---- regras que faltam
0 1 0 0 0 * célula = 0 -- fica igual
0 0 1 0 0 * célula = 0 -- fica igual
0 0 0 1 0 * célula = 0 -- fica igual
Arquivo origem: DojoJogoVida.xml.