Example
#{example}"); ipb.editor_values.get('templates')['togglesource'] = new Template(""); ipb.editor_values.get('templates')['toolbar'] = new Template(""); ipb.editor_values.get('templates')['button'] = new Template("
Emoticons
"); // Add smilies into the mix ipb.editor_values.set( 'show_emoticon_link', false ); ipb.editor_values.set( 'bbcodes', $H({"snapback":{"id":"1","title":"Post Snap Back","desc":"This tag displays a little linked image which links back to a post - used when quoting posts from the board. Opens in same window by default.","tag":"snapback","useoption":"0","example":"[snapback]100[/snapback]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"topic":{"id":"5","title":"Topic Link","desc":"This tag provides an easy way to link to a topic","tag":"topic","useoption":"1","example":"[topic=1]Click me![/topic]","switch_option":"0","menu_option_text":"Enter the topic ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"post":{"id":"6","title":"Post Link","desc":"This tag provides an easy way to link to a post.","tag":"post","useoption":"1","example":"[post=1]Click me![/post]","switch_option":"0","menu_option_text":"Enter the Post ID","menu_content_text":"Enter the title for this link","single_tag":"0","optional_option":"0","image":""},"spoiler":{"id":"7","title":"Spoiler","desc":"Spoiler tag","tag":"spoiler","useoption":"0","example":"[spoiler]Some hidden text[/spoiler]","switch_option":"0","menu_option_text":"","menu_content_text":"Enter the text to be masked","single_tag":"0","optional_option":"0","image":""},"acronym":{"id":"8","title":"Acronym","desc":"Allows you to make an acronym that will display a description when moused over","tag":"acronym","useoption":"1","example":"[acronym='Laugh Out Loud']lol[/acronym]","switch_option":"0","menu_option_text":"Enter the description for this acronym (EG: Laugh Out Loud)","menu_content_text":"Enter the acronym (EG: lol)","single_tag":"0","optional_option":"0","image":""},"hr":{"id":"12","title":"Horizontal Rule","desc":"Adds a horizontal rule to separate text","tag":"hr","useoption":"0","example":"[hr]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"1","optional_option":"0","image":""},"php":{"id":"14","title":"PHP Code","desc":"Allows you to enter PHP code into a formatted/highlighted syntax box","tag":"php","useoption":"0","example":"[php]$variable = true;\n\nprint_r($variable);[/php]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"html":{"id":"15","title":"HTML Code","desc":"Allows you to enter formatted/syntax-highlighted HTML code","tag":"html","useoption":"0","example":"[html]\n \n[/html]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"sql":{"id":"16","title":"SQL Code","desc":"Allows you to enter formatted/syntax-highlighted SQL code","tag":"sql","useoption":"0","example":"[sql]SELECT p.*, t.* FROM posts p LEFT JOIN topics t ON t.tid=p.topic_id WHERE t.tid=7[/sql]","switch_option":"0","menu_option_text":"","menu_content_text":"","single_tag":"0","optional_option":"0","image":""},"xml":{"id":"17","title":"XML Code","desc":"Allows you to enter formatted/syntax-highlighted XML code","tag":"xml","useoption":"0","example":"[xml]3 Replies - 44 Views - Last Post: Today, 02:08 AM
#1
Reputation: 0
- Posts: 3
- Joined: Today, 12:41 AM
Posted Today, 12:45 AM
I am writing a program for my programming class and I seem to be having trouble with making sure the cells come to life correctly I think the issue is in my neighbor If statements but cant seem to find it. Here are the instructions my code and the text fileThe game of life is a computer simulation of the life and death events of a population of organisms. This program will determine the life, death, and survival of bacteria from one generation to the next, assuming the starting grid of bacteria is generation zero (0). Each cell has a total of up to 8 neighbors, including the 4 immediately adjacent cells and the 4 diagonal cells. The rules for the creation of each cell in the next generation are as follows:
If the cell is currently empty:
If the cell has exactly three living neighbors, it will come to life in the next generation.
If the cell has any other number of living neighbors, it will remain empty.
If the cell is currently living:
If the cell has one or zero living neighbors, it will die of loneliness in the next generation.
If the cell has four or more living neighbors, it will die of overcrowding in the next generation.
If the cell has two or three neighbors, it will remain living.
All births and deaths occur simultaneously (make sure you don't get this one wrong!).
#include <iostream> #include <fstream> #include <iomanip> using namespace std; const int SIZE = 20; void initGrid(bool life[][SIZE],bool life2[][SIZE]); void readGrid(bool life[][SIZE], bool life2[][SIZE]); void printGrid(bool life[][SIZE]); int livecellNeighbors (bool life[][SIZE],int,int); int deadcellNeighbors (bool life [][SIZE],int,int); void determineNextGen(bool life[][SIZE], bool life2 [][SIZE]); int main() { bool life[SIZE][SIZE]; bool life2[SIZE][SIZE]; readGrid(life,life2); int neighbors; int neighbors2; for (int count = 0; count < 1; count++) { determineNextGen(life, life2); } printGrid(life); printGrid(life2); return 0; } /*------------------------------------------------------- readGrid (and related functions) ---------------------------------------------------------*/ void readGrid(bool life[][SIZE], bool life2[][SIZE]) { ifstream infile("bacteria.txt"); int numBacteria, row, col; initGrid(life,life2); infile >> row >> col; while (infile){ life[row][col] = true; infile >> row >> col; } infile.close(); } void initGrid(bool life[][SIZE],bool life2[][SIZE]) { for (int row = 0; row < SIZE; row++){ for (int col = 0; col < SIZE; col++){ life[row][col] = false; } } for (int row = 0; row < SIZE; row++){ for (int col = 0; col < SIZE; col++){ life2[row][col] = false; } } } void printGrid(bool life[][SIZE]) { cout << " 01234567890123456789" << endl; for (int row = 0; row < SIZE; row++){ cout << setw(2) << row; for (int col = 0; col < SIZE; col++){ if (life[row][col]){ cout << "*"; } else { cout << "!"; } } cout << endl; } } int livecellNeighbors (bool life[SIZE][SIZE],int row,int col) { int neighbors=0; if(life[row][col]== true && life[row][col-1]==true && col-1>=0)//left { neighbors++; } if(life[row][col]== true && life[row+1][col-1]==true && row+1<=20 && col-1>=0)//left bottom { neighbors++; } if(life[row][col]== true && life[row+1][col]==true & row+1<20)//bottom { neighbors++; } if(life[row][col]== true && life[row][col+1]==true && col+1<20)//right { neighbors++; } if(life[row][col]== true && life[row-1][col-1]==true && row-1>=0 && col-1>=0 )//top left { neighbors++; } if(life[row][col]== true && life[row+1][col+1]==true && row+1<3 && col+1<=20)//bottom right { neighbors++; } if(life[row][col]== true && life[row-1][col]==true && row-1>=0)//top { neighbors++; } if(life[row][col]== true && life[row-1][col+1]==true && row-1>=0 && col+1<20)//top right { neighbors++; } return neighbors; } int deadcellNeighbors (bool life [SIZE][SIZE],int row,int col) { int neighbors2=0; if(life[row][col]== false && life[row][col-1]==true && col-1>=0) { neighbors2++; } if(life[row][col]== false && life[row+1][col-1]==true && row+1<=20 && col-1>=0) { neighbors2++; } if(life[row][col]== false && life[row+1][col]==true & row+1<20) { neighbors2++; } if(life[row][col]== false && life[row][col+1]==true && col+1<20) { neighbors2++; } if(life[row][col]== false && life[row-1][col-1]==true && row-1>=0 && col-1>=0 ) { neighbors2++; } if(life[row][col]== false && life[row+1][col+1]==true && row+1<3 && col+1<=20) { neighbors2++; } if(life[row][col]== false && life[row-1][col]==true && row-1>=0) { neighbors2++; } if(life[row][col]== false && life[row-1][col+1]==true && row-1>=0 && col+1<20) { neighbors2++; } return neighbors2; } void determineNextGen(bool life[][SIZE],bool life2 [][SIZE]) { int neighbors=0,neighbors2=0; for (int row=0;row<20;row++) { for (int col=0;col<20;col++) { neighbors=livecellNeighbors(life,row,col); if (neighbors<=1) life2[row][col]=false; if (neighbors>=4) life2[row][col]=false; if (neighbors==2 || neighbors==3) life2[row][col]=true; } } for (int row=0;row<20;row++) { for (int col=0;col<20;col++) { neighbors2=deadcellNeighbors(life,row,col); if (neighbors2==3) life2[row][col]=true; } } /*for (int row=0;row<SIZE;row++) { for (int col=0;col<SIZE;col++) life[row][col]=life2[row][col]; }*/ }
Is This A Good Question/Topic? 0
Replies To: Game of life Issue
#2
Reputation: 473
- Posts: 1,522
- Joined: 20-March 10
Re: Game of life Issue
Posted Today, 01:27 AM
Hi,Well the first errors are on lines 100 and 139
line 100 if(life[row][col]== true && life[row+1][col]==true & row+1<20)//bottom
This should be && shouldn't it
line 139 is the same...
you have variables that you dont use as well.
Regards
Snoopy.
#3
Reputation: 0
- Posts: 3
- Joined: Today, 12:41 AM
Re: Game of life Issue
Posted Today, 01:37 AM
wow i totally missed that but i am still having some issues with the right cells coming to life but i am trying to get a for loop to take the place of all the if statements
#4
Reputation: 0
- Posts: 3
- Joined: Today, 12:41 AM
Re: Game of life Issue
Posted Today, 02:08 AM
so i switched to for loops but I am not sure how to check the edge cells here is my new neighbor count codeint livecellNeighbors (bool life[SIZE][SIZE],int row,int col) { int neighbors=0; if (life[row][col]==true) { for (int i=-1; row+i<=row+1; i++) { for (int c=-1;col+c<=col+1;c++) { if (i==0 && c==0) { } else if (life[row+i][col+c]==true) neighbors++; } } } return neighbors; }
Page 1 of 1
Source: http://www.dreamincode.net/forums/topic/321307-game-of-life-issue/
usher James Holmes Minka Kelly sex tape Colorado shooting Colorado shooting victims aurora Angie Everhart
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.