esca 0.3.0

A chess model that answers what is true about a position: variants, positions, games, and move text.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
//! Variants, square sets, moves, positions and games.

use std::sync::Arc;

use pyo3::prelude::*;
use pyo3::types::PyList;

use crate::game::Game;
use crate::moves::Move;
use crate::position::Position;
use crate::types::{Piece, SquareSet};
use crate::variant::Variant as VariantTrait;

use super::convert::{
    castling_output_from, castling_output_name, claim_name, colour_from, colour_name,
    move_kind_from, move_kind_name, outcome_name, role_from, role_name, square_from, square_name,
    value_error, variant_by_name, wing_from,
};
use super::explain::{
    PyCastling, PyClaimableDraw, PyDrawStatus, PyEnPassant, PyFiftyMove, PyPin, PyRepetition,
    PySkewer, claims,
};
use super::facts::{PyAnnotatedMove, PyFacts};

/// One set of chess rules.
#[pyclass(frozen, eq, hash, from_py_object, module = "esca", name = "Variant")]
#[derive(Clone)]
pub struct PyVariant {
    pub(crate) inner: Arc<dyn VariantTrait>,
}

impl PyVariant {
    pub(crate) fn new(inner: Arc<dyn VariantTrait>) -> PyVariant {
        PyVariant { inner }
    }

    pub(crate) fn rules(&self) -> &dyn VariantTrait {
        self.inner.as_ref()
    }
}

impl PartialEq for PyVariant {
    fn eq(&self, other: &PyVariant) -> bool {
        self.inner.name() == other.inner.name()
    }
}

impl Eq for PyVariant {}

impl std::hash::Hash for PyVariant {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.inner.name().hash(state);
    }
}

#[pymethods]
impl PyVariant {
    /// The shared variant of that name: `chess` or `chess960`.
    #[staticmethod]
    fn named(name: &str) -> PyResult<PyVariant> {
        variant_by_name(name).map(PyVariant::new)
    }

    /// The identifier PGN and UCI use.
    #[getter]
    fn name(&self) -> &'static str {
        self.inner.name()
    }

    /// The roles a pawn may promote to.
    #[getter]
    fn promotion_roles(&self) -> Vec<String> {
        self.inner
            .promotion_roles()
            .iter()
            .copied()
            .map(role_name)
            .collect()
    }

    /// The position a game of this variant starts from.
    #[pyo3(signature = (seed = 0))]
    fn start_position(&self, seed: u64) -> PyPosition {
        PyPosition::new(self.inner.start_position(seed))
    }

    fn __repr__(&self) -> String {
        format!("<Variant {}>", self.inner.name())
    }

    fn __reduce__<'py>(slf: &Bound<'py, Self>) -> PyResult<(Bound<'py, PyAny>, (&'static str,))> {
        let named = slf.get_type().getattr("named")?;
        Ok((named, (slf.get().inner.name(),)))
    }
}

/// A set of squares.
#[pyclass(frozen, eq, hash, from_py_object, module = "esca", name = "SquareSet")]
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct PySquareSet {
    pub(crate) inner: SquareSet,
}

impl PySquareSet {
    pub(crate) fn new(inner: SquareSet) -> PySquareSet {
        PySquareSet { inner }
    }

    /// The two sets of a side-paired fact, us first.
    pub(crate) fn pair(sets: [SquareSet; 2]) -> (PySquareSet, PySquareSet) {
        (PySquareSet::new(sets[0]), PySquareSet::new(sets[1]))
    }
}

#[pymethods]
impl PySquareSet {
    #[new]
    #[pyo3(signature = (squares = None))]
    fn py_new(squares: Option<Vec<String>>) -> PyResult<PySquareSet> {
        let mut set = SquareSet::EMPTY;
        for name in squares.unwrap_or_default() {
            set.insert(square_from(&name)?);
        }
        Ok(PySquareSet::new(set))
    }

    /// The membership bits, bit *i* for square *i*.
    #[getter]
    fn bits(&self) -> u64 {
        self.inner.bits()
    }

    /// The members, in ascending square index.
    #[getter]
    fn squares(&self) -> Vec<String> {
        self.inner.into_iter().map(square_name).collect()
    }

    fn __len__(&self) -> usize {
        self.inner.len() as usize
    }

    fn __bool__(&self) -> bool {
        !self.inner.is_empty()
    }

    fn __contains__(&self, square: &str) -> PyResult<bool> {
        Ok(self.inner.contains(square_from(square)?))
    }

