Difference between revisions of "Assorted Algorithm Alliteration"

From CDOT Wiki
Jump to: navigation, search
(Created page with '{{GPU610/DPS915 Index | 20123}} = Assorted Algorithm Alliteration = == Team Members == # [mailto:mddelacruz1@myseneca.ca?subject=GPU610 Mark de la Cruz] # [mailto:elim2@mysene…')
(No difference)

Revision as of 15:12, 5 October 2012


GPU610/DPS915 | Student List | Group and Project Index | Student Resources | Glossary

Assorted Algorithm Alliteration

Team Members

  1. Mark de la Cruz
  2. Edwin Lim
  3. Michael Afidchao
  4. eMail All

Proposal

Game of Life

The Game of Life is a "0 player game" cellular automaton. With an initial configuration, the game uses a set of rules to determine what happens to the life forms from generation to generation. More information can be found at http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

Source code can be found here:

http://www.shodor.org/media/content//petascale/materials/UPModules/exercises/Game_of_Life/GoL_Serial_Source_Files.zip

Profile

These results were taken with an execution of 50000 generations and default settings for the rest of the options.

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  Ts/call  Ts/call  name
 55.82     14.76    14.76                             eval_rules
 41.75     25.80    11.04                             do_draw
  2.23     26.39     0.59                             update_grid
  0.19     26.44     0.05                             copy_bounds
  0.00     26.44     0.00    11025     0.00     0.00  rand_double
  0.00     26.44     0.00        1     0.00     0.00  allocate_grids
  0.00     26.44     0.00        1     0.00     0.00  free_grids
  0.00     26.44     0.00        1     0.00     0.00  init_grids
  0.00     26.44     0.00        1     0.00     0.00  moveWindow
  0.00     26.44     0.00        1     0.00     0.00  parse_args
  0.00     26.44     0.00        1     0.00     0.00  randomize_grid
  0.00     26.44     0.00        1     0.00     0.00  setupWindow
  0.00     26.44     0.00        1     0.00     0.00  write_grid

Code Snippet

/*
        eval_rules()
                Evaluate the rules of Life for each cell; count
                neighbors and update current state accordingly.
*/
void eval_rules (struct life_t * life) {
        int i,j,k,l,neighbors;

        int ncols = life->ncols;
        int nrows = life->nrows;

        int ** grid      = life->grid;
        int ** next_grid = life->next_grid;

        for (i = 1; i <= ncols; i++) {
                for (j = 1; j <= nrows; j++) {
                        neighbors = 0;

                        // count neighbors
                        for (k = i-1; k <= i+1; k++) {
                                for (l = j-1; l <= j+1; l++) {
                                        if (!(k == i && l == j) && grid[k][l] != DEAD)
                                                neighbors++;
                                }
                        }

                        // update state
                        if (neighbors < LOWER_THRESH || neighbors > UPPER_THRESH)
                                next_grid[i][j] = DEAD;
                        else if (grid[i][j] != DEAD || neighbors == SPAWN_THRESH)
                                next_grid[i][j] = grid[i][j]+1;
                }
        }
}


Instructor's Comments