# simple vex code for Conway's game of life

## Recommended Posts

Hi there,

I'm quite new to vex and try to build a simple loop to implement the set of rules of the "game of life" by Conway.

The code seems to work for the first iteration, but then stops working as I would expect.

In my example I use a grid with 5 points to be having a attrib value of 1, which is called

`i@life`

the others are set to 0.

This goes into a point wrangle:

```int count = chi("count");

int life = i@life;

int alive = 0;

adj = nearpoints(0, @P, 10, 9);

for(int i = 0; i < count; i++){

alive = 0;

for(int p = 0; p < len(adj); p++){
alive += point(0, "life", iter);
}

if(life == 1){
if(alive < 2 || alive == 8) life = 0;
}
else if(alive == 3) life = 1;

i@life = life;

}```

I would very much apprecciate any help on that!

vex_gameOfLife.hiplc

##### Share on other sites

You need to use a solver sop. Houdini don't keep "global" variables overtime. It's why you need a solver.
I've put your wrangle in a solver and it's do something but more like an infection. Don't know if it's the behavior you expect.
I've also give it a try some time ago, the file is attached. Not perfect and stop working at frame 55. No idea why.

A very good explanation of the solver sop here.
https://www.tokeru.com/cgwiki/index.php?title=The_solver_sop
If you're new to houdini this site is a must see.

It as also a simple game of life example.
https://www.tokeru.com/cgwiki/index.php?title=HoudiniVex#Solver_sop_and_wrangles_for_simulation

Edited by flcc

##### Share on other sites

Thank you Fred!

within a sop solver it works fine!
I don't get though, why it wouldn't work without it just with the loop.

And thank you for the links, they are very useful!

Edited by regart

##### Share on other sites

Read the first bit on that solver sop page, it explains it.

## Create an account

Register a new account