File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -275,6 +275,32 @@ def square(file_index: File, rank_index: Rank) -> Square:
275275 """Gets a square number by file and rank index."""
276276 return rank_index * 8 + file_index
277277
278+ def parse_file (name : str ) -> File :
279+ """
280+ Gets the file index for the given file *name*
281+ (e.g., ``a`` returns ``0``).
282+
283+ :raises: :exc:`ValueError` if the file name is invalid.
284+ """
285+ return FILE_NAMES .index (name )
286+
287+ def file_name (file : File ) -> str :
288+ """Gets the name of the file, like ``a``."""
289+ return FILE_NAMES [file ]
290+
291+ def parse_rank (name : str ) -> File :
292+ """
293+ Gets the rank index for the given rank *name*
294+ (e.g., ``1`` returns ``0``).
295+
296+ :raises: :exc:`ValueError` if the rank name is invalid.
297+ """
298+ return FILE_NAMES .index (name )
299+
300+ def rank_name (rank : Rank ) -> str :
301+ """Gets the name of the rank, like ``1``."""
302+ return FILE_NAMES [rank ]
303+
278304def square_file (square : Square ) -> File :
279305 """Gets the file index of the square where ``0`` is the a-file."""
280306 return square & 7
You can’t perform that action at this time.
0 commit comments