Exemplo n.º 1
0
        public void Test3_Graphics()
        {
            GraphPointArray[] cells = new GraphPointArray[0];

            GameOfLifeRules rules = new GameOfLifeRules();

            rules.initialLiveCells     = new PositionInt[] { new PositionInt(5, 5) };
            rules.neighbours_ToSurvive = new int[] { 2, 3 };
            rules.neighbours_ToDie     = new int[] { 0, 1, 4, 5, 6, 7, 8 };
            rules.neighbours_ToCreate  = new int[] { 3 };
            rules.plateSize            = new PositionInt(20, 20);
            GameOfLifePlate plate = new GameOfLifePlate(rules);

            new Thread(() =>
            {
                Graph graph = new Graph(
                    500, 500,
                    1,
                    cells,
                    Color.FromArgb(70, 70, 70),
                    $"",
                    new Size(1, 1),
                    false
                    );
            }).Start();
        }
Exemplo n.º 2
0
        public void Dead_Cell_With_Exactly_Three_Neighbors_Becomes_A_Live_Cell(
            [Values(CellState.Dead)] CellState currentState, [Values(3)] int liveNeighbors)
        {
            CellState newState = GameOfLifeRules.GetNewState(currentState, liveNeighbors);

            Assert.AreEqual(CellState.Alive, newState);
        }
Exemplo n.º 3
0
        public void Dead_Cell_With_More_Than_Three_Neighbors_Stays_Dead(
            [Values(CellState.Dead)] CellState currentState, [Range(4, 8)] int liveNeighbors)
        {
            CellState newState = GameOfLifeRules.GetNewState(currentState, liveNeighbors);

            Assert.AreEqual(CellState.Dead, newState);
        }
Exemplo n.º 4
0
        public void Live_Cell_With_Two_Or_Three_Live_Neighbors_Lives(
            [Values(CellState.Alive)] CellState currentState, [Values(2, 3)] int liveNeighbors)
        {
            CellState newState = GameOfLifeRules.GetNewState(currentState, liveNeighbors);

            Assert.AreEqual(CellState.Alive, newState);
        }
Exemplo n.º 5
0
        public void Live_Cell_With_Fewer_Than_Two_Live_Neighbors_Dies(
            [Values(CellState.Alive)] CellState currentState, [Values(0, 1)] int liveNeighbors)
        {
            CellState newState = GameOfLifeRules.GetNewState(currentState, liveNeighbors);

            Assert.AreEqual(CellState.Dead, newState);
        }
Exemplo n.º 6
0
        public void ShouldReturnDeadIfAliveAnd4OrMoreAliveNeighbours()
        {
            var gameOfLifeRule            = new GameOfLifeRules();
            var deadOrAliveNeighbourCount = new DeadOrAliveNeighboursCount {
                AliveNeighbourCount = 4
            };
            var result = gameOfLifeRule.LifeStatusForNextTick(deadOrAliveNeighbourCount, LifeStatus.Alive);

            Assert.AreEqual(LifeStatus.Dead, result);
        }
Exemplo n.º 7
0
        public void ShouldNotReturnAliveIfAliveAnd2AliveNeighbours()
        {
            var gameOfLifeRule            = new GameOfLifeRules();
            var deadOrAliveNeighbourCount = new DeadOrAliveNeighboursCount {
                AliveNeighbourCount = 2
            };
            var result = gameOfLifeRule.LifeStatusForNextTick(deadOrAliveNeighbourCount, LifeStatus.Alive);

            Assert.AreEqual(LifeStatus.Alive, result);
        }
Exemplo n.º 8
0
        public void AnAliveCellWithTwoOrThreeNeighbors_ShouldResultInALiveCell()
        {
            int numberOfNeighbors = 2;

            Assert.That(GameOfLifeRules.ApplyRules(numberOfNeighbors, State.Alive), Is.EqualTo(State.Alive));

            numberOfNeighbors = 3;

            Assert.That(GameOfLifeRules.ApplyRules(numberOfNeighbors, State.Alive), Is.EqualTo(State.Alive));
        }
Exemplo n.º 9
0
        public void Test1()
        {
            GameOfLifeRules gofr = new GameOfLifeRules();

            //gofr.neighbours_ToBecomeAlive = new PositionInt[] { new PositionInt(1, 1), new PositionInt(0, 1) };
            gofr.initialLiveCells = new PositionInt[] {
                new PositionInt(1, 1),
                new PositionInt(0, 0)
            };
            gofr.neighbours_ToSurvive = new int[] { 2, 3 };
            gofr.neighbours_ToDie     = new int[] { 0, 1, 4, 5, 6, 7, 8 };
            gofr.neighbours_ToCreate  = new int[] { 3 };
            gofr.plateSize            = new PositionInt(20, 20);
            //Console.WriteLine(JsonSerializer.Serialize(gofr));
            Console.WriteLine(JsonConvert.SerializeObject(gofr, Formatting.Indented));
        }
