mirror of
https://github.com/correl/riichi.git
synced 2024-11-14 11:09:36 +00:00
Module cleanup
This commit is contained in:
parent
f53f8059c5
commit
4d90a04f76
6 changed files with 23 additions and 13 deletions
|
@ -6,7 +6,7 @@
|
|||
|
||||
-module(game).
|
||||
|
||||
-include("riichi.hrl").
|
||||
-include("../include/riichi.hrl").
|
||||
|
||||
-export([new/0,
|
||||
new/1,
|
||||
|
@ -31,10 +31,10 @@ new() ->
|
|||
new(Players) ->
|
||||
lists:foldl(fun add_player/2, new(), Players).
|
||||
|
||||
add_player(_Player, Game = #game{players=Players})
|
||||
add_player(_Player, #game{players=Players})
|
||||
when length(Players) >= 4 ->
|
||||
throw("Game full");
|
||||
add_player(Name, Game = #game{players = Players})
|
||||
add_player(Name, Game = #game{})
|
||||
when is_list(Name) ->
|
||||
add_player(#player{name=Name}, Game);
|
||||
add_player(Player = #player{}, Game = #game{players=Players}) ->
|
||||
|
@ -70,7 +70,7 @@ draw(#game{turn = Turn} = Game) ->
|
|||
Updated = update_player(Game, Turn, Player),
|
||||
Updated#game{wall=Wall}.
|
||||
|
||||
get_player(#game{players = Players} = Game, Seat) ->
|
||||
get_player(#game{players = Players}, Seat) ->
|
||||
Pos = position(Seat) + 1,
|
||||
lists:nth(Pos, Players).
|
||||
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
-module(game_tree).
|
||||
|
||||
-include("riichi.hrl").
|
||||
-include("lazy.hrl").
|
||||
-include("../include/riichi.hrl").
|
||||
-include("../include/lazy.hrl").
|
||||
|
||||
-export([build/1,
|
||||
do/2]).
|
||||
|
||||
-compile([export_all]).
|
||||
|
||||
-record(game_tree, {game, actions}).
|
||||
-record(game_action, {player, action, arguments}).
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
kernel,
|
||||
stdlib
|
||||
]},
|
||||
{modules, []},
|
||||
{mod, { riichi_app, []}},
|
||||
{env, []}
|
||||
]}.
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
-export([waiting/3,
|
||||
playing/2,
|
||||
turn/2]).
|
||||
-export([init/1, handle_event/3, handle_sync_event/4, handle_info/3, terminate/3]).
|
||||
-export([init/1, handle_event/3, handle_sync_event/4, handle_info/3, terminate/3, code_change/4]).
|
||||
|
||||
-include("../include/riichi.hrl").
|
||||
|
||||
|
@ -68,3 +68,6 @@ terminate(Reason, StateName, _State) ->
|
|||
{from_state, StateName},
|
||||
{reason, Reason}]),
|
||||
ok.
|
||||
|
||||
code_change(_OldVsn, StateName, State, _Extra) ->
|
||||
{ok, StateName, State}.
|
||||
|
|
|
@ -22,7 +22,7 @@ handle_call(get_players, _From, State) ->
|
|||
handle_call(_Msg, _From, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
handle_cast({send, {message, From, Body}=Message}, State) ->
|
||||
handle_cast({send, {message, _From, _Body}=Message}, State) ->
|
||||
Players = State#state.players,
|
||||
[gen_server:cast(Pid, Message) || Pid <- Players],
|
||||
{noreply, State};
|
||||
|
@ -37,4 +37,4 @@ terminate(_Reason, _State) ->
|
|||
ok.
|
||||
|
||||
code_change(_OldVsn, State, _Extra) ->
|
||||
{ok, State}.
|
||||
{ok, State}.
|
||||
|
|
12
src/yaku.erl
12
src/yaku.erl
|
@ -28,7 +28,15 @@
|
|||
chinitsu/2,
|
||||
kokushi_musou/2,
|
||||
ryuu_iisou/2,
|
||||
dai_san_gen/2]).
|
||||
dai_san_gen/2,
|
||||
suu_an_kou/2,
|
||||
tsu_iisou/2,
|
||||
chinrouto/2,
|
||||
shou_suushi/2,
|
||||
dai_suushi/2,
|
||||
chuuren_pooto/2,
|
||||
suu_kan_tsu/2
|
||||
]).
|
||||
|
||||
%% @doc Counts the pons/kans of value tiles in a player's hand.
|
||||
%% Value tiles include all of the dragons, plus the round wind and the player's seat wind.
|
||||
|
@ -117,7 +125,7 @@ chanta(#game{}, #player{hand=#hand{tiles=[], melds=Melds}}) ->
|
|||
-spec itsuu(game(), player()) -> boolean().
|
||||
itsuu(#game{}, #player{hand=#hand{tiles=[], melds=Melds}}) ->
|
||||
Tiles = lists:flatten([TS || #meld{type=chii, tiles=TS} <- Melds]),
|
||||
Runs = [lists:filter(fun(#tile{suit=S, value=V}) -> S =:= Suit end, Tiles)
|
||||
Runs = [lists:filter(fun(#tile{suit=S}) -> S =:= Suit end, Tiles)
|
||||
|| Suit <- [man,sou,pin]],
|
||||
lists:any(fun(TS) ->
|
||||
sets:from_list([V || #tile{value=V} <- TS]) =:= sets:from_list(lists:seq(1,9))
|
||||
|
|
Loading…
Reference in a new issue