48 lines
1.7 KiB
Swift
48 lines
1.7 KiB
Swift
|
|
import Foundation
|
||
|
|
@testable import ChessPenguin
|
||
|
|
|
||
|
|
func loadGame(_ pgn: String, index: UInt32 = 0) throws -> GameData {
|
||
|
|
let database = try openBytes(name: "fixture.pgn", bytes: Data(pgn.utf8))
|
||
|
|
return try database.game(index: index)
|
||
|
|
}
|
||
|
|
|
||
|
|
func makeGameRow(result: String = "1-0") -> GameRow {
|
||
|
|
GameRow(
|
||
|
|
index: 6,
|
||
|
|
white: "Morphy, Paul",
|
||
|
|
black: "Duke Karl / Count Isouard",
|
||
|
|
result: result,
|
||
|
|
date: "1858.??.??",
|
||
|
|
event: "Paris Opera",
|
||
|
|
eco: "C41",
|
||
|
|
whiteElo: "",
|
||
|
|
blackElo: ""
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
let operaPGN = #"""
|
||
|
|
[Event "Paris Opera"]
|
||
|
|
[Site "Paris FRA"]
|
||
|
|
[Date "1858.??.??"]
|
||
|
|
[Round "?"]
|
||
|
|
[White "Morphy, Paul"]
|
||
|
|
[Black "Duke Karl / Count Isouard"]
|
||
|
|
[Result "1-0"]
|
||
|
|
[ECO "C41"]
|
||
|
|
[PlyCount "33"]
|
||
|
|
|
||
|
|
{The "Opera Game": a model of rapid development and open lines.} 1. e4 e5 2. Nf3
|
||
|
|
d6 3. d4 Bg4 $6 {Pinning the knight, but Black will have to give up the bishop
|
||
|
|
pair.} 4. dxe5 Bxf3 (4... dxe5 5. Qxd8+ Kxd8 6. Nxe5 {wins a pawn.}) 5. Qxf3
|
||
|
|
dxe5 6. Bc4 {Threatening Qxf7#.} Nf6 7. Qb3 $1 {A double attack on f7 and b7.}
|
||
|
|
Qe7 8. Nc3 {Morphy prefers development to material.} (8. Qxb7 Qb4+ 9. Qxb4 Bxb4+
|
||
|
|
{only trades queens.}) 8... c6 9. Bg5 b5 $2 {Black wants to chase the bishop, but opens lines towards his own king.}
|
||
|
|
(9... Nbd7 {is the healthy move:} 10. O-O-O {keeps the pressure on d7.} (10. Qxb7 $6 Qb4+
|
||
|
|
11. Qxb4 Bxb4 {[%csl Gb4] and Black is fine.}) 10... h6 11. Bh4 $14) 10. Nxb5 $1
|
||
|
|
{[%cal Gb5d6,Gc4f7] The knight sacrifice opens the c-file and the a4-e8 diagonal.} cxb5 11.
|
||
|
|
Bxb5+ Nbd7 12. O-O-O {[%csl Rd7][%cal Gd1d7,Gb5d7] All of White's pieces aim at d7.} Rd8
|
||
|
|
13. Rxd7 $1 Rxd7 14. Rd1 Qe6 15. Bxd7+ Nxd7 16. Qb8+ $3 {[%cal Gb3b8,Gd1d8] The famous
|
||
|
|
queen sacrifice.} Nxb8 17. Rd8# {[%csl Re8] A model of rapid development.}
|
||
|
|
1-0
|
||
|
|
"""#
|