Skip to content

Commit 55fa545

Browse files
committed
Convert more cosmic mods to majs
1 parent a8794a4 commit 55fa545

File tree

9 files changed

+240
-36
lines changed

9 files changed

+240
-36
lines changed

priv/static/mods/cosmic_calls.majs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# replace closed call check
32
apply replace_all, "", [["chii", "pon", "daiminkan", "kakan"], ["ton", "chii", "chon", "chon_honors", "daiminfuun", "pon", "daiminkan", "kapon", "kakakan", "kafuun", "kakan"]]
43
apply replace_all, "buttons.kakan.show_when", [["kakan"], ["kakan", "kakakan"]]
@@ -9,12 +8,14 @@ def do_kan_draw do
98
shift_tile_to_dead_wall(1)
109
draw(1, "opposite_end")
1110
end
11+
# chankan should work on kakakan
12+
# TODO make last_call_is a constant
1213
define_button chankan,
1314
display_name: "Ron",
1415
show_when: not_our_turn
1516
and match(["hand", "calls"], ["tenpai"])
1617
and status_missing("furiten", "just_reached")
17-
and last_call_is("kakan", "pei")
18+
and last_call_is("kakan", "kakakan", "pei")
1819
and match(["hand", "calls", "last_called_tile"], ["win"])
1920
do
2021
big_text("Ron")
@@ -125,10 +126,7 @@ define_button anfuun,
125126
and status_missing("just_reached")
126127
and (status_missing("riichi") or not_call_would_change_waits("win"))
127128
and self_call_available,
128-
call_conditions:
129-
can_discard_after_call
130-
and match(["called_tile"], ~m"(1z 2z 3z 4z):1")
131-
and (status_missing("riichi") or not_call_changes_waits("win")),
129+
call_conditions: match(["called_tile"], ~m"(1z 2z 3z 4z):1") and (status_missing("riichi") or not_call_changes_waits("win")),
132130
call: [[1, 2, 3]],
133131
call_style: %{
134132
self: [["1x", 2], 0, 1, ["1x", 3]]
@@ -149,7 +147,7 @@ define_button kapon,
149147
and status_missing("just_reached")
150148
and (status_missing("riichi") or not_call_would_change_waits("win"))
151149
and can_upgrade_call,
152-
call_conditions: can_discard_after_call and (status_missing("riichi") or not_call_changes_waits("win")),
150+
call_conditions: status_missing("riichi") or not_call_changes_waits("win"),
153151
call: [[0, 0]],
154152
upgrades: "ton",
155153
call_style: %{
@@ -170,7 +168,7 @@ define_button kakakan,
170168
and status_missing("just_reached")
171169
and (status_missing("riichi") or not_call_would_change_waits("win"))
172170
and can_upgrade_call,
173-
call_conditions: can_discard_after_call and (status_missing("riichi") or not_call_changes_waits("win")),
171+
call_conditions: status_missing("riichi") or not_call_changes_waits("win"),
174172
call: [[0, 0, 0]],
175173
upgrades: "kapon",
176174
call_style: %{

priv/static/mods/kan.majs

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
on after_initialization do
2+
add_rule("Rules", "Rinshan", "If you kan and then tsumo on the replacement tile, you are awarded rinshan (1 han).")
3+
add_rule("Rules", "Chankan", "If someone calls kan to upgrade a triplet (added kan), you may call ron on the added tile. Doing so awards chankan (1 han).)")
4+
end
5+
6+
define_yaku yaku, "Chankan", 1, won_by_call
7+
define_yaku yaku, "Rinshan", 1, status("kan")
8+
define_yaku yaku, "Sankantsu", 2, match(["calls"], ~m"(daiminkan ankan kakan):3")
9+
define_yaku yakuman, "Suukantsu", 1, match(["calls"], ~m"(daiminkan ankan kakan):4")
10+
11+
def do_kan_draw do
12+
set_status("$status")
13+
shift_tile_to_dead_wall(1)
14+
draw(1, "opposite_end")
15+
end
16+
17+
apply prepend, "functions.discard_passed" do
18+
as others do
19+
unset_status("kan")
20+
end
21+
end
22+
23+
# additional furiten check
24+
apply append, "functions.discard_passed" do
25+
as everyone do
26+
if (last_call_is("kakan") and match(["hand", "calls", "last_called_tile"], ["win"]))
27+
or (last_call_is("ankan") and match(["hand", "calls"], ["kokushi_tenpai"]) and match(["hand", "calls", "last_called_tile"], ["win"])) do
28+
set_status("furiten")
29+
end
30+
end
31+
end
32+
33+
apply append, "buttons.ron.precedence_over", ["daiminkan"]
34+
35+
define_button daiminkan,
36+
display_name: "Kan",
37+
show_when:
38+
not_our_turn
39+
and not_no_tiles_remaining
40+
and someone_else_just_discarded
41+
and status_missing("riichi") # TODO should the riichi mod add this?
42+
and tile_not_drawn(-4)
43+
and call_available,
44+
call_conditions: can_discard_after_call,
45+
precedence_over: ["chii", "pon", "daiminkan"],
46+
call: [[0, 0, 0]],
47+
call_style: %{
48+
kamicha: ["call_sideways", 0, 1, 2],
49+
toimen: [0, "call_sideways", 1, 2],
50+
shimocha: [0, 1, 2, "call_sideways"]
51+
}
52+
do
53+
big_text("Kan")
54+
call
55+
change_turn("self")
56+
do_kan_draw(status: "kan")
57+
end
58+
59+
define_button ankan,
60+
display_name: "Ankan",
61+
show_when:
62+
our_turn
63+
and not_no_tiles_remaining
64+
and has_draw
65+
and status_missing("just_reached") # TODO should the riichi mod add this?
66+
and tile_not_drawn(-4)
67+
and self_call_available,
68+
precedence_over: ["chii", "pon", "daiminkan"],
69+
call: [[0, 0, 0]],
70+
call_style: %{self: [["1x", 2], 0, 1, ["1x", 3]]}
71+
do
72+
big_text("Kan")
73+
self_call
74+
do_kan_draw(status: "kan")
75+
end
76+
77+
define_button kakan,
78+
display_name: "Kan",
79+
show_when:
80+
our_turn
81+
and not_no_tiles_remaining
82+
and has_draw
83+
and status_missing("just_reached") # TODO should the riichi mod add this?
84+
and tile_not_drawn(-4)
85+
and can_upgrade_call,
86+
precedence_over: ["chii", "pon", "daiminkan"],
87+
call: [[0, 0, 0]],
88+
upgrades: "pon",
89+
call_style: %{
90+
kamicha: [["sideways", 0], "call_sideways", 1, 2],
91+
toimen: [0, ["sideways", 1], "call_sideways", 2],
92+
shimocha: [0, 1, ["sideways", 2], "call_sideways"]
93+
}
94+
do
95+
big_text("Kan")
96+
upgrade_call
97+
discard_passed
98+
do_kan_draw(status: "kan")
99+
end
100+
101+
define_button chankan,
102+
display_name: "Ron",
103+
show_when: not_our_turn
104+
and match(["hand", "calls"], ["tenpai"])
105+
and status_missing("furiten", "just_reached")
106+
and last_call_is("kakan")
107+
and match(["hand", "calls", "last_called_tile"], ["win"]),
108+
precedence_over: ["chii", "pon", "daiminkan"]
109+
do
110+
big_text("Ron")
111+
pause(1000)
112+
reveal_hand
113+
win_by_call
114+
end
115+
116+
apply merge, "constants.calls_fu", %{
117+
ankan: 16,
118+
daiminkan: 8,
119+
kakan: 8
120+
}

priv/static/mods/kontsu.majs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ define_match junchan, ~m"exhaustive, (terminal_l terminal_r terminal_t terminak_
77
# now leaving the chanta zone
88

99
# kontsu fu
10-
apply append, "constants.calls_fu", %{
10+
apply merge, "constants.calls_fu", %{
1111
chon: 1,
1212
kapon: 2,
1313
kakakan: 8,

priv/static/mods/sanma.majs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ apply replace_all, "", ["pei", "pei_triplet"]
2727
apply prepend, "functions.discard_passed", [["as", "others", [["unset_status", "pei"]]]]
2828

2929
# change tenpai payments and add tsumo loss
30-
apply append, "score_calculation", %{
30+
apply merge, "score_calculation", %{
3131
draw_tenpai_payments: [1000, 2000, 0],
3232
tsumo_loss: true
3333
}
@@ -85,6 +85,8 @@ def do_kan_draw do
8585
shift_tile_to_dead_wall(1)
8686
draw(1, "opposite_end")
8787
end
88+
# chankan should work on pei
89+
# TODO make last_call_is a constant
8890
define_button chankan,
8991
display_name: "Ron",
9092
show_when: not_our_turn
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
define_set kontsu_123, ~s"1z 2z 3z"
2+
define_set kontsu_124, ~s"1z 2z 4z"
3+
define_set kontsu_134, ~s"1z 3z 4z"
4+
define_set kontsu_234, ~s"2z 3z 4z"
5+
define_set kontsu_567, ~s"5z 6z 7z"
6+
define_set fuun, ~s"1z 2z 3z 4z"
7+
define_set ryandoukon, ~s"0 10 20, 0 10 20"
8+
define_set sandoukon, ~s"0 10 20, 0 10 20, 0 10 20"
9+
define_set yondoukon, ~s"0 10 20, 0 10 20, 0 10 20, 0 10 20"
10+
11+
# handle mini-sangen counting
12+
on before_scoring do
13+
set_counter("mini_sangen", 0)
14+
# count each mini sangen and multiply by 0.5
15+
add_counter("mini_sangen", "count_matches", ["hand", "calls", "winning_tile"], ~m"kontsu_567:1")
16+
multiply_counter("mini_sangen", 0.5)
17+
end
18+
define_yaku yaku, "Mini-Sangen", "mini_sangen", counter_at_least("mini_sangen", 0.5)
19+
20+
# handle mixed winds counting
21+
on before_scoring do
22+
set_counter("mixed_winds", 0)
23+
# count mixed winds that contain both prevalent and seat wind
24+
unless round_wind_is("north") and seat_is("north") do
25+
add_counter("mixed_winds_123", "count_matches", ["hand", "calls", "winning_tile"], ~m"kontsu_123:1")
26+
end
27+
unless round_wind_is("west") and seat_is("west") do
28+
add_counter("mixed_winds_124", "count_matches", ["hand", "calls", "winning_tile"], ~m"kontsu_124:1")
29+
end
30+
unless round_wind_is("south") and seat_is("south") do
31+
add_counter("mixed_winds_134", "count_matches", ["hand", "calls", "winning_tile"], ~m"kontsu_134:1")
32+
end
33+
unless round_wind_is("east") and seat_is("east") do
34+
add_counter("mixed_winds_234", "count_matches", ["hand", "calls", "winning_tile"], ~m"kontsu_234:1")
35+
end
36+
# the above counts will count fuuns, so subtract fuun count from each
37+
# "fuuns" in hand also contribute to double counting
38+
add_counter("fuun_count", "count_matches", ["hand", "calls", "winning_tile"], ~m"fuun:1")
39+
subtract_counter("mixed_winds_123", "fuun_count")
40+
subtract_counter("mixed_winds_124", "fuun_count")
41+
subtract_counter("mixed_winds_134", "fuun_count")
42+
subtract_counter("mixed_winds_234", "fuun_count")
43+
# add the counts up and multiply by 0.5
44+
if counter_at_least("mixed_winds_123", 1) do
45+
add_counter("mixed_winds", "mixed_winds_123")
46+
end
47+
if counter_at_least("mixed_winds_124", 1) do
48+
add_counter("mixed_winds", "mixed_winds_124")
49+
end
50+
if counter_at_least("mixed_winds_134", 1) do
51+
add_counter("mixed_winds", "mixed_winds_134")
52+
end
53+
if counter_at_least("mixed_winds_234", 1) do
54+
add_counter("mixed_winds", "mixed_winds_234")
55+
end
56+
if counter_at_least("fuun_count", 1) do
57+
add_counter("mixed_winds", "fuun_count")
58+
end
59+
multiply_counter("mixed_winds", 0.5)
60+
end
61+
define_yaku yaku, "Mixed Winds", "mixed_winds", counter_at_least("mixed_winds", 0.5)
62+
63+
# other kontsu yaku
64+
65+
define_const closed_hand, has_no_call_named("ton", "chii", "chon", "chon_honors", "daiminfuun", "pon", "daiminkan", "kapon", "kakakan", "kafuun", "kakan")
66+
67+
define_yaku yaku, "Toikon", 1, match(["hand", "calls", "winning_tile"], ~m"exhaustive, (kontsu_123 kontsu_124 kontsu_134 kontsu_234 kontsu_dragons):4, pair:1")
68+
define_yaku yaku, "Ryandoukon", 1, "@closed_hand" and match(["hand", "calls", "winning_tile"], ~m"exhaustive, ryandoukon:1, (shuntsu koutsu kontsu):2, pair:1")
69+
define_yaku yaku, "Sandoukon", 2, match(["hand", "calls", "winning_tile"], ~m"exhaustive, sandoukon:1, (shuntsu koutsu kontsu):1, pair:1")
70+
remove_yaku yaku, "Rinshan"
71+
define_yaku yaku, "Rinshan", 1, status("kan") or status("fuun")
72+
define_yaku yakuman, "Yondoukon", 1, match(["hand", "calls", "winning_tile"], ~m"exhaustive, yondoukon:1, pair:1")
73+
define_yaku meta_yaku, "Toikon", 1, @closed_hand and has_existing_yaku("Toikon")
74+
define_yaku meta_yaku, "Sandoukon", 1, @closed_hand and has_existing_yaku("Sandoukon")
75+
76+
define_yaku_precedence "Sanshoku Doukou", ["Sandoukon"]
77+
define_yaku_precedence "Kokushi Musou", ["Mixed Winds", "Mini-Sangen"]
78+
define_yaku_precedence "Kokushi Musou Juusan Menmachi", ["Mixed Winds", "Mini-Sangen"]

priv/static/rulesets/riichi.majs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ define_set quad, ~s"0 0 0 0"
4141
define_set "ryanmen/penchan", ~s"0 1"
4242
define_set kanchan, ~s"0 2"
4343
define_set iipeikou, ~s"0 0 1 1 2 2"
44-
define_set ittsu, ~s"0 1 2 | 3 4 5 | 6 7 8"
45-
define_set sanshoku_doujun, ~s"0 1 2 | 10 11 12 | 20 21 22"
46-
define_set sanshoku_doukou, ~s"0 0 0 | 10 10 10 | 20 20 20"
44+
define_set ittsu, ~s"0 1 2, 3 4 5, 6 7 8"
45+
define_set sanshoku_doujun, ~s"0 1 2, 10 11 12, 20 21 22"
46+
define_set sanshoku_doukou, ~s"0 0 0, 10 10 10, 20 20 20"
4747
define_set ton, ~s"1z 1z 1z"
4848
define_set nan, ~s"2z 2z 2z"
4949
define_set shaa, ~s"3z 3z 3z"
@@ -121,14 +121,16 @@ define_match sanankou_ron,
121121
| exhaustive, (pon daiminkan kakan):-2, (koutsu):4, (any@winning_tile):0, pair:1
122122
"""
123123

124-
define_yaku yaku, "Tsumo", 1, won_by_draw and has_no_call_named("chii", "pon", "daiminkan", "kakan")
124+
define_const closed_hand, has_no_call_named("chii", "pon", "daiminkan", "kakan")
125+
126+
define_yaku yaku, "Tsumo", 1, won_by_draw and @closed_hand
125127
define_yaku yaku, "Haitei", 1, no_tiles_remaining and won_by_draw
126128
define_yaku yaku, "Houtei", 1, no_tiles_remaining and not_won_by_draw
127-
define_yaku yaku, "Pinfu", 1, has_no_call_named("chii", "pon", "daiminkan", "kakan")
129+
define_yaku yaku, "Pinfu", 1, @closed_hand
128130
and match(["hand", "calls", "winning_tile"], ["standard_win"])
129131
and ((won_by_draw and fu_equals(20)) or (not_won_by_draw and fu_equals(30)))
130132
define_yaku yaku, "Tanyao", 1, winning_hand_consists_of("2m","3m","4m","5m","6m","7m","8m","2p","3p","4p","5p","6p","7p","8p","2s","3s","4s","5s","6s","7s","8s")
131-
define_yaku yaku, "Iipeikou", 1, has_no_call_named("chii", "pon", "daiminkan", "kakan")
133+
define_yaku yaku, "Iipeikou", 1, @closed_hand
132134
and match(["hand", "calls", "winning_tile"], ~m"exhaustive, iipeikou:1, (shuntsu koutsu):2, pair:1")
133135
define_yaku yaku, "Haku", 1, match(["hand", "calls", "winning_tile"], ~m"exhaustive, haku:1, (shuntsu koutsu):3, pair:1")
134136
define_yaku yaku, "Hatsu", 1, match(["hand", "calls", "winning_tile"], ~m"exhaustive, hatsu:1, (shuntsu koutsu):3, pair:1")
@@ -182,12 +184,12 @@ define_yaku yaku, "Chinitsu", 5,
182184
winning_hand_consists_of("1m","2m","3m","4m","5m","6m","7m","8m","9m")
183185
or winning_hand_consists_of("1p","2p","3p","4p","5p","6p","7p","8p","9p")
184186
or winning_hand_consists_of("1s","2s","3s","4s","5s","6s","7s","8s","9s")
185-
define_yaku meta_yaku, "Chanta", 1, has_no_call_named("chii", "pon", "daiminkan", "kakan") and has_existing_yaku("Chanta")
186-
define_yaku meta_yaku, "Ittsu", 1, has_no_call_named("chii", "pon", "daiminkan", "kakan") and has_existing_yaku("Ittsu")
187-
define_yaku meta_yaku, "Sanshoku", 1, has_no_call_named("chii", "pon", "daiminkan", "kakan") and has_existing_yaku("Sanshoku")
188-
define_yaku meta_yaku, "Junchan", 1, has_no_call_named("chii", "pon", "daiminkan", "kakan") and has_existing_yaku("Junchan")
189-
define_yaku meta_yaku, "Honitsu", 1, has_no_call_named("chii", "pon", "daiminkan", "kakan") and has_existing_yaku("Honitsu")
190-
define_yaku meta_yaku, "Chinitsu", 1, has_no_call_named("chii", "pon", "daiminkan", "kakan") and has_existing_yaku("Chinitsu")
187+
define_yaku meta_yaku, "Chanta", 1, @closed_hand and has_existing_yaku("Chanta")
188+
define_yaku meta_yaku, "Ittsu", 1, @closed_hand and has_existing_yaku("Ittsu")
189+
define_yaku meta_yaku, "Sanshoku", 1, @closed_hand and has_existing_yaku("Sanshoku")
190+
define_yaku meta_yaku, "Junchan", 1, @closed_hand and has_existing_yaku("Junchan")
191+
define_yaku meta_yaku, "Honitsu", 1, @closed_hand and has_existing_yaku("Honitsu")
192+
define_yaku meta_yaku, "Chinitsu", 1, @closed_hand and has_existing_yaku("Chinitsu")
191193
define_yaku yakuman, "Tenhou", 1, status("discards_empty") and won_by_draw and seat_is("east")
192194
define_yaku yakuman, "Chiihou", 1, status("discards_empty") and won_by_draw and not_seat_is("east")
193195
define_yaku yakuman, "Daisangen", 1, match(["hand", "calls", "winning_tile"], ~m"haku:1, hatsu:1, chun:1")
@@ -292,9 +294,7 @@ def discard_passed do
292294
end
293295
end
294296

295-
define_const calls_fu, %{
296-
pon: 2
297-
}
297+
define_const calls_fu, %{pon: 2}
298298
define_const winning_groups_fu, [
299299
# kanchan
300300
%{group: [-1, 1], value: 2},
@@ -319,19 +319,19 @@ def calculate_fu do
319319
remove_attrs
320320

321321
# score calls
322-
convert_calls("@calls_fu")
322+
convert_calls(@calls_fu)
323323
remove_tanyaohai_calls
324-
convert_calls("@calls_fu")
324+
convert_calls(@calls_fu)
325325
remove_calls
326326

327327
# now remove the winning group
328-
remove_winning_groups("@winning_groups_fu")
328+
remove_winning_groups(@winning_groups_fu)
329329

330330
# now remove all closed groups
331-
remove_groups("@groups_fu")
332-
remove_groups("@groups_fu")
333-
remove_groups("@groups_fu")
334-
remove_groups("@groups_fu")
331+
remove_groups(@groups_fu)
332+
remove_groups(@groups_fu)
333+
remove_groups(@groups_fu)
334+
remove_groups(@groups_fu)
335335

336336
# remove final pair, if any
337337
remove_groups([%{group: [0, 0], yakuhai_value: 2}])
@@ -346,11 +346,11 @@ def calculate_fu do
346346
add(20)
347347

348348
# tsumo +2 (except closed pinfu tsumo)
349-
add(2, won_by_draw and (minipoints_at_most(999) or not_has_no_call_named("chii", "pon", "daiminkan", "kakan")))
349+
add(2, won_by_draw and (minipoints_at_most(999) or not @closed_hand))
350350

351351
# closed ron +10 and open pinfu ron +10
352-
add(10, not_won_by_draw and has_no_call_named("chii", "pon", "daiminkan", "kakan"))
353-
add(10, not_won_by_draw and not_has_no_call_named("chii", "pon", "daiminkan", "kakan") and minipoints_at_least(1000))
352+
add(10, not_won_by_draw and @closed_hand)
353+
add(10, not_won_by_draw and not @closed_hand and minipoints_at_least(1000))
354354

355355
# take max, then subtract 1000 from pinfu hands
356356
take_maximum
@@ -366,7 +366,7 @@ def calculate_fu do
366366
add(25, minipoints_equals(0) and match(["hand", "calls", "winning_tile"], [[ [["pair"], 7] ]]))
367367

368368
# kokushi
369-
add(40, not_won_by_draw and has_no_call_named("chii", "pon", "daiminkan", "kakan") and minipoints_equals(0) and match(["hand", "calls", "winning_tile"], ["kokushi"]))
369+
add(40, not_won_by_draw and @closed_hand and minipoints_equals(0) and match(["hand", "calls", "winning_tile"], ["kokushi"]))
370370
add(30, minipoints_equals(0) and match(["hand", "calls", "winning_tile"], ["kokushi"]))
371371
take_maximum
372372
end

0 commit comments

Comments
 (0)