| 14 | using namespace af; |
| 15 | |
| 16 | int main(int, char**) { |
| 17 | try { |
| 18 | static const float h_kernel[] = {1, 1, 1, 1, 0, 1, 1, 1, 1}; |
| 19 | static const int reset = 500; |
| 20 | static const int game_w = 128, game_h = 128; |
| 21 | |
| 22 | af::info(); |
| 23 | |
| 24 | std::cout << "This example demonstrates the Conway's Game of Life " |
| 25 | "using ArrayFire" |
| 26 | << std::endl |
| 27 | << "There are 4 simple rules of Conways's Game of Life" |
| 28 | << std::endl |
| 29 | << "1. Any live cell with fewer than two live neighbours " |
| 30 | "dies, as if caused by under-population." |
| 31 | << std::endl |
| 32 | << "2. Any live cell with two or three live neighbours lives " |
| 33 | "on to the next generation." |
| 34 | << std::endl |
| 35 | << "3. Any live cell with more than three live neighbours " |
| 36 | "dies, as if by overcrowding." |
| 37 | << std::endl |
| 38 | << "4. Any dead cell with exactly three live neighbours " |
| 39 | "becomes a live cell, as if by reproduction." |
| 40 | << std::endl |
| 41 | << "Each white block in the visualization represents 1 alive " |
| 42 | "cell, black space represents dead cells" |
| 43 | << std::endl |
| 44 | << std::endl; |
| 45 | |
| 46 | std::cout |
| 47 | << "The conway_pretty example visualizes all the states in Conway" |
| 48 | << std::endl |
| 49 | << "Red : Cells that have died due to under population" |
| 50 | << std::endl |
| 51 | << "Yellow: Cells that continue to live from previous state" |
| 52 | << std::endl |
| 53 | << "Green : Cells that are new as a result of reproduction" |
| 54 | << std::endl |
| 55 | << "Blue : Cells that have died due to over population" |
| 56 | << std::endl |
| 57 | << std::endl; |
| 58 | |
| 59 | std::cout |
| 60 | << "This examples is throttled so as to be a better visualization" |
| 61 | << std::endl; |
| 62 | |
| 63 | af::Window simpleWindow(512, 512, |
| 64 | "Conway's Game Of Life - Current State"); |
| 65 | af::Window prettyWindow(512, 512, |
| 66 | "Conway's Game Of Life - Visualizing States"); |
| 67 | simpleWindow.setPos(32, 32); |
| 68 | prettyWindow.setPos(512 + 32, 32); |
| 69 | |
| 70 | int frame_count = 0; |
| 71 | |
| 72 | // Initialize the kernel array just once |
| 73 | const af::array kernel(3, 3, h_kernel, afHost); |