Compare commits
3 Commits
fe7884233c
...
baac9b3e74
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
baac9b3e74 | ||
|
|
4daf04d340 | ||
|
|
f19638a4e6 |
17
app.py
17
app.py
@@ -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"
|
p.value.isupper() != is_white or p.value == "E"
|
||||||
):
|
):
|
||||||
valids.append(target.copy())
|
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
|
return valids
|
||||||
|
|
||||||
|
|
||||||
@@ -388,8 +393,16 @@ def generate_valid_moves(
|
|||||||
)
|
)
|
||||||
if king not in enemy_moves:
|
if king not in enemy_moves:
|
||||||
continue
|
continue
|
||||||
|
ni = i
|
||||||
|
nj = j
|
||||||
|
if j == sx and i == sy:
|
||||||
|
ni = m.y
|
||||||
|
nj = m.x
|
||||||
new_enemy_moves = get_piece_moves(
|
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:
|
if king in new_enemy_moves:
|
||||||
king_safe = False
|
king_safe = False
|
||||||
@@ -456,7 +469,7 @@ async def move(request: Request, room_id):
|
|||||||
board.grid[c.y][c.x] = srcp
|
board.grid[c.y][c.x] = srcp
|
||||||
sx, sy = pos_to_coord(src)
|
sx, sy = pos_to_coord(src)
|
||||||
board.grid[sy][sx] = Piece.EMPTY
|
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
|
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.turn = Color.BLACK if color == Color.WHITE else Color.WHITE
|
||||||
room.last_move = datetime.now(timezone.utc)
|
room.last_move = datetime.now(timezone.utc)
|
||||||
|
|||||||
Reference in New Issue
Block a user