Skip to content

Commit

Permalink
riichi module
Browse files Browse the repository at this point in the history
  • Loading branch information
shinkuan committed Feb 13, 2024
1 parent adb1f93 commit 54b4228
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 25 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ https://github.com/shinkuan/RandomStuff/assets/35415788/ce1b598d-b1d7-49fe-a175-

### You will need:
1. A `mortal.pth`. [(Get one from Discord server if you don't have one.)](https://discord.gg/Z2wjXUK8bN)
2. A `libriichi` that match your system. [(Get it here)](https://github.com/shinkuan/Akagi/releases/tag/v0.1.0-libriichi)
3. (Optional, Recommend) Use Windows Terminal to open client.py for a nice looking TUI.
4. (Optional) If you want to use Steam, Majsoul Plus, or anything other client, proxy the client using tools like proxifier.
2. (Optional, Recommend) Use Windows Terminal to open client.py for a nice looking TUI.
3. (Optional) If you want to use Steam, Majsoul Plus, or anything other client, proxy the client using tools like proxifier.

__Get mortal.pth at [Discord](https://discord.gg/Z2wjXUK8bN)__
1. Go to #verify and click the ✅ reaction.
Expand All @@ -65,8 +64,7 @@ Download `install_akagi.ps1` at [Release](https://github.com/shinkuan/Akagi/rele
7. Close it.
8. Go to your user home directory `~/.mitmproxy`
9. Install the certificate.
10. Put `libriichi` into `./Akagi/mjai/bot` and rename it as `libriichi`
11. Put `mortal.pth` into `./Akagi/mjai/bot`
10. Put `mortal.pth` into `./Akagi/mjai/bot`

### settings.json

Expand Down
10 changes: 4 additions & 6 deletions README_CH.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ https://github.com/shinkuan/RandomStuff/assets/35415788/ce1b598d-b1d7-49fe-a175-

在開始前,你需要以下東西:
1. `mortal.pth` [(如果你沒有的話,到Discord去下載)](https://discord.gg/Z2wjXUK8bN)
2. `libriichi` [(到這邊根據你的平台下載對應版本)](https://github.com/shinkuan/Akagi/releases/tag/v0.1.0-libriichi)
3. (Optional) 推薦使用Windows Terminal,以獲得預期中的UI效果。
4. (Optional) 如果你要使用Steam或Majsoul Plus之類的,請使用類似Proxifier的軟體將連線導向至MITM
2. (Optional) 推薦使用Windows Terminal,以獲得預期中的UI效果。
3. (Optional) 如果你要使用Steam或Majsoul Plus之類的,請使用類似Proxifier的軟體將連線導向至MITM

__[Discord](https://discord.gg/Z2wjXUK8bN)下載我提供的mortal.pth__
1. 到 #verify 頻道點擊 ✅ 驗證身分.
Expand All @@ -60,10 +59,9 @@ __到[Discord](https://discord.gg/Z2wjXUK8bN)下載我提供的mortal.pth__
5. 執行: `install_akagi.ps1`
6. 如果這是您第一次使用mitmproxy,請打開它。
7. 關閉它。
8. cd 到用戶主目錄 `~/.mitmproxy`
8. 到使用者主目錄 `~/.mitmproxy`
9. 安裝證書。
10.`libriichi` 放入 `./Akagi/mjai/bot` 並將其重新命名為 `libriichi`
11.`mortal.pth` 放入 `./Akagi/mjai/bot`
10.`mortal.pth` 放入 `./Akagi/mjai/bot`

### settings.json

Expand Down
2 changes: 1 addition & 1 deletion client.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def compose(self) -> ComposeResult:

self.setting_save_button = Button("Save", variant="warning", id="setting_save_button")

self.remove_this_then_you_badluck_for_100years_and_get_hit_by_a_car_then_die = HoverLink("Akagi is developed by shinkuan, and it's Free and Open Sourced on GitHub.\n本程式Akagi由shinkuan開發,在GitHub上完全開源且免費。如果你是付費取得的,你已經被倒賣的騙了,請立即舉報、差評、退款。", "https://github.com/shinkuan/Akagi", id="remove_this_you_die")
self.remove_this_then_you_badluck_for_100years_and_get_hit_by_a_car_then_die = HoverLink("Akagi is Free and Open Sourced on GitHub.\n本程式Akagi在GitHub上完全開源且免費。如果你是付費取得的,你已經被賣家欺騙,請立即舉報、差評、退款。", "https://github.com/shinkuan/Akagi", id="remove_this_you_die")

self.setting_container = ScrollableContainer(
self.port_setting_container,
Expand Down
2 changes: 1 addition & 1 deletion mhm/proto/liqi_pb2.py

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions mjai/bot/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from typing import *
from functools import partial
from itertools import permutations
from .libriichi.mjai import Bot
from .libriichi.consts import obs_shape, oracle_obs_shape, ACTION_SPACE, GRP_SIZE
import riichi

class ChannelAttention(nn.Module):
def __init__(self, channels, ratio=16, actv_builder=nn.ReLU, bias=True):
Expand Down Expand Up @@ -115,9 +114,9 @@ def __init__(self, *, conv_channels, num_blocks, is_oracle=False, version=1):
self.is_oracle = is_oracle
self.version = version

in_channels = obs_shape(version)[0]
in_channels = riichi.consts.obs_shape(version)[0]
if is_oracle:
in_channels += oracle_obs_shape(version)[0]
in_channels += riichi.consts.oracle_obs_shape(version)[0]

norm_builder = partial(nn.BatchNorm1d, conv_channels, momentum=0.01)
actv_builder = partial(nn.Mish, inplace=True)
Expand Down Expand Up @@ -205,7 +204,7 @@ def __init__(self, *, version=1):
match version:
case 1:
self.v_head = nn.Linear(512, 1)
self.a_head = nn.Linear(512, ACTION_SPACE)
self.a_head = nn.Linear(512, riichi.consts.ACTION_SPACE)
case 2 | 3:
hidden_size = 512 if version == 2 else 256
self.v_head = nn.Sequential(
Expand All @@ -216,15 +215,15 @@ def __init__(self, *, version=1):
self.a_head = nn.Sequential(
nn.Linear(1024, hidden_size),
nn.Mish(inplace=True),
nn.Linear(hidden_size, ACTION_SPACE),
nn.Linear(hidden_size, riichi.consts.ACTION_SPACE),
)
case 4:
self.net = nn.Linear(1024, 1 + ACTION_SPACE)
self.net = nn.Linear(1024, 1 + riichi.consts.ACTION_SPACE)
nn.init.constant_(self.net.bias, 0)

def forward(self, phi, mask):
if self.version == 4:
v, a = self.net(phi).split((1, ACTION_SPACE), dim=-1)
v, a = self.net(phi).split((1, riichi.consts.ACTION_SPACE), dim=-1)
else:
v = self.v_head(phi)
a = self.a_head(phi)
Expand Down Expand Up @@ -321,7 +320,7 @@ def sample_top_p(logits, p):
sampled = probs_idx.gather(-1, probs_sort.multinomial(1)).squeeze(-1)
return sampled

def load_model(seat: int) -> Bot:
def load_model(seat: int) -> riichi.mjai.Bot:

# check if GPU is available
if torch.cuda.is_available():
Expand Down Expand Up @@ -356,5 +355,5 @@ def load_model(seat: int) -> Bot:
version= state['config']['control']['version']
)

bot = Bot(engine, seat)
bot = riichi.mjai.Bot(engine, seat)
return bot
2 changes: 1 addition & 1 deletion proto/liqi_pb2.py

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion requirement.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ protobuf==4.25.1
rich==13.7.0
textual==0.46.0
playwright==1.41.0
torch
torch>=2.2.0
--find-links https://github.com/shinkuan/Akagi/releases/expanded_assets/v0.1.0-libriichi
riichi

0 comments on commit 54b4228

Please sign in to comment.