Skip to content

Commit

Permalink
Add move annotations (#1)
Browse files Browse the repository at this point in the history
* Added ability to annotate moves in `Game` object
  • Loading branch information
pdil authored May 11, 2023
2 parents 1bcf98e + ce08811 commit 7a9661f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# [Unreleased]
# ChessKit 0.1.2
Released Thursday, May 11, 2023.

* Add documentation for all public members
* Add default starting position for `Game` initializer
* Add ability to annotate moves via `Game`

# ChessKit 0.1.1
Released Wednesday, April 12, 2023.
Expand Down
11 changes: 11 additions & 0 deletions Sources/ChessKit/Game.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,15 @@ public class Game: ObservableObject {
PGNParser.convert(game: self)
}

/// Annotate the move of a given `color` for a given `turn`.
public func annotate(
moveAt turn: Int,
color: Piece.Color,
assessment: Move.Assessment,
comment: String = ""
) {
moves[turn]?.updateMove(with: color, keyPath: \.assessment, newValue: assessment)
moves[turn]?.updateMove(with: color, keyPath: \.comment, newValue: comment)
}

}
29 changes: 29 additions & 0 deletions Tests/ChessKitTests/GameTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// GameTests.swift
// ChessKitTests
//

import XCTest
@testable import ChessKit

class GameTests: XCTestCase {

func testAnnotation() {
let game = Game(
pgn: """
1. e4 e5 2. Nf3 $2 Nc6 3. Bb5 a6
4. Ba4 Nf6 5. O-O Be7 6. Re1 b5 7. Bb3 d6 8. c3 O-O 9. h3 Nb8 10. d4 Nbd7 $4
11. c4 c6 12. cxb5 axb5 13. Nc3 Bb7 14. Bg5 b4 15. Nb1 h6 16. Bh4 c5 17. dxe5 Nxe4
"""
)

let assessment = Move.Assessment.good
let comment = "This opening is called the Ruy Lopez."
game?.annotate(moveAt: 3, color: .black, assessment: assessment, comment: comment)

XCTAssertEqual(game?.moves[3]?.black?.assessment, assessment)
XCTAssertEqual(game?.moves[3]?.black?.comment, comment)
}


}

0 comments on commit 7a9661f

Please sign in to comment.