Skip to content

Commit

Permalink
Merge pull request #23 from shinkuan/dev
Browse files Browse the repository at this point in the history
v1.3.0
  • Loading branch information
shinkuan authored Feb 4, 2024
2 parents c53bd7f + 08e253d commit 4dfa512
Show file tree
Hide file tree
Showing 18 changed files with 609 additions and 1,176 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@
/players/bot.zip
/common/proxinject
/log
/account
/account
/config.json
/mjai/bot/mortal.pth
/mjai/bot/libriichi.*
/mjai/bot_3p
81 changes: 34 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,65 +35,46 @@ https://github.com/shinkuan/RandomStuff/assets/35415788/ce1b598d-b1d7-49fe-a175-

## Setup

### Installation, I suggest you watch the video.
### Installation.

### Some content are outdated:
- You don't need to install mjai now.
- You need to install chromium if you want to use playwright: `playwright install chromium`

[YouTube Video for you to follow.](https://youtu.be/ZN3qbMyZeus)
[YouTube Video for you to follow.](https://youtu.be/NdAULJgBJ-U)

### You will need:
1. Docker
2. Proxifier or something that can redirect connection to mitmproxy.
1. __Remember to trust mitmproxy's Certificate!!!__ Don't know how? Google it.
3. A `bot.zip` that contains the AI. [Examples](https://github.com/smly/mjai.app/tree/main/examples)
4. (Optional, Recommend) Use Windows Terminal to open client.py for a nice looking TUI.

__Don't know how to make a bot.zip yourself? Don't worry!__

__Get bot.zip at [Discord](https://discord.gg/Z2wjXUK8bN)__

### Docker:
1. Install Docker on your PC
2. `docker pull smly/mjai-client:v3`
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.

__Get mortal.pth at [Discord](https://discord.gg/Z2wjXUK8bN)__
1. Go to #verify and click the ✅ reaction.
2. Go to #bot-zip
3. Download a bot you like.
4. Extract the zip.
5. And mortal.pth is there.

### Akagi:

Download `install_akagi.ps1` at [Release](https://github.com/shinkuan/Akagi/releases/latest)

1. Place `install_akagi.ps1` at the folder you want to install Akagi.
2. Open Powershell as admin.
3. Go to the folder.
4. To prevent your PC restrict from executing powershell script, run:
- `Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass`
5. Run `install_akagi.ps1`
6. put `bot.zip` into ./players folder

### if `install_akagi.ps1` not working for you:

Follow the [video](https://youtu.be/ZN3qbMyZeus).

1. `git clone this`
2. `cd into this repo`
3. Create a Python Virtual Env `python -m venv venv`
4. Activate it. `.\venv\Scripts\activate`
5. `pip install -r requirement.txt`
6. `playwright install chromium`
7. put `bot.zip` into ./players folder

### Run

After you __activate the venv__:
1. Configure your setting at `setting.json`
2. `python mitm_playwright.py` or `python mitm.py`
3. `python client.py`
1. Put `install_akagi.ps1` at the location you want to install Akagi.
2. Open **Powershell** as **Administrator**
3. cd in to the directory
4. Run: `Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass`
5. Run: `install_akagi.ps1`
6. Open mitmproxy if this is your first time using it.
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`

### settings.json

- `Unlocker`: Decide to use [MajsoulUnlocker](https://github.com/shinkuan/MajsoulUnlocker) or not.
- `v10`: If your Majsoul client in still in v0.10.x and you want to use MajsoulUnlocker, set it to true.
- `Autoplay`: Autoplay.
- `Helper`: To use [mahjong-helper](https://github.com/EndlessCheng/mahjong-helper) or not
- `Autohu`: Auto Ron.
- `Port`:
- `MITM`: The MITM Port, you should redirect Majsoul connection to this port.
- `XMLRPC`: The XMLRPC Port.
Expand Down Expand Up @@ -126,7 +107,7 @@ On top right is the MJAI Messages, this is the message our bot sent back to us,

Then below is our tehai, it is composed using unicode characters.

Bottom left is the settings. (WIP, currently you should change settings via settings.json)
Bottom left is the settings.

Bottom right is the bot's action.

Expand All @@ -145,6 +126,8 @@ Following guide can minimum the probility of account suspension.
### There is no way to guarantee 100% no account suspension currently.

# TODO
- [x] 3 Player Mahjong
- Already done, but not planned to release yet.
- [x] Change Setting inside application.
- [x] Autoplay
- [ ] Auto use stickers to make opponent think we are not a bot.
Expand Down Expand Up @@ -179,7 +162,7 @@ Following guide can minimum the probility of account suspension.

ETH Mainnet: 0x83095C4355E43bDFe9cEf2e439F371900664D41F

Paypal or Others: Maybe? Contact me.
Paypal or Others: Contact me on Discord.

You can find me at [Discord](https://discord.gg/Z2wjXUK8bN).

Expand All @@ -204,8 +187,12 @@ Next, you can find me on Discord, where I will assign you a donor role.

# Special Thanks

[Equim-chan/Mortal](https://github.com/Equim-chan/Mortal)

[Majsoul Mod Plus](https://github.com/Avenshy/majsoul_mod_plus)

[mahjong-helper](https://github.com/EndlessCheng/mahjong-helper)

[MahjongRepository/mahjong_soul_api](https://github.com/MahjongRepository/mahjong_soul_api)

[smly/mjai.app](https://github.com/smly/mjai.app)
Expand Down
90 changes: 34 additions & 56 deletions README_CH.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,64 +35,43 @@ https://github.com/shinkuan/RandomStuff/assets/35415788/ce1b598d-b1d7-49fe-a175-

### 安裝

[點我到Youtube觀看安裝影片](https://youtu.be/ZN3qbMyZeus)
[點我到Youtube觀看安裝影片](https://youtu.be/NdAULJgBJ-U)

在開始前,你需要以下東西:
1. Docker
2. Proxifier或任何可以將雀魂連線導向到MITM Proxy的工具。
1. __記得要信任mitmproxy的憑證!!!__ 不要問我怎麼做。去問Google。
3. 一個`bot.zip`[Examples](https://github.com/smly/mjai.app/tree/main/examples)
4. (Optional) 推薦使用Windows Terminal,以獲得預期中的UI效果。
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

__不知道如何製作bot.zip嗎?不用擔心!__
__[Discord](https://discord.gg/Z2wjXUK8bN)下載我提供的mortal.pth__
1. 到 #verify 頻道點擊 ✅ 驗證身分.
2. 到 #bot-zip
3. 選一個你喜歡的bot下載
4. 解壓縮

__[Discord](https://discord.gg/Z2wjXUK8bN)下載我提供的bot.zip__

Docker:
1. 安裝Docker Desktop
2. 在cmd輸入`docker pull smly/mjai-client:v3`

Akagi:

### 影片部分內容已過時:
- 現在已經有自動化安裝 `install_akagi.ps1`
- 現在你不再需要安裝mjai
- 如果你想使用playwright記得安裝chromium: `playwright install chromium`
### Akagi:

[Release](https://github.com/shinkuan/Akagi/releases/latest)下載`install_akagi.ps1`

1.`install_akagi.ps1`放到你想安裝的位置
2. 以管理員開啟Powershell
3. cd到安裝位置
4. 有些電腦會限制Powershell腳本的執行,這也是為什麼我們需要管理員權限,執行以下指令以讓腳本能夠運行:
- `Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass`
5. 執行 `install_akagi.ps1`
6.`bot.zip`放入 ./players

### 如果 `install_akagi.ps1` 有問題:

建議你跟著[影片](https://youtu.be/ZN3qbMyZeus)中的教學安裝。

1. 下載這個Repo到你電腦內,或在cmd輸入`git clone <repo>`
2. 在cmd輸入`cd Akagi`進到資料夾
3. 創建一個Python venv `python -m venv venv`
4. 啟動它. `.\venv\Scripts\activate`
5. `pip install -r requirement.txt`
6. `playwright install chromium`
7. put `bot.zip` into ./players folder

### 執行

**啟動venv**後:
1.`setting.json`調整設定
2. `python mitm_playwright.py` or `python mitm.py`
3. `python client.py`
1.`install_akagi.ps1` 放在您想安裝Akagi的位置。
2.**管理員**身份打開 **Powershell**
3. cd 到該目錄
4. 執行: `Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass`
5. 執行: `install_akagi.ps1`
6. 如果這是您第一次使用mitmproxy,請打開它。
7. 關閉它。
8. cd 到用戶主目錄 `~/.mitmproxy`
9. 安裝證書。
10.`libriichi` 放入 `./Akagi/mjai/bot` 並將其重新命名為 `libriichi`
11.`mortal.pth` 放入 `./Akagi/mjai/bot`

### settings.json

- `Unlocker`: 使用 [MajsoulUnlocker](https://github.com/shinkuan/MajsoulUnlocker)
- `v10`: 如果你的客戶端還在v0.10.x版本而且你想要使用MajsoulUnlocker,設為true
- `Autoplay`: 自動打牌.
- `Helper`: [mahjong-helper](https://github.com/EndlessCheng/mahjong-helper)
- `Autohu`: Auto Ron.
- `Port`:
- `MITM`: MITM Port, 你應該將雀魂連線導向到這個Port.
- `XMLRPC`: The XMLRPC Port.
Expand Down Expand Up @@ -125,7 +104,7 @@ LiqiProto訊息隨後被轉錄為mjai格式並發送給機器人。

然後下方是我們的手牌,它是使用Unicode字符組成的。

左下角是設置。(目前還未完成,你應該通過settings.json來更改設置)
左下角是設置。

右下角是機器人的動作。

Expand All @@ -146,9 +125,10 @@ LiqiProto訊息隨後被轉錄為mjai格式並發送給機器人。
### 目前沒有任何辦法保證完全不封號。

# TODO

- [x] 三麻模式
- 已完成,但尚未決定公布。
- [x] 在應用程式內更改Setting。
- [x] 自動打牌 - (能運作,但 ____ 穩定)
- [x] 自動打牌
- [ ] 自動使用貼圖,讓對手認為我們不是機器人。
- [ ] 在settings.json中添加隨機時間,讓用戶選擇他們想要的時間。
- [ ] 混合多個AI的決策,讓我們看起來更像人類,而不是完美的機器人。
Expand Down Expand Up @@ -181,17 +161,11 @@ LiqiProto訊息隨後被轉錄為mjai格式並發送給機器人。

ETH Mainnet: 0x83095C4355E43bDFe9cEf2e439F371900664D41F

Paypal或其他: Maybe? Contact me.
Paypal或其他: 到Discord找我

You can find me at [Discord](https://discord.gg/Z2wjXUK8bN).

### 斗內後我能得到什麼?

首先,非常感謝您願意支持作者。

我會優先考慮捐款者的意見,比如功能要求和錯誤修復。

接下來,您可以在Discord上找到我,我會給您指定一個捐款者身分組。
![image](https://github.com/shinkuan/RandomStuff/assets/35415788/2b500d5c-21cd-422c-9684-50477835fe13)

<!-- 未來計劃:
Expand All @@ -207,8 +181,12 @@ You can find me at [Discord](https://discord.gg/Z2wjXUK8bN).

# Special Thanks

[Equim-chan/Mortal](https://github.com/Equim-chan/Mortal)

[Majsoul Mod Plus](https://github.com/Avenshy/majsoul_mod_plus)

[mahjong-helper](https://github.com/EndlessCheng/mahjong-helper)

[MahjongRepository/mahjong_soul_api](https://github.com/MahjongRepository/mahjong_soul_api)

[smly/mjai.app](https://github.com/smly/mjai.app)
Expand Down
15 changes: 11 additions & 4 deletions action.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
(10.875, 5.9), # 2 1 0
(8.6375, 5.9), #
(6.4 , 5.9),
(10.875, 4.8), # Not used
(8.6375, 4.8), # Not used
(6.4 , 4.8), # Not used
],
"candidates": [
(3.6625, 6.3), # (-(len/2)+idx+0.5)*2+5
Expand Down Expand Up @@ -71,7 +74,8 @@
2, # Reach # Self Discard
1, # Zimo # Self Discard
1, # Rong # Opponent Discard
4, # Ryukyoku # Self Discard
5, # Ryukyoku # Self Discard
4, # Nukidora # Self Discard
]

ACTION2TYPE = {
Expand All @@ -82,6 +86,7 @@
"hora": 9,
#^^^^^^^^^^^^^^^^Opponent Discard^^^^^^^^^^^^^^^^
"ryukyoku": 10,
"nukidora": 11,
"ankan": 4,
"kakan": 6,
"reach": 7,
Expand Down Expand Up @@ -110,8 +115,8 @@ def do_autohu(self):

def decide_random_time(self):
if self.isNewRound:
return random.uniform(2.3, 2.5)
return random.uniform(0.3, 1.2)
return random.uniform(3.5, 4.5)
return random.uniform(1.0, 3.2)


def click_chiponkan(self, mjai_msg: dict | None, tehai: list[str], tsumohai: str | None):
Expand Down Expand Up @@ -144,6 +149,8 @@ def click_chiponkan(self, mjai_msg: dict | None, tehai: list[str], tsumohai: str
for idx, operation in enumerate(latest_operation_list_temp):
if operation['type'] == ACTION2TYPE[mjai_msg['type']]:
self.page_clicker(LOCATION['actions'][idx])
self.do_autohu()
self.isNewRound = False
break

if mjai_msg['type'] == 'reach':
Expand Down Expand Up @@ -280,7 +287,7 @@ def mjai2action(self, mjai_msg: dict | None, tehai: list[str], tsumohai: str | N
time.sleep(dahai_delay)
self.click_dahai(mjai_msg, tehai, tsumohai)
return
if mjai_msg['type'] in ['none', 'chi', 'pon', 'daiminkan', 'ankan', 'kakan', 'hora', 'reach', 'ryukyoku']:
if mjai_msg['type'] in ['none', 'chi', 'pon', 'daiminkan', 'ankan', 'kakan', 'hora', 'reach', 'ryukyoku', 'nukidora']:
time.sleep(2)
self.click_chiponkan(mjai_msg, tehai, tsumohai)
# kan can have multiple candidates too! ex: tehai=1111m 1111p 111s 11z, tsumohai=1s
Expand Down
Loading

0 comments on commit 4dfa512

Please sign in to comment.