mirror of
https://github.com/correl/riichi.git
synced 2024-11-23 11:09:56 +00:00
Records and a module for handling game setup
This commit is contained in:
parent
2802bbf15e
commit
9848553050
3 changed files with 59 additions and 8 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
-define(SIMPLES, [#tile{suit=S, value=V} || S <- [pin, man, sou], V <- lists:seq(2,8)]).
|
||||||
|
-define(TERMINALS, [#tile{suit=S, value=V} || S <- [pin, man, sou], V <- [1,9]]).
|
||||||
|
-define(DRAGONS, [#tile{suit=dragon, value=V} || V <- [green, red, white]]).
|
||||||
|
-define(WINDS, [#tile{suit=wind, value=V} || V <- [east, south, west, north]]).
|
||||||
|
-define(HONOURS, ?DRAGONS ++ ?WINDS).
|
||||||
|
-define(TILES, ?SIMPLES ++ ?TERMINALS ++ ?HONOURS).
|
||||||
|
|
||||||
-type wind() :: east | south | west | north.
|
-type wind() :: east | south | west | north.
|
||||||
-type dragon() :: green | red | white.
|
-type dragon() :: green | red | white.
|
||||||
|
|
||||||
|
@ -19,3 +26,27 @@
|
||||||
melds=[] :: [meld()]
|
melds=[] :: [meld()]
|
||||||
}).
|
}).
|
||||||
-type hand() :: #hand{}.
|
-type hand() :: #hand{}.
|
||||||
|
|
||||||
|
-record(player, {
|
||||||
|
name :: string(),
|
||||||
|
seat :: wind(),
|
||||||
|
hand :: hand(),
|
||||||
|
discards :: [tile()],
|
||||||
|
drawn :: none | {tsumo | ron, tile()}
|
||||||
|
}).
|
||||||
|
-type player() :: #player{}.
|
||||||
|
|
||||||
|
-type phase() :: draw | discard.
|
||||||
|
|
||||||
|
-record(game, {
|
||||||
|
rounds=2 :: integer(),
|
||||||
|
timeout=infinity :: integer() | infinity,
|
||||||
|
round=east :: wind(),
|
||||||
|
turn=east :: wind(),
|
||||||
|
phase=draw :: phase(),
|
||||||
|
wall :: [tile()],
|
||||||
|
rinshan :: [tile()],
|
||||||
|
dora :: [tile()],
|
||||||
|
uradora :: [tile()],
|
||||||
|
players :: [player()]
|
||||||
|
}).
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
-module(riichi).
|
-module(riichi).
|
||||||
|
|
||||||
-include("riichi.hrl").
|
-include("../include/riichi.hrl").
|
||||||
|
|
||||||
-export([
|
-export([
|
||||||
is_valid_tile/1,
|
is_valid_tile/1,
|
||||||
dora/1,
|
dora/1,
|
||||||
nearest/2,
|
nearest/2,
|
||||||
score/3,
|
score/3,
|
||||||
score_hand/1,
|
score_hand/1,
|
||||||
score_hand/2,
|
score_hand/2,
|
||||||
score_hand/3
|
score_hand/3,
|
||||||
|
shuffle/1,
|
||||||
|
tiles/0
|
||||||
]).
|
]).
|
||||||
|
|
||||||
is_valid_tile(#tile{suit=dragon, value=Value}) ->
|
is_valid_tile(#tile{suit=dragon, value=Value}) ->
|
||||||
|
@ -130,3 +132,9 @@ find_sets(Tiles) ->
|
||||||
Unique = sets:to_list(sets:from_list(Tiles)),
|
Unique = sets:to_list(sets:from_list(Tiles)),
|
||||||
[{length(lists:filter(fun(X) -> X == T end, Tiles)), T}
|
[{length(lists:filter(fun(X) -> X == T end, Tiles)), T}
|
||||||
|| T <- Unique].
|
|| T <- Unique].
|
||||||
|
|
||||||
|
shuffle(List) ->
|
||||||
|
[X || {_, X} <- lists:sort([{random:uniform(), I} || I <- List])].
|
||||||
|
|
||||||
|
tiles() ->
|
||||||
|
lists:flatten([lists:duplicate(4, T) || T <- ?TILES]).
|
||||||
|
|
12
src/riichi_game.erl
Normal file
12
src/riichi_game.erl
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
-module(riichi_game).
|
||||||
|
|
||||||
|
-include("../include/riichi.hrl").
|
||||||
|
|
||||||
|
-export([new/0]).
|
||||||
|
|
||||||
|
new() ->
|
||||||
|
Tiles = riichi:shuffle(riichi:tiles()),
|
||||||
|
#game{rinshan=lists:sublist(Tiles, 1, 4),
|
||||||
|
dora=lists:sublist(Tiles, 5, 5),
|
||||||
|
uradora=lists:sublist(Tiles, 10,5),
|
||||||
|
wall=lists:sublist(Tiles, 15, 124)}.
|
Loading…
Reference in a new issue