Jump to content

simple vex code for Conway's game of life


regart

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 adj[] = array();
int alive = 0;

adj = nearpoints(0, @P, 10, 9);
removeindex(adj, 0);
i[]@adj = adj;

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

    alive = 0;
    
    for(int p = 0; p < len(adj); p++){
        int iter = 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

Link to comment
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

 

vex_gameOfLife + solver.hiplc

GameOfLife_F.hiplc

Edited by flcc
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...