Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed solution for Game of Life kata #42

Closed
garora opened this issue Mar 27, 2018 · 2 comments
Closed

Proposed solution for Game of Life kata #42

garora opened this issue Mar 27, 2018 · 2 comments
Assignees

Comments

@garora
Copy link
Owner

garora commented Mar 27, 2018

PR #28 is providing a solution for 4 X 8 grid. But we need something generic.
Refer to this code: Game of Life for an idea. Implement and make changes to your code before creating a new PR .

@garora
Copy link
Owner Author

garora commented Mar 27, 2018

Current solution for 4 X 8 grid is:

`namespace TDD_Katas_project.TheGameOfLifeKata
{
public class GameOfLife
{
public GameOfLife()
{
for (i = 0; i < 4; i++)
{
for (j = 0; j < 8; j++)
{
if (i == 0)
k = i;
else
k = i - 1;
if (j == 0)
l = j;
else
l = j - 1;
for (int m = k; m <= i + 1 && m < 4; m++)
{
for (int n = l; n <= j + 1 && n < 8; n++)
{
if (input2D[m, n] == "" && (m != i || n != j))
NoOfLiveN[i, j]++;
}
}
}
}
}
int i = 0, j = 0, k, l;
public string[,] input2D = new string[4, 8] { { ".", ".", ".", ".", ".", ".", ".", "." }, { ".", ".", ".", ".", "
", ".", ".", "." }, { ".", ".", ".", "", "", ".", ".", "." }, { ".", ".", ".", ".", ".", ".", ".", "." } };
public string[,] output2D = new string[4, 8] { { "", "", "", "", "", "", "", "" }, { "", "", "", "", "", "", "", "" }, { "", "", "", "", "", "", "", "" }, { "", "", "", "", "", "", "", "" } };

    int[,] NoOfLiveN = new int[4, 8] { { 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, 0, 0, 0, 0 } };
    void inputPattern()
    {
        //Console.WriteLine("input");
        //Console.WriteLine("give a input in this format * indicates live cell, . indicates dead cell");
        for (i = 0; i < 4; i++)
        {
            for (j = 0; j < 8; j++)
            {

                //Console.Write(input2D[i, j]);
            }
            // Console.WriteLine();
        }
    }
    public void printOutput()
    {
        
        for (i = 0; i < 4; i++)
        {
            for (j = 0; j < 8; j++)
            {
                if (input2D[i, j] == "*" && (NoOfLiveN[i, j] > 3 || NoOfLiveN[i, j] < 2))
                    output2D[i, j] = output2D[i, j] + ".";

                else if (input2D[i, j] == "*" && NoOfLiveN[i, j] == (2 | 3))
                    output2D[i, j] = output2D[i, j] + "*";

                else if (input2D[i, j] == "." && NoOfLiveN[i, j] == 3)
                    output2D[i, j] = output2D[i, j] + "*";
                else
                    output2D[i, j] = output2D[i, j] + input2D[i, j];

                Console.Write(output2D[i, j]);
            }
            Console.WriteLine();
        }

    }
}

}
`

@garora garora self-assigned this Apr 15, 2018
@garora
Copy link
Owner Author

garora commented Mar 14, 2021

Closing the issue, shall take it in future. If anyone can take it, create a new task and implement.

@garora garora closed this as completed Mar 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant