Skip to content

Instantly share code, notes, and snippets.

@jamhed
Created December 22, 2015 12:38
Show Gist options
  • Save jamhed/6677b95b75438fc675ed to your computer and use it in GitHub Desktop.
Save jamhed/6677b95b75438fc675ed to your computer and use it in GitHub Desktop.
if_true(true, Action) -> Action;
if_true(false, _) -> no_such_tile.
check_tile_exists(ExistsAction, Seat, Tile, Seats) ->
#desk_seat{ hand=Hand } = lists:nth(Seat, Seats),
if_true(deck:member(Tile, Hand), ExistsAction).
wait_for_discard({check_discard_possible, Seat, Tile}, S=#state{seat=Seat, seats=Seats}) ->
wait_for_discard({check_tile_exists(discard, Seat, Tile, Seats), Seat, Tile}, S);
wait_for_discard({no_such_tile, Seat, Tile}, S=#state{}) ->
error(S, Seat, #no_such_tile{tile=Tile}),
{next_state, wait_for_discard, S};
% discard
wait_for_discard({discard, Seat, Tile}, S=#state{seat=Seat, seats=Seats}) ->
notify(S, Seat, #discarded{tile=Tile}),
next_move(S#state{seats=discard_tile(Seat, Tile, Seats)});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment