Question

Using c# visual studio Game of Life The Game of Life program assignment follows the material...

Using c# visual studio

Game of Life

The Game of Life program assignment follows the material from Chapters 7 and 8 in your book. There are 2 major focus points for this project:

  • 2-dimensional arrays - This is our first data structure that moves beyond a simple linear list of values. We will expand this and also look at some of the built-in collections in the C# FCL.
  • nested for loops (2 loops, an inner loop and an outer loop) - A natural fit for processing data from a 2 dimensional array, since the data structure is logically similar to a spreadsheet or matrix consisting of rows and columns of storage "cells".
  • The Game of Life is a computational phenomenon invented by British mathematician John Conway circa 1970 to show possibilities of population simulations in a mathematically controlled environment. The original computations were not executed on machines, they were performed using marbles on a game board similar to Go. The results of processing were determined using pencil and paper from one generation to the next. Glad we got us some silicon diodes!
  • Recently, according to the Wikipedia page on Game of Life, a researcher has carried out a GOL simulation to the 6,366,548,773,467,669,985,195,496,000th (6 octillionth) generation of a Turing machine, computed in less than 30 seconds on an Intel Core Duo 2 GHz CPU.
  • The standard Game of Life is symbolized as B3/S23. A cell is Born if it has exactly three neighbors, Survives if it has two or three living neighbors, and dies otherwise.
    • The first number, or list of numbers, is what is required for a dead cell to be born.
    • The second set is the requirement for a live cell to survive to the next generation.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

using System;
  
public class GameOfLife {
  
public static void Main()
{
int M = 10, N = 10;
int[,] grid = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 },
{ 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
Console.WriteLine("Original Generation");
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
if (grid[i,j] == 0)
Console.Write(".");
else
Console.Write("*");
}
Console.WriteLine();
}
Console.WriteLine();
nextGeneration(grid, M, N);
}
static void nextGeneration(int [,]grid,
int M, int N)
{
int[,] future = new int[M,N];
for (int l = 1; l < M - 1; l++)
{
for (int m = 1; m < N - 1; m++)
{
int aliveNeighbours = 0;
for (int i = -1; i <= 1; i++)
for (int j = -1; j <= 1; j++)
aliveNeighbours +=
grid[l + i,m + j];
aliveNeighbours -= grid[l,m];
if ((grid[l,m] == 1) &&
(aliveNeighbours < 2))
future[l,m] = 0;
  
else if ((grid[l,m] == 1) &&
(aliveNeighbours > 3))
future[l,m] = 0;
else if ((grid[l,m] == 0) &&
(aliveNeighbours == 3))
future[l,m] = 1;
else
future[l,m] = grid[l,m];
}
}
  
Console.WriteLine("Next Generation");
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
if (future[i,j] == 0)
Console.Write(".");
else
Console.Write("*");
}
Console.WriteLine();
}
}
}

Add a comment
Know the answer?
Add Answer to:
Using c# visual studio Game of Life The Game of Life program assignment follows the material...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA. Threading the Game of Life Write a Java program to implement the Game of Life,...

    JAVA. Threading the Game of Life Write a Java program to implement the Game of Life, as defined by John Conway: Any live cell with fewer than two live neighbors dies, as if caused by under-population. Any live cell with two or three live neighbors lives on to the next generation. Any live cell with more than three live neighbors dies, as if by overpopulation. Any dead cell with exactly three live neighbors becomes a live cell, as if by...

  • Write this Game of Life program in Java. The Game of Life is a well-known mathematical...

    Write this Game of Life program in Java. The Game of Life is a well-known mathematical game that gives rise to amazingly complex behavior, although it can be specified by a few simple rules. Here are the rules. The game is played on a rectangular board. Each square can be either empty or occupied. At the beginning, you can specify empty and occupied cells using 1's and 0's; then the game runs automatically. In each generation, the next generation is...

  • Write this Game of Life program in Java. The Game of Life is a well-known mathematical...

    Write this Game of Life program in Java. The Game of Life is a well-known mathematical game that gives rise to amazingly complex behavior, although it can be specified by a few simple rules. Here are the rules. The game is played on a rectangular board. Each square can be either empty or occupied. At the beginning, you can specify empty and occupied cells using 1's and 0's; then the game runs automatically. In each generation, the next generation is...

  • I have a question about my assignment. Could you please make program and give me some...

    I have a question about my assignment. Could you please make program and give me some explanation of codes? I need c++ codes. Conway's Game of Life is a game invented by mathematician John Conway in 1970. The rules are as follows: Each cell lives in a cell in a square (make it 10x10) grid. A cell can either be dead or alive. Before you start the game, you need to provide an initial state. You can do this by...

  • I have a question about my assignment. Could you please make program and give me some...

    I have a question about my assignment. Could you please make program and give me some explanation of codes? Conway's Game of Life is a game invented by mathematician John Conway in 1970. The rules are as follows: Each cell lives in a cell in a square (make it 10x10) grid. A cell can either be dead or alive. Before you start the game, you need to provide an initial state. You can do this by randomly setting 20 of...

  • Please use C++, thank you! The life game consists of a board with size of NxN cells and cells are occupied by creatures. Each cell can have at most one creature. The surrounding cells are called the...

    Please use C++, thank you! The life game consists of a board with size of NxN cells and cells are occupied by creatures. Each cell can have at most one creature. The surrounding cells are called the neighbors of this cell Each game state is called "generation". The game progresses from one generation to the next according to the following rules: A creature that has more than 3 neighbors- dies of crowding. Its cell will be empty in the next...

  • I am really struggling with how to approach this program. Conway's Game of life, whereby, 1....

    I am really struggling with how to approach this program. Conway's Game of life, whereby, 1. Any live cell with fewer than two live neighbours dies, as if caused by under-population. 2. Any live cell with two or three live neighbours lives on to the next generation. 3. Any live cell with more than three live neighbours dies, as if by over-population. 4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. Submit...

  • Program in C++ Implement Conway's Game of Life using 2-dimensional arrays. All the tips, tricks, techniques...

    Program in C++ Implement Conway's Game of Life using 2-dimensional arrays. All the tips, tricks, techniques we have been using in class are allowed. Nothing else. The program should read the initial state of the board by reading in "alive" cells from a user input data file. Meaning your program should ask the user the name of the data file. Assume all the other cells are "dead." Make sure to use modular coding techniques. The main program should be pretty...

  • You are going to be implementing the classic computer science simulation, Conway's Game of Life. Conway's...

    You are going to be implementing the classic computer science simulation, Conway's Game of Life. Conway's Life is played on a matrix of cells, kind of like a chess board but theoretically extending infinitely in every direction. Each individual cell in the matrix can either be alive or dead. A live cell in the matrix is shown in our simulation by printing an asterisk (*) to the screen. A dead cell is shown by leaving that area of the matrix...

  • Task: Simulate the growth of a biological population. The Game of Life, invented by John H....

    Task: Simulate the growth of a biological population. The Game of Life, invented by John H. Conway, is supposed to model the genetic laws for birth, survival, and death. Our implementation of the game will use a 2-dimensional array with 12 rows and 12 columns. Each cell of the array will hold either a 1 (an organism is present) or a 0 (no organism there). You will calculate 4 generations of the organisms’ birth, survival, and death. An organism’s neighbors...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT