Programming Assignment

Pages: 12
Hey guys I'm currently a freshman in college and I really really need help doing this particular coding assignment called the "Game of Life" is anyone willing to help me? I'm kinda desperate right now. The course's instructor, and I'm not exaggerating one bit, just walks into the classroom and reads PowerPoints of the book all class and gives ZERO help and input for the huge programming assignments she throws at us. If anyone is willing to help please reply with your email and I'll get back to you with the assignment's PDF and what not. PLEASE I'm so frustrated right now its unreal.
Last edited on
If anyone is willing to help please reply with your email and I'll get back to you with the assignment's PDF and

I can help you and I will give my email.

My email address : nanamikohana@gmail.com
Hey Mantorr22 I emailed you :)
I strongly suggest that you ask for help publicly. This helps ensure the quality of the information you're getting (since it's usually examined by multiple people), and it makes the solution to your problem and the related discussion available to others who have the same issue.

If the offer is made, do not pay for help.
Last edited on
Thanks for your input mbozzi! I guess I can start posting on the forum instead of privately. Were you here to help me out a bit or to just give me a tip on forums?
Depending on what you ask me to do, I can probably help. :)
Well here is the problem, I don't even know what to ask because I don't even know where to begin with this assignment. Is there any way I can attatch a PDF to this forum or something? And to clarify, I'm not asking anyone to do my assignment at all! Just looking for a head start or some sort of walkthrough in the beginning so that I can understand it fully
Is there any way I can attach a PDF


Unfortunately, no. Is the assignment mostly text? If so, just copy-paste it.

Otherwise, do you have a file-sharing account somewhere? e.g., https://dropbox.com/ ?

If all else fails you can e-mail me the document and I will host it. But I prefer not to post my email-address publicly on forums like this.
Programming Assignment 1: Game of Life

The objective of this programming assignment is to design and implement what is known as the “Game of Life”, conceptualized by the British mathematician John Horton Conway in 1970 to simulate the evolution patterns in a population of living organisms.



The game board is seeded with an initial population pattern, and then evolves based on the set of rules defining when a cell dies or is born into life. A cell’s life cycle depends on the state of its neighboring cells.



The game has no players - a user interacts with the “Game of Life” by creating an initial configuration and then observes how it unfolds. Some already known initial patterns have interesting predictable properties – you might discover a new one!



The implementation will only utilize the C++ programming concepts covered by pre-requisite courses. We will take an iterative approach; walk through the phases of specification, design and implementation.



Task #1 - Preparation
Please familiarize yourself with the topic by watching the following video:


https://www.youtube.com/watch?v=CgOcEZinQ2I (Links to an external site.)




Then read the description of the game – please note the rules of life, as this is what this assignment will attempt to implement:

https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life (Links to an external site.)



And here is an interactive demonstration – click the “next” button to watch how a pattern evolves. Your implementation will also need to display a new generation of the game board, but only using a simple character based (console) type of a display

http://www.bitstorm.org/gameoflife (Links to an external site.)





Task #2 - Specification
We will discuss the game specification in class. What functionality (encapsulated in the member functions/methods) will be needed to accomplish the goal? Which of those methods will be publically available (API) to invoke and operate the game, and which methods will be private to carry out the internal implementation details?



The specification will then be documented as part of the GameOfLife.h file – the comment section of the file, including the Pre-Conditions and Post-Conditions, followed by methods’ prototypes.



At the end of this part, the .h file will be fully defined, and it is expected that it will be implemented as such. Although many other implementations are possible, it is the requirement of this project to follow this model in order to meet the learning objectives.



Task #3 - Object Oriented Design
Object Oriented design asks to model all significant entities in a problem domain as classes, with appropriate structural relationships between them. We would then have two classes - one corresponding to the game itself (example: GameOfLife_T), and another one corresponding to a cell (example: Cell_T). The GameOfLife class will contain a private structure(s) of Cell_T. The entities will each have a set of responsibilities, reflected in the corresponding member functions/methods.



The GameOfLife_T would have to be able to:

Seed/initialize the game board with
a predefined pattern (from a file)
a randomly generated pattern (alive cells at randomly generated indexes)
Run the game
Execute the rules for every cell in order to generate the next generation of our cell population
Display the next generation matrix
Stop the game (ask a user up front how many generations to display, or ask a user whether to continue every step of the way)


The Cell_T would have to be able to:

Hold its state: value of the ‘state’ member set to true (indicates alive) or false (dead)
Communicate its state (whether it is alive or not)
Die (cell’s state set to false, and the face set to ‘dead’)
Come alive (cell’s state set to true, and the face set to ‘alive’)


Task #4 - Implementation


There are many ways to implement the generation of the “next step/generation” game board, and it will be up to a student to decide. We will discuss the options in class.



The display of the board will be character based, simply accomplished with console output.



--------------------

-----*--------------

----*-*-------------

--------*-----------



Please put your game in Namespace CSCI2312

Deliverables
A zip/archive file named <CSCI2312_PA1_LastName_FirstName.zip> containing:

h header file
cxx implementation file
cxx with main() to instantiate and run the game
txt – configuration file to seed the initial population pattern
Here is the full Pdf document in case anyone wants to read it :
https://drive.google.com/open?id=0B7Gm7CCE_DjZUDUxbHA5THNXNkgyd1FNN0RHSGdrOF9KWHZz
Excellent. Also, here:
http://mbozzi.com/csci2312pa1.pdf

