Skip to content

Commit 6ba172d

Browse files
authored
add pgn tag used in chess.com (#16) (#17)
Signed-off-by: NSStudent <[email protected]>
1 parent 371f718 commit 6ba172d

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

Sources/FischerCore/PGN/Model/PGNTag.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,18 @@ public enum PGNTag: String, CaseIterable, Equatable {
127127

128128
case blackRatingDiff = "BlackRatingDiff"
129129
case whiteRatingDiff = "WhiteRatingDiff"
130+
131+
// CurrentPosition in chess.com PGN sharing
132+
case currentPosition = "CurrentPosition"
133+
case timeZone = "Timezone"
134+
case ecoUrl = "ECOUrl"
135+
case startTime = "StartTime"
136+
case endTime = "EndTime"
137+
case endDate = "EndDate"
138+
case link = "Link"
139+
case whiteUrl = "WhiteUrl"
140+
case whiteCountry = "WhiteCountry"
141+
case blackUrl = "BlackUrl"
142+
case blackCountry = "BlackCountry"
130143

131144
}

Tests/FischerCoreTests/PGN/PGNParserTests.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,4 +612,47 @@ class PGNParserTests {
612612
let resutl = try parser.parse(input)
613613
print(resutl)
614614
}
615+
616+
@Test func eventsInChessComTest() async throws {
617+
let input = """
618+
[Event "Live Chess"]
619+
[Site "Chess.com"]
620+
[Date "2025.07.12"]
621+
[Round "-"]
622+
[White "djgggg"]
623+
[Black "nsstudent"]
624+
[Result "0-1"]
625+
[CurrentPosition "r4rk1/6b1/3p2pp/2pPp3/1pP1q3/7P/PB2N3/1K1Q3R w - - 0 30"]
626+
[Timezone "UTC"]
627+
[ECO "A40"]
628+
[ECOUrl "https://www.chess.com/openings/Modern-Defense-with-1-d4...3.Nf3-d6-4.e4-e5"]
629+
[UTCDate "2025.07.12"]
630+
[UTCTime "11:27:27"]
631+
[WhiteElo "1436"]
632+
[BlackElo "1459"]
633+
[TimeControl "180"]
634+
[Termination "nsstudent won on time"]
635+
[StartTime "11:27:27"]
636+
[EndDate "2025.07.12"]
637+
[EndTime "11:27:27"]
638+
[Link "https://www.chess.com/analysis/game/live/140609505268/analysis?move=57"]
639+
[WhiteUrl "https://www.chess.com/bundles/web/images/noavatar_l.84a92436.gif"]
640+
[WhiteCountry "231"]
641+
[WhiteTitle ""]
642+
[BlackUrl "https://images.chesscomfiles.com/uploads/v1/user/17698432.739dcb00.50x50o.dd9d56a69cea.jpeg"]
643+
[BlackCountry "163"]
644+
[BlackTitle ""]
645+
646+
1. d4 g6 2. c4 Bg7 3. Nf3 d6 4. e4 e5 5. d5 c6 $6 6. Nc3 f5 $6 7. Bd3 $6 f4 8. b3
647+
Nd7 9. Bb2 $6 Nc5 $6 10. Qd2 $6 Nf6 $6 11. Ba3 $6 Nxd3+ 12. Qxd3 c5 13. Ng5 Qe7 14.
648+
Nb5 a6 15. Nc3 h6 16. Nf3 Bd7 17. h3 $6 Nh5 $6 18. O-O-O $6 b5 19. Bb2 b4 20. Ne2
649+
a5 21. Kb1 $6 a4 22. g4 fxg3 $1 23. fxg3 axb3 24. Qxb3 $2 Ba4 $1 25. Qd3 Bxd1 26. Qxd1
650+
O-O 27. Nh4 Nxg3 $3 28. Nxg3 Qxh4 29. Ne2 $6 Qxe4+ 0-1
651+
"""
652+
653+
let parser = PGNGameParser()
654+
let result = try parser.parse(input)
655+
print(result)
656+
#expect(result.elements.count == 29)
657+
}
615658
}

0 commit comments

Comments
 (0)