riichi/src/player.erl
2013-06-14 23:43:46 -04:00

26 lines
594 B
Erlang

-module(player).
-include("riichi.hrl").
-export([new/0,
new/1,
new/2,
discards/1,
draw/2]).
new() ->
new("Computer").
new(Name) ->
new(Name, player_dummy).
new(Name, Type) ->
{ok, PID} = Type:start_link(Name),
#player{name = Name, pid = PID}.
discards(#player{discards = Discards} = Player) ->
[{discard, Tile, Player#player{hand = Hand, discards = [Tile|Discards]}}
|| {discard, Tile, Hand} <- hand:discards(Player#player.hand)].
draw(#player{hand = Hand} = Player, Tile) ->
Player#player{hand = hand:draw(Hand, Tile)}.