Completed
Push — master ( 73004b...66a620 )
by Thijs
02:37
created

DecisionWithScore   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 41
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isBetterThan() 0 7 2
A getBestComparator() 0 6 2
A getWorstComparator() 0 6 2
1
<?php
2
3
namespace lucidtaz\minimax;
4
5
class DecisionWithScore
6
{
7
    /**
8
     * @var Decision
9
     */
10
    public $decision = null;
11
12
    /**
13
     * @var float
14
     */
15
    public $score;
16
17
    /**
18
     * @var integer How deep in the execution tree this result was found. Higher
19
     * means earlier. This is to prefer earlier solutions to later solutions
20
     * with the same score.
21
     */
22
    public $age;
23
24 9
    public function isBetterThan(DecisionWithScore $other): bool
25
    {
26 9
        if (abs($this->score - $other->score) < 0.1) {
27 9
            return $this->age > $other->age;
28
        }
29 7
        return $this->score > $other->score;
30
    }
31
32 11
    public static function getBestComparator(): \Closure
33
    {
34
        return function (DecisionWithScore $a, DecisionWithScore $b) {
35 9
            return $a->isBetterThan($b) ? $a : $b;
36 11
        };
37
    }
38
39
    public static function getWorstComparator(): \Closure
40
    {
41 10
        return function (DecisionWithScore $a, DecisionWithScore $b) {
42 9
            return $b->isBetterThan($a) ? $a : $b;
43 10
        };
44
    }
45
}
46