And your code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
Peter Nguyen
Last Date Modified: 6 December 2016
Assignment: Programming Assignment #1
Description: The Game of Life
Status: Prep phase
Met All Requirements: No
*/


#include <iostream>
#include <string>
#include "GameofLife.h"

namespace CSCI2312
{
	using std::string;
	using std::ostream;
	using std::istream;


	Cell::Cell()
	{
		state = false;
	}

	Cell::Cell(bool State)
	{
		
	}

	Cell::~Cell()
	{
	}

	bool Cell::getState() const
	{
		return state;
	}

	void Cell::setState(bool newState)
	{
		state = newState;
	}

	char Cell::getFace() const
	{
		return face;
	}

	
	bool GameOfLife::executeRules(unsigned int countAlive, bool currentState)
	{
		
	}

	void GameOfLife::nextGeneration()
	{
	}

	GameOfLife::GameOfLife()
	{
		for (int x = 0; x < MAX_BOARD; x++)
		{
			
		}
	}

}
Last edited on
Thanks Mantorr22. Here is the .h file my instructor gave me
https://drive.google.com/open?id=0Bz77xd-ohSCrbG0xQVlIY2xtMWs

This .h file is exactly what I have in my program.
Last edited on
So here are my questions:
1. How do i make the board?
2. She speaks of a .txt file that is needed to "seed" the game. How do i do this and what does it look like?

If i can simply make the board, the two dimensional array, it would help me TREMENDOUSLY in doing everything else.
Last edited on
1. The simplest way would be to simply continually reallocate a large block as more space is required on the board. A std::vector should be sufficient for this purpose.

A more advanced solution could use binary space partitioning trees as a space and time optimization, but maybe that's not necessary. If the input will be very small and you are not under time constraints, the simplest way to do this will be to update every single cell on the board, until a live cell would appear past the edge of the board. At that point the board would grow.

2. The game board needs some initial state. The "seed" file provides that initial state.

I would probably use a line-based format until that became untenable, something like this:
--------------------
-----*--------------
----*-*-------------
--------*-----------


A good starting point for creating the board would be to read your "seed file" and generate dimensions from it:
std::vector<std::vector<Cell>> board{};

You can then define a function to read each line of the file, filling in each nested vector with the data from the file. Doing it this way eliminates the need to read the file twice, and allows you to easily report at which point a syntax error occurs in the seed file.
Last edited on
mbozzi i would definitely use a vector as well but i think the requirements for this particular assignment stress that we need to use a 2D array.
1
2
// - What data structure(s) of cells will you use to model and implement the board?
//   This implementation will use static two-dimensional arrays 


Okay, I missed it -- this was buried in the header file, which wasn't posted.

The statement static arrays indicates the simulation doesn't evolve on an infinite board. That makes things simpler.

Objects with static storage duration are zero-intialized first. They can't be defined in a header file, but instead must be defined in exactly one translation unit. For the record, it doesn't make much sense to use a static array in this context.

You should set the arrays to be valid cells in seedBoard().

Header file
1
2
3
class GameOfLife {
  static Cell my_array[rows][cols]; 
}

Source file
 
Cell GameOfLife::my_array[rows][cols] = {{0}};
Last edited on
Hey mbozzi. how do you read in just the quantity of rows from the first column of a .txt file?\
I got the # of columns correctly but idk how to get the number of rows correctly
For an example....

SeedPattern.txt:
00000
00000
00000
00000

row = 4
col = 5

I need the number of rows to correctly make my board!
You'd need to read the whole file and count the number of lines. It's probably not harmful to just read the file twice.
1
2
3
4
5
6
7
std::ifstream strm {"seed-file.txt"};
strm.unsetf(std::ios_base::skipws); 
auto const nlines = std::count(std::istream_iterator<char>(strm),
                               std::istream_iterator<char>(), '\n');
// check the error state of the stream here
// then seek back to the beginning
strm.seekg(0);

Last edited on
I don't understand this code mbozzi. Kinda hard for me to read it.

This is kind of what i did to get the amount of rows.

getline(inputFile, xRow1)
if (xRow1.length() > 1)
{
xRowNum1 = xRow1[0];
}

getline(inputFile, xRow2)
if (xRow2.length() > 1)
{
xRowNum2 = xRow2[0];
}

getline(inputFile, xRow3)
if (xRow3.length() > 1)
{
xRowNum3 = xRow3[0];
}

getline(inputFile, xRow4)
if (xRow4.length() > 1)
{
xRowNum4 = xRow4[0];
}

row = xRowNum1 + xRowNum2 + xRowNum3 + xRowNum4;

it works for this because i only have 4 rows.
But what if i had 50+ rows. I cant possibly do this 50 times. with 50 variables of xRow, xRowNum
yes, that isn't the way.

use a loop and an array, vector, or similar construct capable of holding multiple rows at once.

int index = 0;
while (! inputfile.eof()) //be careful with this. Its just a quick example to make a point
{
getline(inputFile, somevectororarray[index]); //this is array logic, vector is a little diff but same idea
if(somevectororarray[index].length() > 1)
index++; //else don't increment and next time the same index is over-written
}



Last edited on
Pages: 12