    fn __iter__(slf: PyRef<'_, Self>) -> PyResult<Py<PyAny>> {
        let py = slf.py();
        Ok(PyList::new(py, slf.squares())?
            .try_iter()?
            .into_any()
            .unbind())
    }

    fn __and__(&self, other: &PySquareSet) -> PySquareSet {
        PySquareSet::new(self.inner & other.inner)
    }

    fn __or__(&self, other: &PySquareSet) -> PySquareSet {
        PySquareSet::new(self.inner | other.inner)
    }

    fn __xor__(&self, other: &PySquareSet) -> PySquareSet {
        PySquareSet::new(self.inner ^ other.inner)
    }

    fn __sub__(&self, other: &PySquareSet) -> PySquareSet {
        PySquareSet::new(self.inner - other.inner)
    }

    fn __invert__(&self) -> PySquareSet {
        PySquareSet::new(!self.inner)
    }

    /// Whether every member is a member of `other`.
    fn is_subset(&self, other: &PySquareSet) -> bool {
        self.inner.is_subset(other.inner)
    }

    fn __repr__(&self) -> String {
        format!("SquareSet({:?})", self.squares())
    }

    fn __getnewargs__(&self) -> (Vec<String>,) {
        (self.squares(),)
    }
}

/// One action: origin, destination, promotion role and kind.
#[pyclass(frozen, eq, hash, from_py_object, module = "esca", name = "Move")]
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct PyMove {
    pub(crate) inner: Move,
}

impl PyMove {
    pub(crate) fn new(inner: Move) -> PyMove {
        PyMove { inner }
    }
}

#[pymethods]
impl PyMove {
    #[new]
    #[pyo3(signature = (origin, destination, promotion = None, kind = "quiet", is_capture = false))]
    fn py_new(
        origin: &str,
        destination: &str,
        promotion: Option<&str>,
        kind: &str,
        is_capture: bool,
    ) -> PyResult<PyMove> {
        let promotion = promotion.map(role_from).transpose()?;
        let mv = Move::new(
            square_from(origin)?,
            square_from(destination)?,
            promotion,
            move_kind_from(kind)?,
        );
        Ok(PyMove::new(mv.with_capture(is_capture)))
    }

    /// The square the moving unit starts on; for castling, the king's.
    #[getter]
    fn origin(&self) -> String {
        square_name(self.inner.from())
    }

    /// The square it ends on; for castling, the rook's own square.
    #[getter]
    fn destination(&self) -> String {
        square_name(self.inner.to())
    }

    /// The role a promoting pawn becomes.
    #[getter]
    fn promotion(&self) -> Option<String> {
        self.inner.promotion().map(role_name)
    }

    /// `quiet`, `capture`, `en_passant`, `castling` or `promotion`.
    #[getter]
    fn kind(&self) -> &'static str {
        move_kind_name(self.inner.kind())
    }

    #[getter]
    fn is_capture(&self) -> bool {
        self.inner.is_capture()
    }

    #[getter]
    fn is_castling(&self) -> bool {
        self.inner.is_castling()
    }

    #[getter]
    fn is_en_passant(&self) -> bool {
        self.inner.is_en_passant()
    }

    /// Origin, destination and promotion role, castling king-to-rook. The
    /// spelling a variant asks for comes from `Game.move_to_uci`.
    #[getter]
    fn uci(&self) -> String {
        self.inner.to_string()
    }

    fn __str__(&self) -> String {
        self.inner.to_string()
    }

    fn __repr__(&self) -> String {
        format!("<Move {}>", self.inner)
    }

    fn __getnewargs__(&self) -> (String, String, Option<String>, &'static str, bool) {
        (
            self.origin(),
            self.destination(),
            self.promotion(),
            self.kind(),
            self.inner.is_capture(),
        )
    }
}

/// Placement and state, with no rules attached.
#[pyclass(frozen, eq, hash, from_py_object, module = "esca", name = "Position")]
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct PyPosition {
    pub(crate) inner: Position,
}

impl PyPosition {
    pub(crate) fn new(inner: Position) -> PyPosition {
        PyPosition { inner }
    }

    /// The text a round trip has to preserve: four fields when the clocks are
    /// unknown, six otherwise.
    fn text(&self) -> String {
        if self.inner.clocks_known() {
            self.inner.fen()
        } else {
            self.inner.epd()
        }
    }
}

