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

CCA::cycle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
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