Skip to content

Commit

Permalink
Merge d6ee824 into 1e63537
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmay2004 committed Sep 7, 2020
2 parents 1e63537 + d6ee824 commit 58c1721
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions chess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ def square_name(square: Square) -> str:
"""Gets the name of the square, like ``a3``."""
return SQUARE_NAMES[square]

def parse_square(sq_name: str) -> Square:
"""
Gets a square number from the square's name (e.g., "e4" returns 28).
:raises: :exc:`ValueError` if sq_name is invalid (e.g., "d9").
"""
if sq_name in SQUARE_NAMES:
return SQUARE_NAMES.index(sq_name)
else:
raise ValueError(f"'{sq_name}' is not a valid square name")

def square_distance(a: Square, b: Square) -> int:
"""
Gets the distance (i.e., the number of king steps) from square *a* to *b*.
Expand Down

0 comments on commit 58c1721

Please sign in to comment.