#[pymethods]
impl PyPosition {
    /// Reads a six-field FEN, or a four-field one, which leaves the clocks
    /// unknown.
    #[staticmethod]
    fn from_fen(fen: &str) -> PyResult<PyPosition> {
        Position::from_fen(fen)
            .map(PyPosition::new)
            .map_err(value_error)
    }

    /// The six-field FEN.
    #[getter]
    fn fen(&self) -> String {
        self.inner.fen()
    }

    /// The first four FEN fields.
    #[getter]
    fn epd(&self) -> String {
        self.inner.epd()
    }

    /// `w` or `b`.
    #[getter]
    fn side_to_move(&self) -> String {
        colour_name(self.inner.side_to_move())
    }

    /// The FEN castling field.
    #[getter]
    fn castling_rights(&self) -> String {
        self.inner.castling_rights().to_fen_field()
    }

    /// The square a pawn skipped on the previous ply.
    #[getter]
    fn en_passant(&self) -> Option<String> {
        self.inner.en_passant().map(square_name)
    }

    #[getter]
    fn halfmove_clock(&self) -> u32 {
        self.inner.halfmove_clock()
    }

    #[getter]
    fn fullmove_number(&self) -> u32 {
        self.inner.fullmove_number()
    }

    /// False when the position came from a four-field FEN.
    #[getter]
    fn clocks_known(&self) -> bool {
        self.inner.clocks_known()
    }

    #[getter]
    fn in_check(&self) -> bool {
        self.inner.in_check()
    }

    /// Every square holding a unit.
    #[getter]
    fn occupied(&self) -> PySquareSet {
        PySquareSet::new(self.inner.occupied())
    }

    /// The Zobrist key. An identity within one process run only.
    #[getter]
    fn key(&self) -> u64 {
        self.inner.key().get()
    }

    /// The FEN letter of the unit on `square`, if any.
    fn piece_at(&self, square: &str) -> PyResult<Option<String>> {
        Ok(self
            .inner
            .piece_at(square_from(square)?)
            .map(|piece| piece.to_char().to_string()))
    }

    /// Every square holding a unit of `role`, of either colour.
    fn by_role(&self, role: &str) -> PyResult<PySquareSet> {
        Ok(PySquareSet::new(self.inner.by_role(role_from(role)?)))
    }

    /// Every square holding a unit of `colour`.
    fn by_colour(&self, colour: &str) -> PyResult<PySquareSet> {
        Ok(PySquareSet::new(self.inner.by_colour(colour_from(colour)?)))
    }

    /// Every square holding a unit of `role` and `colour`.
    fn by_piece(&self, role: &str, colour: &str) -> PyResult<PySquareSet> {
        let piece = Piece::new(role_from(role)?, colour_from(colour)?);
        Ok(PySquareSet::new(self.inner.by_piece(piece)))
    }

    /// Where `colour`'s king stands.
    fn king_of(&self, colour: &str) -> PyResult<String> {
        Ok(square_name(self.inner.king_of(colour_from(colour)?)))
    }

    /// The Polyglot key: the same number in every run and in every program
    /// that implements the format.
    #[getter]
    fn polyglot_key(&self) -> u64 {
        self.inner.polyglot_key()
    }

    /// The static exchange evaluation of the unit on `square`.
    fn see(&self, square: &str) -> PyResult<i32> {
        Ok(self.inner.see(square_from(square)?))
    }

    /// The static exchange evaluation of `mv`, which the caller has checked is
    /// a move of this position.
    fn see_capture(&self, mv: &PyMove) -> i32 {
        self.inner.see_capture(mv.inner)
    }

    /// The facts of this position under `variant`.
    #[pyo3(signature = (variant = None))]
    fn facts(&self, variant: Option<PyVariant>) -> PyFacts {
        let variant = variant.unwrap_or_else(super::default_variant);
        PyFacts::of_position(&self.inner, variant)
    }

    /// What stands in the way of `colour` castling on `wing`, which is
    /// `short` or `long`.
    fn castling(&self, colour: &str, wing: &str) -> PyResult<PyCastling> {
        let castling = self.inner.castling(colour_from(colour)?, wing_from(wing)?);
        Ok(PyCastling::of(&castling))
    }

    /// The en-passant capture this position offers the side to move.
    fn en_passant_status(&self) -> PyEnPassant {
        PyEnPassant::of(&self.inner.en_passant_status())
    }

    /// The units giving check to the side to move.
    fn checkers(&self) -> PySquareSet {
        PySquareSet::new(self.inner.checkers())
    }

