File tree Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 8
8
/// as pawn promotions and end results.
9
9
public protocol BoardDelegate : AnyObject , Sendable {
10
10
func didPromote( with move: Move )
11
- func didCheckKing( ofColor: Piece . Color )
11
+ func didCheckKing( ofColor color : Piece . Color )
12
12
func didEnd( with result: Board . EndResult )
13
13
}
14
14
@@ -233,7 +233,7 @@ public struct Board: Sendable {
233
233
} else if positionHashCounts [ position. hashValue] == 3 {
234
234
delegate? . didEnd ( with: . draw( . repetition) )
235
235
} else if checkState == . check {
236
- delegate? . didCheckKing ( ofColor: processedMove. piece. color)
236
+ delegate? . didCheckKing ( ofColor: processedMove. piece. color. opposite )
237
237
}
238
238
239
239
// pawn promotion
Original file line number Diff line number Diff line change @@ -352,8 +352,23 @@ final class BoardTests: XCTestCase {
352
352
353
353
func testCheckMove( ) {
354
354
var board = Board ( position: . init( fen: " k7/7R/8/8/8/8/K7/8 w - - 0 1 " ) !)
355
+
356
+ nonisolated ( unsafe) var expectation : XCTestExpectation ? = self . expectation ( description: " Board returns check result " )
357
+
358
+ let delegate = MockBoardDelegate ( didCheckKing: { color in
359
+ if color == . black {
360
+ expectation? . fulfill ( )
361
+ expectation = nil
362
+ } else {
363
+ XCTFail ( )
364
+ }
365
+ } )
366
+
367
+ board. delegate = delegate
355
368
let move = board. move ( pieceAt: . h7, to: . h8)
356
369
XCTAssertEqual ( move? . checkState, . check)
370
+
371
+ waitForExpectations ( timeout: 1.0 )
357
372
}
358
373
359
374
func testCheckmateMove( ) {
Original file line number Diff line number Diff line change 7
7
8
8
final class MockBoardDelegate : BoardDelegate {
9
9
private let didPromote : ( @Sendable ( Move ) -> Void ) ?
10
+ private let didCheckKing : ( @Sendable ( Piece . Color ) -> Void ) ?
10
11
private let didEnd : ( @Sendable ( Board . EndResult ) -> Void ) ?
11
12
12
13
init (
13
14
didPromote: ( @Sendable ( Move ) -> Void ) ? = nil ,
15
+ didCheckKing: ( @Sendable ( Piece . Color ) -> Void ) ? = nil ,
14
16
didEnd: ( @Sendable ( Board . EndResult ) -> Void ) ? = nil
15
17
) {
16
18
self . didPromote = didPromote
19
+ self . didCheckKing = didCheckKing
17
20
self . didEnd = didEnd
18
21
}
19
22
20
23
func didPromote( with move: Move ) {
21
24
didPromote ? ( move)
22
25
}
23
26
24
- func didCheckKing( ofColor: Piece . Color ) {
25
-
27
+ func didCheckKing( ofColor color : Piece . Color ) {
28
+ didCheckKing ? ( color )
26
29
}
27
30
28
31
func didEnd( with result: Board . EndResult ) {
You can’t perform that action at this time.
0 commit comments