Completed
Push — develop ( e322b0...461e3c )
by Barry
02:41
created

CCA::setSeed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Barryvanveen\CCA;
4
5
class CCA
6
{
7
    /** @var Config */
8
    protected $config;
9
10
    /** @var Grid */
11
    protected $grid;
12
13
    /** @var int */
14
    protected $generation = 0;
15
16 6
    public function __construct(Config $config, Grid $grid)
17
    {
18 6
        $this->config = $config;
19
20 6
        $this->grid = $grid;
21 6
    }
22
23 9
    public function cycle(int $cycles = 1): int
24
    {
25 9
        while ($cycles > 0) {
26 6
            $this->grid->computeNextState();
27
28 6
            $this->grid->setNextState();
29
30 6
            $this->generation++;
31
32 6
            $cycles--;
33
        }
34
35 9
        return $this->generation;
36
    }
37
38 3
    public function getState(): State
39
    {
40 3
        return new State($this->grid);
41
    }
42
43 3
    public function printCells()
44
    {
45 3
        printf("Cells at generation %d:\n", $this->generation);
46
47 3
        printf("%s", $this->grid);
48 3
    }
49
}
50