    /// The units of `colour` attacking `square`, pins ignored.
    fn attackers(&self, square: &str, colour: &str) -> PyResult<PySquareSet> {
        let square = square_from(square)?;
        Ok(PySquareSet::new(
            self.inner.attackers(square, colour_from(colour)?),
        ))
    }

    /// The squares strictly between two squares; empty when they share no
    /// rank, file or diagonal.
    fn between(&self, origin: &str, destination: &str) -> PyResult<PySquareSet> {
        let origin = square_from(origin)?;
        Ok(PySquareSet::new(
            self.inner.between(origin, square_from(destination)?),
        ))
    }

    /// The absolute pins on `colour`'s units.
    fn pins(&self, colour: &str) -> PyResult<Vec<PyPin>> {
        Ok(self
            .inner
            .pins(colour_from(colour)?)
            .iter()
            .map(PyPin::of)
            .collect())
    }

    /// The skewers on `colour`'s units, the more valuable one in front.
    fn skewers(&self, colour: &str) -> PyResult<Vec<PySkewer>> {
        Ok(self
            .inner
            .skewers(colour_from(colour)?)
            .iter()
            .map(PySkewer::of)
            .collect())
    }

    /// The position with the colours swapped and the ranks flipped.
    fn mirrored(&self) -> PyPosition {
        PyPosition::new(self.inner.mirrored())
    }

    /// Board, side to move and state, for a human reader. Not a stable format.
    fn summary(&self) -> String {
        self.inner.summary()
    }

    fn __str__(&self) -> String {
        self.inner.fen()
    }

    fn __repr__(&self) -> String {
        format!("<Position {}>", self.text())
    }

    fn __reduce__<'py>(slf: &Bound<'py, Self>) -> PyResult<(Bound<'py, PyAny>, (String,))> {
        let from_fen = slf.get_type().getattr("from_fen")?;
        Ok((from_fen, (slf.get().text(),)))
    }
}

/// A variant, a start position and the moves played from it.
#[pyclass(module = "esca", name = "Game")]
pub struct PyGame {
    inner: Game,
    variant: PyVariant,
}

impl PyGame {
    pub(crate) fn seeded(inner: Game, variant: PyVariant) -> PyGame {
        PyGame { inner, variant }
    }

    #[cfg(any(feature = "pgn", feature = "polyglot", feature = "uci"))]
    pub(crate) fn played(&self) -> &Game {
        &self.inner
    }
}

#[pymethods]
impl PyGame {
    #[new]
    #[pyo3(signature = (*, variant = None, seed = 0))]
    fn py_new(variant: Option<PyVariant>, seed: u64) -> PyGame {
        let variant = variant.unwrap_or_else(super::default_variant);
        let game = Game::with_seed(variant.inner.clone(), seed);
        PyGame::seeded(game, variant)
    }

    /// A game starting from the position `fen` describes.
    #[staticmethod]
    #[pyo3(signature = (fen, *, variant = None))]
    fn from_fen(fen: &str, variant: Option<PyVariant>) -> PyResult<PyGame> {
        let variant = variant.unwrap_or_else(super::default_variant);
        let game = Game::from_fen(variant.inner.clone(), fen).map_err(value_error)?;
        Ok(PyGame::seeded(game, variant))
    }

    /// A game starting from `position`.
    #[staticmethod]
    #[pyo3(signature = (position, *, variant = None))]
    fn from_position(position: &PyPosition, variant: Option<PyVariant>) -> PyResult<PyGame> {
        let variant = variant.unwrap_or_else(super::default_variant);
        let game = Game::from_position(variant.inner.clone(), position.inner.clone())
            .map_err(value_error)?;
        Ok(PyGame::seeded(game, variant))
    }

    /// The rules this game is played under.
    #[getter]
    fn variant(&self) -> PyVariant {
        self.variant.clone()
    }

    /// The position now.
    #[getter]
    fn position(&self) -> PyPosition {
        PyPosition::new(self.inner.position().clone())
    }

    /// The position the game started from.
    #[getter]
    fn start_position(&self) -> PyPosition {
        PyPosition::new(self.inner.start_position().clone())
    }

    /// The moves played, in order.
    #[getter]
    fn moves(&self) -> Vec<PyMove> {
        self.inner
            .moves()
            .iter()
            .copied()
            .map(PyMove::new)
            .collect()
    }

