mirror of
https://github.com/correl/riichi.git
synced 2024-11-30 11:09:56 +00:00
26 lines
594 B
Erlang
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)}.
|