Create actions.py

main
wsy182 2024-11-30 13:28:56 +08:00
parent b7bd0a7037
commit 3d22b695e6
1 changed files with 13 additions and 0 deletions

13
src/engine/actions.py Normal file
View File

@ -0,0 +1,13 @@
def draw_tile(state):
if state.remaining_tiles == 0:
raise ValueError("牌堆已空")
tile = state.deck.pop(0)
state.remaining_tiles -= 1
state.hands[state.current_player][tile] += 1
return tile
def discard_tile(state, tile):
if state.hands[state.current_player][tile] == 0:
raise ValueError("玩家没有这张牌")
state.hands[state.current_player][tile] -= 1
state.discards[state.current_player].append(tile)