Completed
Pull Request — master (#7)
by Thijs
02:24
created

TraversalResult   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 28
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 4 1
A onlyEvaluation() 0 4 1
1
<?php
2
3
namespace lucidtaz\minimax\engine;
4
5
use lucidtaz\minimax\game\GameState;
6
7
/**
8
 * An value type to hold an evaluation result and possibly a move
9
 * For tree traversal, technically only the evaluation result is needed.
10
 * However, at the root of the tree we need to know which move was selected to
11
 * produce that result, because that's the final answer that the caller is
12
 * interested in.
13
 */
14
class TraversalResult
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
15
{
16
    /**
17
     * @var ?GameState Empty if the traversed node was a leaf node
18
     */
19
    public $move;
20
21
    /**
22
     * @var EvaluationResult
23
     */
24
    public $evaluation;
25
26 12
    private function __construct(EvaluationResult $evaluation, GameState $move = null)
27
    {
28 12
        $this->move = $move;
29 12
        $this->evaluation = $evaluation;
30 12
    }
31
32 12
    public static function create(GameState $move, EvaluationResult $evaluation): TraversalResult
33
    {
34 12
        return new static($evaluation, $move);
35
    }
36
37 12
    public static function onlyEvaluation(EvaluationResult $evaluation): TraversalResult
38
    {
39 12
        return new static($evaluation);
40
    }
41
}
42