    /// Every position from the start to the current one.
    #[getter]
    fn positions(&self) -> Vec<PyPosition> {
        self.inner
            .positions()
            .cloned()
            .map(PyPosition::new)
            .collect()
    }

    /// How many moves have been played.
    #[getter]
    fn ply(&self) -> u32 {
        self.inner.ply()
    }

    /// The castling spelling of this game's UCI output.
    #[getter]
    fn castling_output(&self) -> &'static str {
        castling_output_name(self.inner.castling_output())
    }

    #[setter]
    fn set_castling_output(&mut self, style: &str) -> PyResult<()> {
        self.inner.set_castling_output(castling_output_from(style)?);
        Ok(())
    }

    /// The legal moves in the current position.
    fn legal_moves(&self) -> Vec<PyMove> {
        self.inner
            .legal_moves()
            .iter()
            .copied()
            .map(PyMove::new)
            .collect()
    }

    /// Every legal move in the current position, annotated.
    fn annotated_moves(&self) -> Vec<PyAnnotatedMove> {
        self.inner
            .annotated_moves()
            .iter()
            .copied()
            .map(PyAnnotatedMove::new)
            .collect()
    }

    /// Plays a move, given as a `Move` or as UCI text.
    fn play(&mut self, mv: &Bound<'_, PyAny>) -> PyResult<()> {
        if let Ok(mv) = mv.extract::<PyMove>() {
            return self.inner.play(mv.inner).map_err(value_error);
        }
        let text: String = mv.extract()?;
        self.inner.play_uci(&text).map_err(value_error)
    }

    /// Plays the move `text` names in SAN.
    fn play_san(&mut self, text: &str) -> PyResult<()> {
        self.inner.play_san(text).map_err(value_error)
    }

    /// Takes back the last move, returning it.
    fn undo(&mut self) -> Option<PyMove> {
        self.inner.undo().map(PyMove::new)
    }

    /// The UCI text of `mv` in the current position.
    fn move_to_uci(&self, mv: &PyMove) -> String {
        self.inner.move_to_uci(mv.inner)
    }

    /// The SAN text of `mv` in the current position.
    fn move_to_san(&self, mv: &PyMove) -> String {
        self.inner.move_to_san(mv.inner)
    }

    /// The automatic terminal condition, if any. The winner of a `checkmate`
    /// is the side that is not to move.
    fn outcome(&self) -> Option<&'static str> {
        self.inner.outcome().map(outcome_name)
    }

    /// The draws a player could claim now.
    fn claims(&self) -> Vec<&'static str> {
        self.inner
            .claims()
            .iter()
            .copied()
            .map(claim_name)
            .collect()
    }

    /// How often the current position has occurred in this game.
    fn repetitions(&self) -> u32 {
        self.inner.repetitions()
    }

    /// How often the current position has stood, and which earlier plies
    /// share its placement without counting.
    fn repetition_status(&self) -> PyRepetition {
        PyRepetition::of(&self.inner.repetition_status())
    }

    /// The halfmove clock, what it counts towards, and what last cleared it.
    fn fifty_move_status(&self) -> PyFiftyMove {
        PyFiftyMove::of(&self.inner.fifty_move_status())
    }

    /// Every draw condition that holds now.
    fn draw_status(&self) -> PyDrawStatus {
        PyDrawStatus::of(&self.inner.draw_status())
    }

    /// What could be claimed once `mv` is played. Empty when `mv` is not
    /// legal here.
    fn claims_after(&self, mv: &PyMove) -> Vec<PyClaimableDraw> {
        claims(&self.inner.claims_after(mv.inner))
    }

    /// The facts of the current position, repetition and history included.
    fn facts(&self) -> PyFacts {
        PyFacts::of_game(&self.inner, self.variant.clone())
    }

    /// The opening of the deepest named position this game has reached.
    #[cfg(feature = "openings")]
    fn opening(&self) -> Option<super::openings::PyOpening> {
        self.inner.opening().map(super::openings::PyOpening::new)
    }

    /// This game as PGN, with a seven-tag roster of placeholders.
    #[cfg(feature = "pgn")]
    fn to_pgn(&self) -> super::pgn::PyPgnGame {
        super::pgn::PyPgnGame::new(self.inner.to_pgn())
    }

    fn __repr__(&self) -> String {
        format!(
            "<Game {} ply {} {}>",
            self.inner.variant().name(),
            self.inner.ply(),
            self.inner.position().fen()
        )
    }
}