File tree Expand file tree Collapse file tree 2 files changed +26
-25
lines changed Expand file tree Collapse file tree 2 files changed +26
-25
lines changed Original file line number Diff line number Diff line change 5
5
use Chess \Board ;
6
6
use Chess \PGN \AN \Color ;
7
7
use Chess \PGN \AN \Piece ;
8
+ use Chess \Piece \AbstractPiece ;
8
9
9
10
/**
10
11
* Abstract evaluation.
@@ -33,4 +34,29 @@ public function __construct(Board $board)
33
34
Piece::Q => 8.8 ,
34
35
];
35
36
}
37
+
38
+ protected function attackedPieces (AbstractPiece $ piece ): array
39
+ {
40
+ $ attackedPieces = [];
41
+ foreach ($ sqs = $ piece ->getSqs () as $ sq ) {
42
+ if ($ attackedPiece = $ this ->board ->getPieceBySq ($ sq )) {
43
+ if ($ attackedPiece ->getId () !== Piece::P) {
44
+ $ attackedPieces [] = $ attackedPiece ;
45
+ }
46
+ }
47
+ }
48
+
49
+ return $ attackedPieces ;
50
+ }
51
+
52
+ protected function isKingAttacked (array $ attackedPieces ): bool
53
+ {
54
+ foreach ($ attackedPieces as $ attackedPiece ) {
55
+ if ($ attackedPiece ->getId () === Piece::K) {
56
+ return true ;
57
+ }
58
+ }
59
+
60
+ return false ;
61
+ }
36
62
}
Original file line number Diff line number Diff line change 7
7
8
8
abstract class AbstractForkEvaluation extends AbstractEvaluation
9
9
{
10
- protected function attackedPieces (AbstractPiece $ piece ): array
11
- {
12
- $ attackedPieces = [];
13
- foreach ($ sqs = $ piece ->getSqs () as $ sq ) {
14
- if ($ attackedPiece = $ this ->board ->getPieceBySq ($ sq )) {
15
- if ($ attackedPiece ->getId () !== Piece::P) {
16
- $ attackedPieces [] = $ attackedPiece ;
17
- }
18
- }
19
- }
20
-
21
- return $ attackedPieces ;
22
- }
23
-
24
- protected function isKingAttacked (array $ attackedPieces ): bool
25
- {
26
- foreach ($ attackedPieces as $ attackedPiece ) {
27
- if ($ attackedPiece ->getId () === Piece::K) {
28
- return true ;
29
- }
30
- }
31
-
32
- return false ;
33
- }
34
-
35
10
protected function sumValues (AbstractPiece $ piece , array $ attackedPieces )
36
11
{
37
12
$ values = 0 ;
You can’t perform that action at this time.
0 commit comments