diff --git a/README.md b/README.md index 33bb1db..daae515 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ♟️ ChessKit -[![Test ChessKit](https://github.com/chesskit-app/chesskit-swift/actions/workflows/test-chesskit.yml/badge.svg)](https://github.com/chesskit-app/chesskit-swift/actions/workflows/test-chesskit.yml) [![codecov](https://codecov.io/gh/chesskit-app/chesskit-swift/branch/master/graph/badge.svg?token=676EP0N8XF)](https://codecov.io/gh/chesskit-app/chesskit-swift) +[![ChessKit Tests](https://github.com/chesskit-app/chesskit-swift/actions/workflows/test-chesskit.yaml/badge.svg)](https://github.com/chesskit-app/chesskit-swift/actions/workflows/test-chesskit.yaml) [![codecov](https://codecov.io/gh/chesskit-app/chesskit-swift/branch/master/graph/badge.svg?token=676EP0N8XF)](https://codecov.io/gh/chesskit-app/chesskit-swift) A Swift package for efficiently implementing chess logic. diff --git a/Sources/ChessKit/Bitboards/PieceSet.swift b/Sources/ChessKit/Bitboards/PieceSet.swift index 735a827..d785ee5 100644 --- a/Sources/ChessKit/Bitboards/PieceSet.swift +++ b/Sources/ChessKit/Bitboards/PieceSet.swift @@ -54,8 +54,6 @@ struct PieceSet: Equatable { /// Bitboard for all the pawn pieces. var pawns: Bitboard { p | P } - /// Bitboard for all the sliding pieces. - var sliders: Bitboard { Q | q | B | b | R | r } /// Bitboard for all the diagonal sliding pieces. var diagonals: Bitboard { Q | q | B | b } /// Bitboard for all the vertical/horizontal sliding pieces. diff --git a/Sources/ChessKit/Bitboards/Square+BB.swift b/Sources/ChessKit/Bitboards/Square+BB.swift index c2b807e..568076c 100644 --- a/Sources/ChessKit/Bitboards/Square+BB.swift +++ b/Sources/ChessKit/Bitboards/Square+BB.swift @@ -25,12 +25,8 @@ extension [Square] { extension Square.File { var bb: Bitboard { .aFile.east(number - 1) } - - static var bb: [Bitboard] = allCases.map(\.bb) } extension Square.Rank { var bb: Bitboard { .rank1.north(value - 1) } - - static var bb: [Bitboard] = range.map(Square.Rank.init(_:)).map(\.bb) } diff --git a/Sources/ChessKit/Move.swift b/Sources/ChessKit/Move.swift index d643daf..42ca3e7 100644 --- a/Sources/ChessKit/Move.swift +++ b/Sources/ChessKit/Move.swift @@ -76,7 +76,7 @@ public struct Move: Equatable, Hashable { /// Initialize a move with a given SAN string. /// /// This initializer fails if the provided SAN string is invalid. - public init?(san: String, color: Piece.Color, position: Position) { + public init?(san: String, position: Position) { guard let move = SANParser.parse(move: san, in: position) else { return nil } diff --git a/Sources/ChessKit/Parsers/PGNParser+Regex.swift b/Sources/ChessKit/Parsers/PGNParser+Regex.swift index c3e4b17..9342439 100644 --- a/Sources/ChessKit/Parsers/PGNParser+Regex.swift +++ b/Sources/ChessKit/Parsers/PGNParser+Regex.swift @@ -12,7 +12,6 @@ extension PGNParser { static let tagPair = #"\[([^"]+?)\s"([^"]+)"\]"# // move pair components - static let number = #"\d{1,}\.{1,3}"# static let castle = #"[Oo0]-[Oo0](-[Oo0])"# static let move = #"[KQRBN]?[a-h]?[1-8]?x?[a-h][1-8](\=[QRBN])?[+#]"# static let annotation = #"\$\d"# diff --git a/Sources/ChessKit/Parsers/PGNParser.swift b/Sources/ChessKit/Parsers/PGNParser.swift index 2be3ea1..332de4e 100644 --- a/Sources/ChessKit/Parsers/PGNParser.swift +++ b/Sources/ChessKit/Parsers/PGNParser.swift @@ -6,6 +6,7 @@ import Foundation /// Positional assessments. +// periphery:ignore enum PositionAnnotation { // } @@ -221,6 +222,10 @@ public class PGNParser { if let black { game.make(move: black, from: blackIndex) } + + if let result = move.result { + game.tags.result = result.rawValue + } } return game diff --git a/Sources/ChessKit/Piece.swift b/Sources/ChessKit/Piece.swift index f7ef3fd..ae823ab 100644 --- a/Sources/ChessKit/Piece.swift +++ b/Sources/ChessKit/Piece.swift @@ -26,17 +26,6 @@ public struct Piece: Equatable, Hashable { case pawn = "" case knight = "N", bishop = "B", rook = "R", queen = "Q", king = "K" - /// The relative value of each piece. - var value: Int { - switch self { - case .pawn: return 1 - case .bishop, .knight: return 3 - case .rook: return 5 - case .queen: return 9 - case .king: return 0 - } - } - /// The notation of the given piece kind. public var notation: String { switch self { diff --git a/Tests/ChessKitTests/MoveTests.swift b/Tests/ChessKitTests/MoveTests.swift index 0e14ab7..c49d722 100644 --- a/Tests/ChessKitTests/MoveTests.swift +++ b/Tests/ChessKitTests/MoveTests.swift @@ -10,13 +10,13 @@ class MoveTests: XCTestCase { func testMoveSANInit() { let move = Move(result: .move, piece: .init(.pawn, color: .white, square: .e4), start: .e2, end: .e4) - let moveFromSAN = Move(san: "e4", color: .white, position: .standard) + let moveFromSAN = Move(san: "e4", position: .standard) XCTAssertEqual(move, moveFromSAN) } func testMoveInvalidSANInit() { - XCTAssertNil(Move(san: "e5", color: .white, position: .standard)) + XCTAssertNil(Move(san: "e5", position: .standard)) } func testMoveNotation() { diff --git a/Tests/ChessKitTests/PieceTests.swift b/Tests/ChessKitTests/PieceTests.swift index bd80b58..910d554 100644 --- a/Tests/ChessKitTests/PieceTests.swift +++ b/Tests/ChessKitTests/PieceTests.swift @@ -10,27 +10,21 @@ class PieceTests: XCTestCase { func testNotation() { let pawn = Piece.Kind.pawn - XCTAssertEqual(pawn.value, 1) XCTAssertEqual(pawn.notation, "") let bishop = Piece.Kind.bishop - XCTAssertEqual(bishop.value, 3) XCTAssertEqual(bishop.notation, "B") let knight = Piece.Kind.knight - XCTAssertEqual(knight.value, 3) XCTAssertEqual(knight.notation, "N") let rook = Piece.Kind.rook - XCTAssertEqual(rook.value, 5) XCTAssertEqual(rook.notation, "R") let queen = Piece.Kind.queen - XCTAssertEqual(queen.value, 9) XCTAssertEqual(queen.notation, "Q") let king = Piece.Kind.king - XCTAssertEqual(king.value, 0) XCTAssertEqual(king.notation, "K") }