TraversalResult   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
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 34
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A create() 0 4 1
A withoutMove() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace lucidtaz\minimax\engine;
6
7
use lucidtaz\minimax\game\GameState;
8
9
/**
10
 * An value type to hold an evaluation result and possibly a move
11
 *
12
 * For tree traversal, technically only the evaluation result is needed.
13
 * However, at the root of the tree we need to know which move was selected to
14
 * produce that result, because that's the final answer that the caller is
15
 * interested in.
16
 */
17
final class TraversalResult
18
{
19
    /**
20
     * @var GameState|null Empty if the traversed node was a leaf node
21
     */
22
    public $move;
23
24
    /**
25
     * @var Evaluation
26
     */
27
    public $evaluation;
28
29
    /**
30
     * @var Analytics
31
     */
32
    public $analytics;
33
34 14
    private function __construct(Evaluation $evaluation, Analytics $analytics, GameState $move = null)
35
    {
36 14
        $this->move = $move;
37 14
        $this->evaluation = $evaluation;
38 14
        $this->analytics = $analytics;
39 14
    }
40
41 13
    public static function create(GameState $move, Evaluation $evaluation, Analytics $analytics): TraversalResult
42
    {
43 13
        return new static($evaluation, $analytics, $move);
44
    }
45
46 14
    public static function withoutMove(Evaluation $evaluation, Analytics $analytics): TraversalResult
47
    {
48 14
        return new static($evaluation, $analytics);
49
    }
50
}
51