2013-06-15 03:43:46 +00:00
|
|
|
-module(player).
|
|
|
|
|
|
|
|
-include("riichi.hrl").
|
|
|
|
|
|
|
|
-export([new/0,
|
|
|
|
new/1,
|
|
|
|
new/2,
|
2017-08-23 23:24:00 +00:00
|
|
|
send/2,
|
2013-06-15 03:43:46 +00:00
|
|
|
discards/1,
|
|
|
|
draw/2]).
|
|
|
|
|
|
|
|
new() ->
|
|
|
|
new("Computer").
|
|
|
|
|
|
|
|
new(Name) ->
|
2017-08-23 23:24:00 +00:00
|
|
|
{ok, Pid} = player_dummy:start_link(Name),
|
|
|
|
new(Name, Pid).
|
2013-06-15 03:43:46 +00:00
|
|
|
|
2017-08-23 23:24:00 +00:00
|
|
|
new(Name, Pid) ->
|
|
|
|
#player{name = Name, pid = Pid}.
|
|
|
|
|
|
|
|
send(#player{pid = Pid}, Message) ->
|
|
|
|
gen_server:cast(Pid, Message).
|
2013-06-15 03:43:46 +00:00
|
|
|
|
|
|
|
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)}.
|