Compare commits

..

3 Commits

Author SHA1 Message Date
0880
baac9b3e74 Fix king protection 2026-01-19 18:30:09 +03:30
0880
4daf04d340 Fix capturing king 2026-01-19 18:18:15 +03:30
0880
f19638a4e6 Fix pawn upgrade 2026-01-19 18:14:37 +03:30

17
app.py
View File

@@ -353,6 +353,11 @@ def get_piece_moves(piece_kind, board: Board, is_white, src: str) -> list[Coord]
p.value.isupper() != is_white or p.value == "E"
):
valids.append(target.copy())
v_temp = [a for a in valids]
valids.clear()
for a in v_temp:
if board.index_coord(a).value.lower != "k":
valids.append(a)
return valids
@@ -388,8 +393,16 @@ def generate_valid_moves(
)
if king not in enemy_moves:
continue
ni = i
nj = j
if j == sx and i == sy:
ni = m.y
nj = m.x
new_enemy_moves = get_piece_moves(
p.value.lower(), fake_board, not is_white, xy_to_pos_safe(j, i)
p.value.lower(),
fake_board,
not is_white,
xy_to_pos_safe(nj, ni),
)
if king in new_enemy_moves:
king_safe = False
@@ -456,7 +469,7 @@ async def move(request: Request, room_id):
board.grid[c.y][c.x] = srcp
sx, sy = pos_to_coord(src)
board.grid[sy][sx] = Piece.EMPTY
if c.y == 0 or c.y == 7 and piece_kind == "p":
if (c.y == 0 or c.y == 7) and piece_kind == "p":
board.grid[c.y][c.x] = Piece.WHITE_QUEEN if is_white else Piece.BLACK_QUEEN
room.turn = Color.BLACK if color == Color.WHITE else Color.WHITE
room.last_move = datetime.now(timezone.utc)