Export_writers (model.misc.export_writers)¶
model.misc.export_writers
¶
Chess export writers converting games to PGN, FEN, and stenographic notation.
ChessNotationWriter
¶
Bases: ExportWriter
Serializes chess moves and board states into standard chess formats (PGN, FEN, stenographic).
Source code in src/model/misc/export_writers.py
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 | |
__init__()
¶
export(format_type='PGN', **kwargs)
¶
Export game information in the requested format ('PGN', 'FEN', or 'STENOGRAPHIC').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format_type
|
str
|
Format name case-insensitively ('PGN', 'FEN', 'STENOGRAPHIC'). |
'PGN'
|
**kwargs
|
Any
|
Format-specific parameters ('moves', 'board', 'metadata', 'active_color'). |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
Serialized string representation. |
Source code in src/model/misc/export_writers.py
to_fen(board, active_color=1)
¶
Convert board state to Forsyth-Edwards Notation (FEN) string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
board
|
Any
|
Board instance with rows, cols, and get_piece_at. |
required |
active_color
|
int
|
Active side color (1 for White, -1 for Black). |
1
|
Returns:
| Type | Description |
|---|---|
str
|
FEN record string. |
Source code in src/model/misc/export_writers.py
to_pgn(moves, metadata=None)
¶
Export game moves and metadata to Portable Game Notation (PGN) text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
moves
|
List[Any]
|
List of played Move instances. |
required |
metadata
|
Optional[MetadataWriter]
|
Optional MetadataWriter instance providing PGN header tags. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Complete PGN format string. |
Source code in src/model/misc/export_writers.py
to_stenographic(moves)
¶
Convert a list of moves to stenographic coordinate format (e.g. 'e2e4 e7e5').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
moves
|
List[Any]
|
List of Move instances with start_pos and end_pos. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Space-delimited string of concatenated coordinate pairs. |
Source code in src/model/misc/export_writers.py
ExportWriter
¶
Abstract base class for game export serialization writers.
Source code in src/model/misc/export_writers.py
__init__()
¶
export(*args, **kwargs)
¶
Export game data into the target serialization format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Variable positional arguments. |
()
|
**kwargs
|
Any
|
Variable keyword arguments. |
{}
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Must be implemented by subclasses. |