Exemplo n.º 10
0
        public void ProduceNextGeneration1()
        {
            var board          = new Board(4, 4);
            var gameOfLifeRule = new GameOfLifeRules();

            board.SetCellExistence(0, 0, true);
            board.SetCellExistence(2, 0, true);
            board.SetCellExistence(0, 1, true);
            board.SetCellExistence(1, 1, true);
            board.SetCellExistence(2, 1, true);
            board.SetCellExistence(3, 1, true);
            board.SetCellExistence(0, 2, true);
            board.SetCellExistence(1, 2, true);
            board.SetCellExistence(2, 2, true);

            Board nextGeneration = gameOfLifeRule.ProduceNextGeneration(board);

            Assert.IsTrue(nextGeneration.IsAlive(0, 0));
            Assert.IsFalse(nextGeneration.IsAlive(1, 0));
            Assert.IsTrue(nextGeneration.IsAlive(2, 0));
            Assert.IsTrue(nextGeneration.IsAlive(3, 0));

            Assert.IsFalse(nextGeneration.IsAlive(0, 1));
            Assert.IsFalse(nextGeneration.IsAlive(1, 1));
            Assert.IsFalse(nextGeneration.IsAlive(2, 1));
            Assert.IsTrue(nextGeneration.IsAlive(3, 1));

            Assert.IsTrue(nextGeneration.IsAlive(0, 2));
            Assert.IsFalse(nextGeneration.IsAlive(1, 2));
            Assert.IsFalse(nextGeneration.IsAlive(2, 2));
            Assert.IsTrue(nextGeneration.IsAlive(3, 2));

            Assert.IsFalse(nextGeneration.IsAlive(0, 3));
            Assert.IsTrue(nextGeneration.IsAlive(1, 3));
            Assert.IsFalse(nextGeneration.IsAlive(2, 3));
            Assert.IsFalse(nextGeneration.IsAlive(3, 3));
        }
Exemplo n.º 11
0
    // Start is called before the first frame update
    void Start()
    {
        Transform cameraTransform = mainCamera.GetComponent <Transform>();

        cameraTransform.position = new Vector3(SceneX / 2.0f, SceneY / 2.0f, mainCamera.GetComponent <Transform>().position.z);

        CreateAllCells();

        BoxCollider2D boxCollider = GetComponent <BoxCollider2D>();

        boxCollider.offset = new Vector2(SceneX / 2.0f, SceneY / 2.0f);
        boxCollider.size   = new Vector2(SceneX, SceneY);

        gameOfLife = new GameOfLifeRules(gameRules);

        // Invoke("PararelUpdate", this.slider.value);
        buf = new ComputeBuffer(64, sizeof(float), ComputeBufferType.Default);
        Shader.SetGlobalBuffer(Shader.PropertyToID("Result"), buf);
        Shader.SetGlobalInt("WORLD_SIZE_X", 200);
        shader.Dispatch(shader.FindKernel("CSMain"), 1, 1, 1);
        float[] data = new float[64];
        buf.GetData(data);
        print(data[0]);
    }
Exemplo n.º 12
0
 public void WhenIDetermineNextGeneration()
 {
     GameOfLifeRules.SetNextGeneration();
 }
Exemplo n.º 13
0
 public void GivenInitialStateCellWithAliveNeighbours(GenerationState initSatate, int neighbour)
 {
     GameOfLifeRules.SetCurrentGeneration(initSatate, neighbour);
 }
Exemplo n.º 14
0
 public void Initialize()
 {
     gameOfLife = new GameOfLifeRules();
     gameOfLife.InitializeBoard(4, 8);
 }
Exemplo n.º 15
0
        public void AnDeadCellWithExactlyThreeNeighbors_ShouldResultInAnAliveCell()
        {
            int numberOfNeighbors = 3;

            Assert.That(GameOfLifeRules.ApplyRules(numberOfNeighbors, State.Dead), Is.EqualTo(State.Alive));
        }
Exemplo n.º 16
0
        public void ADeadCellWithNoNeighbors_ShouldResultInADeadCell()
        {
            int numberOfNeighbors = 0;

            Assert.That(GameOfLifeRules.ApplyRules(numberOfNeighbors, State.Dead), Is.EqualTo(State.Dead));
        }