diff --git a/tasks.cpp b/tasks.cpp new file mode 100644 index 0000000000000000000000000000000000000000..de7c66fb113633e71c16f2a175307de3e424d0ef --- /dev/null +++ b/tasks.cpp @@ -0,0 +1,105 @@ +#include "game_of_life.hpp" +#include <iostream.h> +#include <fstream.h> + +int x; +int y; +int number_of_neighbours; + +// NOTE: +// For the bool value, TRUE equals ALIVE, FALSE equals DEAD + +// Task 1: Implement the rule one function +void rule_one(int x, int y) +{ + // Rule one - Live cell with less than two neighbours equals dead cell + if (gol::num_of_neigbours(int x, int y) < 2) + { + gol::set_cell(int x, int y, bool false); // DEAD + } +} +// Task 2: Implement the rule two function +void rule_two(int x, int y) +{ + // Rule two - Live cell with two or three neighbours equals live cell + if (gol::num_of_neigbours(int x, int y)) || (gol::num_of_neigbours(int x, int y) = 3) + { + gol::set_cell(int x, int y, bool true); // ALIVE + } +} +// Task 3: Define and implement the rule three function +void rule_three(int x, int y) +{ + // Rule three - Live cell with more than three neighbours equals dead cell + if (gol::num_of_neigbours(int x, int y) > 3) + { + gol::set_cell(int x, int y, bool false); // DEAD + } +} + +// Task 4: Define and implement the rule four function +void rule_four(int x, int y) +{ + // Rule four - A dead cell with exactly three neighbours equals live cell + if (gol::num_of_neigbours(int x, int y) = 3) + { + gol::set_cell(int x, int y, bool true); // ALIVE + } +} + +// Task 5: Implement pseudocode +void pseudo_program_code() +{ + gol::init_game_of_life(std::string "game_of_life_generated.gif"); + gol::seed_grid(); + gol::write_frame(); + + int number_of_frames = 100; + for (int a = 0; a < number_of_frames; a++) + { + for (int b = 0; b < dimension_x; b++) + { + for (int c = 0; c < dimension_y; c++) + { + rule_one(x, y); + rule_two(x, y); + rule_three(x, y); + rule_four(x, y); + } + } + } +} + +// Task 6: Program your own game of life pattern thingy +void main_program_code() +{ + gol::init_game_of_life(std::string "game_of_life_generated.gif"); + gol::seed_grid(); + gol::write_frame(); + + int number_of_frames = 100; + for (int a = 0; a < number_of_frames; a++) + { + for (int b = 0; b < dimension_x; b++) + { + for (int c = 0; c < dimension_y; c++) + { + rule_one(x, y); + rule_two(x, y); + rule_three(x, y); + rule_four(x, y); + } + } + } +} + +int main(){ + gol::run_gol(rule_one,rule_two,rule_three,rule_four); + + // Task 5: Using the functions available in game_of_life.hpp and + // the pseudocode in worksheet 4, implement the main program code to + // traverse the grid, apply your functions and generate the Gif + //See this projects readme for details on the gol library. + + return 0; +}