1/20/2024 0 Comments Conways game of life in cI would like to take this program to the next level and have it so that the consectuive U's interact with one another, much in the same manner conway's game of life operates. Std::srand( std::time( nullptr) ) // initialise the legacy rng Set_pattern( array, '1' ) // set the pattern using '1' and the bottom line of the U for( std::size_t j = 0 j <= width ++j )įill( array, '0' ) // fill with all '0' place the two vertical lines for( std::size_t i = 0 i < (height-1) ++i )Īrray = array = pattern_char Std::size_t y = std::rand() % (NCOLS/2-MIN_SZ) Std::size_t x = std::rand() % (NROWS/2-MIN_SZ) choose a random location for the top left corner of the U random width and height of the 'U' (adjust as required) const std::size_t height = std::rand() % (NROWS/2) + MIN_SZ Ĭonst std::size_t width = std::rand() % (NCOLS/2) + MIN_SZ set a random U pattern at a (reasonably) random location void set_pattern( array_type& array, char pattern_char ) Void fill( array_type& array, char fill_char )įor( auto& row : array ) // for each row in the array for( char& c : row ) // for each character in the row // for( const auto& row : array ) // for each row in the arrayįor( char c : row ) std::cout << c // print each character i the row Void print( const array_type& array ) // note: array is passed by reference array_type is just another name for the type of the NROWSxNCOLS array of char using array_type = char #include #include #include const std::size_t NROWS = 30 Tldr, I want to make a "U" made of 1's appear randomly in a box of zeros.Ĭout << "lay - Press 'P' to play." << endl I posted the functions I have so far above, it's not much but it's what I would like it to look like in the long run. Any small push in the right direction or hint would help, thank you in advance and I'm looking forward to learning more from you all and this website. I tried watching a few youtube videos about it however I was not able to translate them properly to this code. I just don't know how to make it so that it appears randomly, I tried making it a print where I just cout the "life" however I would like to make it a 2d array since when I tried to print it would not work. and the "life" that I want to insert is a "U" made of ones in a box of zeros. I have used the rand() function before in a smaller, simpler program. [Hi all, I am brand new to programming but I am having trouble displaying a 2d array and inserting a character in a random location, which is the basic function of conway's game of life.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |