mirror of
https://github.com/solero/houdini.git
synced 2024-11-25 06:57:24 +00:00
Add try except for mancala movement
This commit is contained in:
parent
438d083602
commit
5dfae648c4
@ -26,6 +26,7 @@ async def handle_join_game(p):
|
|||||||
@handlers.handler(XTPacket('zm', ext='z'))
|
@handlers.handler(XTPacket('zm', ext='z'))
|
||||||
@table_handler(MancalaLogic)
|
@table_handler(MancalaLogic)
|
||||||
async def handle_send_move(p, move: int):
|
async def handle_send_move(p, move: int):
|
||||||
|
try:
|
||||||
seat_id = p.table.get_seat_id(p)
|
seat_id = p.table.get_seat_id(p)
|
||||||
is_player = seat_id < 2
|
is_player = seat_id < 2
|
||||||
game_ready = len(p.table.penguins) > 1
|
game_ready = len(p.table.penguins) > 1
|
||||||
@ -34,8 +35,10 @@ async def handle_send_move(p, move: int):
|
|||||||
hollow, = map(int, move)
|
hollow, = map(int, move)
|
||||||
current_player = p.table.penguins[p.table.logic.current_player - 1]
|
current_player = p.table.penguins[p.table.logic.current_player - 1]
|
||||||
|
|
||||||
if current_player != p: return
|
if current_player != p:
|
||||||
if not p.table.logic.is_valid_move(hollow): return
|
return
|
||||||
|
if not p.table.logic.is_valid_move(hollow):
|
||||||
|
return
|
||||||
|
|
||||||
move_result = p.table.logic.place_stone(hollow)
|
move_result = p.table.logic.place_stone(hollow)
|
||||||
await p.table.send_xt('zm', seat_id, hollow, move_result)
|
await p.table.send_xt('zm', seat_id, hollow, move_result)
|
||||||
@ -53,3 +56,5 @@ async def handle_send_move(p, move: int):
|
|||||||
return
|
return
|
||||||
|
|
||||||
p.table.logic.current_player = 2 if p.table.logic.current_player == 1 else 1
|
p.table.logic.current_player = 2 if p.table.logic.current_player == 1 else 1
|
||||||
|
except (KeyError, ValueError):
|
||||||
|
p.logger.warn(f'Invalid mancala move made by {p}')
|
||||||
|
Loading…
Reference in New Issue
Block a user