diff --git a/README.md b/README.md index a5385b5..ba9dff1 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Enjoy! ## What remains to be done +- Filter saving PGN to 80 characters per line - Finish Zobrist hashing unit test with all the scenarios: castling, attack, etc. - Ensure that when a Game is copied, the history is also copied, not just referenced because it will get messed up (see FEngineInfo) - Better handling of openings when a FEN is passed (and the board is not in the expected state for the opening) @@ -31,3 +32,10 @@ Enjoy! - Add more openings - Transposition table [here](http://www.chessbin.com/post/Transposition-Table-and-Zobrist-Hashing) and [here](https://chessprogramming.wikispaces.com/Transposition+Table) - [Optimization](https://people.cs.clemson.edu/~dhouse/courses/405/papers/optimize.pdf) + +## Limitations + +- unable to have read-only document (it always want to write it back) +- background of List is not transparent in Light Mode (it is white) +- unable to create rich text with support of tapping in it (like to select precisely the white or black move) + diff --git a/Shared/BChessUIApp.swift b/Shared/BChessUIApp.swift index feacf4b..0825d1d 100644 --- a/Shared/BChessUIApp.swift +++ b/Shared/BChessUIApp.swift @@ -11,7 +11,7 @@ import SwiftUI @main struct BChessUIApp: App { var body: some Scene { - DocumentGroup(newDocument: ChessDocument()) { file in + DocumentGroup(newDocument: try! ChessDocument()) { file in ContentView(document: file.$document) } #if os(macOS) diff --git a/Shared/ChessDocument.swift b/Shared/ChessDocument.swift index c5e1161..057f47f 100644 --- a/Shared/ChessDocument.swift +++ b/Shared/ChessDocument.swift @@ -111,9 +111,11 @@ struct ChessDocument: FileDocument { return PiecesFactory().pieces(forState: engine.state) } - init(pgn: String = startPosPGN, white: GamePlayer? = nil, black: GamePlayer? = nil, rotated: Bool = false, mode: GameMode = GameMode(value: .play)) { + init(pgn: String = startPosPGN, white: GamePlayer? = nil, black: GamePlayer? = nil, rotated: Bool = false, mode: GameMode = GameMode(value: .play)) throws { self.pgn = pgn - self.engine.loadAllGames(pgn) + guard self.engine.loadAllGames(pgn) else { + throw CocoaError(.fileReadCorruptFile) + } self.whitePlayer = white ?? GamePlayer(name: "", computer: false, level: 0) self.blackPlayer = black ?? GamePlayer(name: "", computer: true, level: 0) self.rotated = rotated @@ -146,9 +148,9 @@ struct ChessDocument: FileDocument { let decoder = JSONDecoder() let state = try decoder.decode(GameState.self, from: data) - self.init(pgn: state.pgn, white: state.white, black: state.black, rotated: state.rotated) + try self.init(pgn: state.pgn, white: state.white, black: state.black, rotated: state.rotated) } else if configuration.contentType == .pgn { - self.init(pgn: String(decoding: data, as: UTF8.self), + try self.init(pgn: String(decoding: data, as: UTF8.self), white: GamePlayer(name: "", computer: false, level: 0), black: GamePlayer(name: "", computer: false, level: 0)) } else { diff --git a/Shared/Views/BoardView.swift b/Shared/Views/BoardView.swift index 68e7117..0527cb3 100644 --- a/Shared/Views/BoardView.swift +++ b/Shared/Views/BoardView.swift @@ -43,7 +43,7 @@ struct BoardView: View { struct BoardView_Previews: PreviewProvider { static var previews: some View { - let doc = ChessDocument() + let doc = try! ChessDocument() BoardView(document: .constant(doc)) } } diff --git a/Shared/Views/ContentView.swift b/Shared/Views/ContentView.swift index abba323..ac2235b 100644 --- a/Shared/Views/ContentView.swift +++ b/Shared/Views/ContentView.swift @@ -66,15 +66,15 @@ struct ContentView_Previews: PreviewProvider { static var previews: some View { Group { - let doc = ChessDocument(mode: GameMode(value: .analyze)) + let doc = try! ChessDocument(mode: GameMode(value: .analyze)) ContentView(document: .constant(doc)) } Group { - let doc = ChessDocument(mode: GameMode(value: .train)) + let doc = try! ChessDocument(mode: GameMode(value: .train)) ContentView(document: .constant(doc)) } Group { - let doc = ChessDocument(rotated: true) + let doc = try! ChessDocument(rotated: true) ContentView(document: .constant(doc)) } } diff --git a/Shared/Views/InformationView.swift b/Shared/Views/InformationView.swift index a458f52..78afb32 100644 --- a/Shared/Views/InformationView.swift +++ b/Shared/Views/InformationView.swift @@ -100,11 +100,11 @@ struct InformationView: View { struct BottomInformationView_Previews: PreviewProvider { static var previews: some View { Group { - let doc = ChessDocument(pgn: "1. e4 e5 *") + let doc = try! ChessDocument(pgn: "1. e4 e5 *") InformationView(document: .constant(doc)) } Group { - let doc = ChessDocument(pgn: "1. e4 e5 2. Nf3 Nf6 3. Nxe5 d6 4. Nc3 dxe5 *") + let doc = try! ChessDocument(pgn: "1. e4 e5 2. Nf3 Nf6 3. Nxe5 d6 4. Nc3 dxe5 *") InformationView(document: .constant(doc)) } } diff --git a/Shared/Views/LabelsView.swift b/Shared/Views/LabelsView.swift index ad1102e..10fac89 100644 --- a/Shared/Views/LabelsView.swift +++ b/Shared/Views/LabelsView.swift @@ -51,14 +51,14 @@ struct LabelsView: View { struct LabelsView_Previews: PreviewProvider { static var previews: some View { Group { - let doc = ChessDocument() + let doc = try! ChessDocument() ZStack { BoardView(document: .constant(doc)) LabelsView(document: .constant(doc)) } } Group { - let doc = ChessDocument(rotated: true) + let doc = try! ChessDocument(rotated: true) ZStack { BoardView(document: .constant(doc)) LabelsView(document: .constant(doc)) diff --git a/Shared/Views/NavigationView.swift b/Shared/Views/NavigationView.swift index 5988384..a4f2501 100644 --- a/Shared/Views/NavigationView.swift +++ b/Shared/Views/NavigationView.swift @@ -51,7 +51,7 @@ struct NavigationView: View { struct NavigationView_Previews: PreviewProvider { static var previews: some View { - let doc = ChessDocument() + let doc = try! ChessDocument() NavigationView(document: .constant(doc)) } } diff --git a/Shared/Views/NewGameView.swift b/Shared/Views/NewGameView.swift index 47f476c..c5c90e3 100644 --- a/Shared/Views/NewGameView.swift +++ b/Shared/Views/NewGameView.swift @@ -84,11 +84,11 @@ struct NewGameView: View { struct NewGameView_Previews: PreviewProvider { static var previews: some View { Group { - let doc = ChessDocument() + let doc = try! ChessDocument() NewGameView(document: .constant(doc), editMode: false) } Group { - let doc = ChessDocument() + let doc = try! ChessDocument() NewGameView(document: .constant(doc), editMode: true) } } diff --git a/Shared/Views/PiecesView.swift b/Shared/Views/PiecesView.swift index d596703..a3fb127 100644 --- a/Shared/Views/PiecesView.swift +++ b/Shared/Views/PiecesView.swift @@ -165,14 +165,14 @@ struct PiecesView: View { struct PiecesView_Previews: PreviewProvider { static var previews: some View { Group { - let doc = ChessDocument() + let doc = try! ChessDocument() ZStack { BoardView(document: .constant(doc)) PiecesView(document: .constant(doc)) } } Group { - let doc = ChessDocument(rotated: true) + let doc = try! ChessDocument(rotated: true) ZStack { BoardView(document: .constant(doc)) PiecesView(document: .constant(doc)) diff --git a/Shared/Views/TopInformationView.swift b/Shared/Views/TopInformationView.swift index 72e0dc3..ecac8e8 100644 --- a/Shared/Views/TopInformationView.swift +++ b/Shared/Views/TopInformationView.swift @@ -99,15 +99,15 @@ struct TopInformationView: View { struct TopInformationView_Previews: PreviewProvider { static var previews: some View { Group { - let doc = ChessDocument(pgn: "1. e4 e5") + let doc = try! ChessDocument(pgn: "1. e4 e5") TopInformationView(document: .constant(doc)) } Group { - let doc = ChessDocument(pgn: "1. e4 e5 2. Nf3 Nf6 3. Nxe5 d6 4. Nc3 dxe5 ") + let doc = try! ChessDocument(pgn: "1. e4 e5 2. Nf3 Nf6 3. Nxe5 d6 4. Nc3 dxe5 ") TopInformationView(document: .constant(doc)) } Group { - let doc = ChessDocument(pgn: "1. e4 e5 2. Nf3 Nf6 3. Nxe5 d6 4. Nc3 dxe5 5. d4 exd4 6. Qxd4 Qxd4 7. Nd5 Nxd5 8. Bb5+ c6 9. Bxc6+ Nxc6 *") + let doc = try! ChessDocument(pgn: "1. e4 e5 2. Nf3 Nf6 3. Nxe5 d6 4. Nc3 dxe5 5. d4 exd4 6. Qxd4 Qxd4 7. Nd5 Nxd5 8. Bb5+ c6 9. Bxc6+ Nxc6 *") TopInformationView(document: .constant(doc)) } } diff --git a/Shared/Views/VariationSelectionView.swift b/Shared/Views/VariationSelectionView.swift index 4c0632e..098d5f7 100644 --- a/Shared/Views/VariationSelectionView.swift +++ b/Shared/Views/VariationSelectionView.swift @@ -61,7 +61,7 @@ struct VariationSelectionView: View { struct VariationSelectionView_Previews: PreviewProvider { static var previews: some View { Group { - let doc = ChessDocument() + let doc = try! ChessDocument() ZStack { BoardView(document: .constant(doc)) PiecesView(document: .constant(doc))