changed up uci impl

This commit is contained in:
simoncreates
2026-02-26 22:14:50 +01:00
parent a533242d7b
commit a88f163a63
+16 -5
View File
@@ -3,6 +3,9 @@ from dataclasses import dataclass
from typing import Iterator, Optional, List, Tuple from typing import Iterator, Optional, List, Tuple
import random import random
FILES = "abcdefgh"
RANKS = "12345678"
class PieceType(Enum): class PieceType(Enum):
PAWN = auto() PAWN = auto()
KNIGHT = auto() KNIGHT = auto()
@@ -513,16 +516,24 @@ class ChessBoard:
# https://en.wikipedia.org/wiki/Algebraic_notation_(chess) # https://en.wikipedia.org/wiki/Algebraic_notation_(chess)
@staticmethod @staticmethod
def pos_to_algebraic(pos: BoardPos) -> str: def pos_to_algebraic(pos: BoardPos) -> str:
file = chr(ord('a') + pos.y) file = FILES[pos.y]
rank = str(8 - pos.x) rank = RANKS[7 - pos.x]
return f"{file}{rank}" return file + rank
@staticmethod @staticmethod
def algebraic_to_pos(s: str) -> BoardPos: def algebraic_to_pos(s: str) -> BoardPos:
if len(s) != 2: if len(s) != 2:
raise ValueError("invalid algebraic square") raise ValueError("invalid algebraic square")
col = ord(s[0].lower()) - ord('a')
row = 8 - int(s[1]) file_char = s[0].lower()
rank_char = s[1]
if file_char not in FILES or rank_char not in RANKS:
raise ValueError("invalid algebraic square")
col = FILES.index(file_char)
row = 7 - RANKS.index(rank_char)
return BoardPos((row, col)) return BoardPos((row, col))
# https://www.chess.com/de/terms/forsyth-edwards-notation-fen # https://www.chess.com/de/terms/forsyth-edwards-notation-fen