jimboom7 / alphajong Goto Github PK
View Code? Open in Web Editor NEWA Mahjong AI for Mahjong Soul
License: GNU General Public License v3.0
A Mahjong AI for Mahjong Soul
License: GNU General Public License v3.0
Can you provide the numerical range of each Parameters?And how high or low values will affect bot.For example, how high the value will drive bot crazy.In addition, which values determine whether bot is riichi or not?I look forward to your answer to my doubts.Thank you.
“jiuzhongjiupai” is Chinese Pinyin of Kanji 九種九牌. That means player can do this operation to restart the round if it already has over 9 types of yaochu at the very beginning.
I just wonder why they not use those words all in Japanese…
bot is west player
bot stopped working after called pon for 4p (probably bot couldn't discard a 4p left because of the rule)
i have been trying to get this script to work for a while now in chrome using tampermonkey and i finally got it to work, but the AI never calls for riichi is this intentional? or did i do something wrong? or do i just not understand the game?
also, i made a code for tampermonkey but didn't want to post it on greaseymonkey since i didn't write the code:
Mahjong AI.user.js.zip
First of all, I would like to thank you for your outstanding project.
I tested the script on a 3 player mahjong and found some problems and strategic errors.
1. AI call pon west wind when seat wind is south. (maybe problem in getSeatWind
function, 3 player mahjong need another function for it)
function getSeatWind(player) {
return ((4 + localPosition2Seat(player) - view.DesktopMgr.Inst.index_ju) % 4) + 1;
}
2. Basically, 3 player mahjong is very aggresive. so AI need another strategy for it.
leftTiles
.3. AI didn't send AboltiveDrawCall
when hand is really bad.
callAboltiveDraw()
, canDoThirteenOrphans
function does not have parentheses.function callAbortiveDraw() { // Kyuushu Kyuuhai, 9 Honors or Terminals in starting Hand
if (!canDoThirteenOrphans) {
sendAbortiveDrawCall();
}
}
However, if AI check hands and there are many pairs of wind tiles and dragon tiles, AI shouldn't call AbortiveDraw even if it's not a ThirteenOrphans strategy. The value of the hand must be determined before calling the function.
3. The offense and defense judgment should be a little more clear.
It is not known whether this is feasible, but some parts need to be optimized.
It is worth considering that the strategy taken by AI changes to some extent depending on the turn by using dynamic parameters rather than static parameters.
when
tilesLeft > 30
, AI more concentrate on offense. (High YAKU_VALUE, DORA_VALUE.)
when someone riichi, AI fold quickly (FOLD_CONSTANT decrease)
etc..
When I meet open quad, it is OK. But if the kan I meet is a closed quad or a kakan(added open quad), the AI will not be able to deal with the situation. The result of it is to wait 25 seconds(20+5) and to discard the tile automatically.
at random intervals when getting a concealed KAN option the ai will get stuck until timeout without discarding or making the kan causing a very long wait with a limited example with ai bots: Mahjong Soul Game Log: https://mahjongsoul.game.yo-star.com/?paipu=jkjols-qvy01326-942c-6795-hada-crhljttts0r1_a823809223_2
l
example with ai bo
I've been testing your new reworked AI, and found some room for an improvement. I haven't used this AI before, but interested in your progress and your concept of AI. Some of those suggestions makes sense on my perspective, but I don't think the bot made a wrong decision.
Info: Master 1, tested on Jade's room
Game log: https://game.mahjongsoul.com/?paipu=jkjpls-sy5u049y-az5b-66id-fkgn-dhjjjpitsutw_a441025507_2
[East 1]
South didn't fold any of the p
tiles, so folding p
looks really dangerous on this side. For an efficiency(shaten) side, dropping hatsu is the best move, but we can't since hatsu is not dropped before. Keeping hatsu in hand almost has a same meaning of folding a full hand(holding only 1 hatsu at late game just means to give up), no-ten is what i prefer to choose on this game.
[South 1, First move]
Bot decided to drop 5p, which looks weird to me(+ trying to keep 1s in hand)
Maybe pairs would work too, but that may raise danger too much?
([RGWh] means Red/Green/White Dragon)
At the moment [R] was discarded, I do have [WhWhWh GG] in hand, which means little/big three dragons might be possible.
But the AI discarded the [R} which is not a normal player would do.
Also at last the AI switched from 2-side wait [3p/6p] to pair wait [5p/G], which is hard to understand for me.
Ai stops when four cards(Kan) are gathered in my hands.
Is there a way to adjust the numerical value so that the calculation can be performed more accurately even if the calculation speed slows down?
这个算役是不是有bug,宝牌为1p,牌型为123s11456788p66s,脚本选择了碰8p听1p和6s。变成无役烦了。
With the 1.3.0 version of the update, the bot appears to show better performance than before.
However, this shows the tendency to use time for calculation every time. (when set to high performance mode)
I was thinking about "Nani Kiru?" at the bottom of the project's description and came up with the following suggestion idea.
If Bot is calculating the Nani Kiru problem to some extent, I think he can calculate the list of tiles with high importance and risk in advance after the player's turn until the next turn. Wouldn't this reduce the computational time required for the player's turn?
Of course, not if someone asks, "Is this necessary?" I think it will take a lot of effort to implement this. However, since most projects are subject to performance-related work after function-related modifications and updates, it would be good if these contents were reflected someday.
Thank you for the great project!
Thanks for Great Update of 1.3.0 v!
There is no big problem, but I came up with a suggestion during the use.
Using Help Mode, visualization and information are very helpful.
However, when making a Richi declaration while using Help Mode, Bot only shows an overview of the log that considers which to be Discarded, and does not seem to show a specific Discard Tile.
Like this :
["6s", "6s", "7s"]
Accept Richii!
(Because I am at outside work now, sorry for this is not accurate Log.)
I think it would be nice if the bot could indicate the Ricii declaration tile recommended.
Like this :
["6s", "6s", "7s"]
Accept Richii with "6s"!
Neither manually nor install via direct download/import. Script seems to have errors.
The log is below. I used a manually built user-script from the call-improvements branch.
##### OWN TURN #####
Debug String: 1s|2058p2244557s33z6s||||6z1s7z4p6s7z|61z19m15z|9p3z5p6z4s4p|0,0,1|1|2|34
Right Player Tenpai Chance: 2.5%, Expected Hand Value: 6000
Left Player Tenpai Chance: 100.0%, Expected Hand Value: 6000
Strategy: Chiitoitsu
Would fold this hand above 64.36 danger for 6s discard.
Tile Danger 553.22 of 🀕: 6s is too dangerous.
Tile Priorities:
Overall: Value Open: <1000> Closed Value: <7200> Riichi Value: <12150> Shanten: <2>
red🀝: 0p: Priority: <-5893.453> Efficiency: <-0.861> Yaku Open: <0.000> Yaku Closed: <2.000> Dora: <2.000> Waits: <0.000> Danger: <19.55>
🀝: 5p: Priority: <-7378.385> Efficiency: <-0.861> Yaku Open: <0.000> Yaku Closed: <2.000> Dora: <2.029> Waits: <0.000> Danger: <17.77>
🀂: 3z: Priority: <-7398.568> Efficiency: <-0.860> Yaku Open: <0.000> Yaku Closed: <2.000> Dora: <3.000> Waits: <0.000> Danger: <0.71>
Discard: 0p
I will post some very strange and unreasonable moves by your bot. For your reference only. The bot can be definitely improved with these problems solved (in some appropriate way).
In this case, the debug string is 5z|577m22447p789s66z3p|||222555z342s||3z5s7z24m2s9p|4z99p7z1m|18p2216m9s3p|234z1s11p7z9m|0,0,0,0|1|1|41
This is the result of priority calculation, the danger of 7p is too high(then it would be bigger than foldThreshold). I don't think it's reasonable because in this case, the flush should be considered into safety calculation. In fact discard 7p is the best choice when I run a AI test(akochan reviewer), it's far more safer than 7s and 8s.
Another issue is the efficiency of 3p should be better than 9s. Although both 3p and 9s are absolutely safe(现物), below is the analysis of akochan.
First off: thank you, this tool has been amazing thanks for your hard work on it.
second: this issue was in 1.1.0 so it might have been patched in 1.2.0 but i had an issue where i got two kitas in a row and the ai called one but discarded the second Mahjong Soul Game Log: https://mahjongsoul.game.yo-star.com/?paipu=jkjnmr-ptxr409v-c68f-6hg8-fijm-ienkmwvswszr_a823809223_2
When I use AI on my mobile device‘s broswer, I often encounter the problem of device lock screen, we may need some logic to keep the mobile device awake.
When I saw this library, I thought maybe we should do this too.
The title says it all.
Example:
Your hand contains a pin sequence: 4 5 (non-dora) 6
The player to your left discards a pin 5 dora.
This might trigger a Chii call and the script then tries to discard the 5 (non-dora). Which is an illegal discard. The game bugs when the script tries to discard it (the tile disappears and everything freezes, needing to reload to rejoin the room).
I've been testing a great project for a while. I am not a mahjong expert, but I am curious about a few things.
2)The AI is not very vigilant about Half Flush and Full Flush.
[Note: I often use 3P mode, so I don't know if this suggestion is valid for 4P mode.]
(I haven't read all the code.) For example, when another player declare pong, the danger level goes up, but it doesn't seem to be able to determine that anything else is a bit safer if they were the same type.
I think this is a difficult problem because the danger level is not given to each opposing player, but just taking this into account would make it more efficient in 3P mode.
The bot often take more than 5 seconds to finish a turn, this didnt happen in 1.0.4 and before
Would it be possible for the AI to work under the option of three player rooms?
Many thanks in advance.
First of all, thank the author very much. This version can play 13 orphans.
but, when I play 3P-Mahjong with it.The hand in the first round looks like 13 orphans,AI just North replacing,that should have been a tsumo.
debug 2z|9m13p18899s234567z|||||||0,0,0|1|1|54
i don't know how ;-;
it will pop out AFK detection windows on firefox and activate auto draw & discard for you makes you lose the game
For example, if you have a starting hand, such as 24478m2p247s12z, the bot preferentially throws away the z-tiles.
This is an efficient approach, but it's like giving up a hand that can be safe later in a real game or a hand that can be Yaku.
(especially in the case of double east double south or our wind tile is only 1 in start hand.)
The method of making efficiency-oriented cards is effective in low tiers, but it is seen as reducing the number of cases that can be won with a rather low defense in the Gold-Jade section. (In particular, Damaten after middle stage of game and Richie of other players)
I don't have an exact idea how to deal with this, but I hope you see it as an approach that can be referred to for future development.
I wonder how BOT predicts the loss composition after another player declares a call.
For example, if there is a player who calls 999s / 999p, it is generally expected to be a Terminal or Honor in each set and is wary of creating a risk card to compensate for it.
(Determine if it is possible to throw away tiles such as 23/78 mps and z-tiles.)
Sometimes, however, BOT tends to cut its teeth too boldly, which seems to be less careful after another player's call raises the Danger Level.
After this process, BOT takes the Fold strategy in quite a few cases. However, since ztiles that can be considered safety pads have already been discarded without damaging their hands in connection with No. 1, they are often deducted from No-ten even if they are not directly Ron.
Judgment of offense and defense is an important issue in Mahjong. However, the bot raises his hand with 1,000 points and shows aggressive behavior despite Oya's statistical announcement of Richie with an average of 5,200 points.
In some cases, this can be passed safely, but in many cases, it results in a loss of points.
In particular, it often appears when it first has two wind tiles or 5,6,7z, so it immediately calls.
I didn't come up with an idea to deal with direct technology related to development, but as a person who loves this project, I wrote a long opinion.
I hope this opinion will be helpful for future development.
请问RIICHI_TILES_LEFT和WAITS_FOR_RIICHI两个数值大小的具体含义是什么?我是新手,如有打扰,甚是抱歉
Any strategy change or more aggressive for points?
Say rank 4th in the last round, Winning or Ron a low value is not making sense.
Or strategy to avoid furiten or sacred discard? sometime this happens
Structure of the folder
Content of the json
Do I have to combine all scripts into one file?
如题。
At brach experimental-ai-core-rework.
My hand is closed, but AI think is open, so it will accept call by mistack
I add some log to locate the bug.
-- setData change isCloesd to true
##### OWN TURN #####
Debug String: 8p|45777m123078p22s||222z|111z||3z1s9m7z4s|6437z19p|9m45z8s2m16s|6p6z9m514z9p|0,0,0,0|1|1|45
Current State: dora:🀠|hand:🀊🀋🀍🀍🀍🀙🀚🀛red🀝🀟🀠🀑🀑|call[0]:|call[1]:🀁🀁🀁|call[2]:🀀🀀🀀|call[3]:|discards[0]:🀂🀐🀏🀄🀓|discards[1]:🀅🀃🀂🀄🀙🀡|discards[2]:🀏🀃🀆🀗🀈🀐🀕|discards[3]:🀞🀅🀏🀆🀀🀃🀡|riichi:0,0,0,0|seatWind:1|roundWind:1|tilesLeft:45
Current Danger Level: 7.889356778670876
Strategy: General
Consider call on 9p
-- calculateFu change isclosed to false
-- calculateFu change isclosed to false
... much more calculateFu isclosed to false
-- calculateFu change isclosed to false
-- calculateFu change isclosed to false
Combination found: 7p|8p
crt isCloesd false
Call accepted because hand is already open!
I think it should reset isClosed
value after calculateFu
.
Line 591 in 1ab5172
Displaying statistics helping users to understand what's the bot thinking and how is these decision are made in real time.
So users can adjusting parameters in real time to fine tune the bot,
Also to find out whether the bot making wrong or right decision so it can be debug easily instead of watching replay.
Here's a project from neighborhood what i using to understand what's the bot thinking for reference.
I want you to add automatic participation in all rooms
Take the example hand "1155m 1477p 449s 22z + 9s". In this case, the player is in tenpai for chiitoitsu, ready for riichi. Assuming there are the same number of waiting tiles left (unrevealed), as a human, the obvious tile to discard would be 4p since there is a significantly higher chance that opponents would discard 1p (for both safety and hand efficiency).
Therefore, whenever there is a situation where the player can choose a single waiting tile (tanki, or kanchan from ryankan) in tenpai, there should be a priority list to determine final machi tiles. (e.g. honor tiles that are only discarded once > 1, 9 > 2, 8 > shouhai honor tiles > 3-7)
##### OWN TURN #####
Debug String: 4p|33344588p45677s||111z||919m67z1p9s9p1m|27z9m2s1m4s1p63z24p|9m9p356z1m2z2p9s6z|0,0,0|3|1|21
Right Player Tenpai Chance: 50.2%, Expected Hand Value: 17721
Left Player Tenpai Chance: 11.5%, Expected Hand Value: 11823
Strategy: General
Consider call on 4p
Could not find combination. Call declined!
##### OWN TURN #####
Debug String: 7s6z|35678899p345s55z|||8888s|9m21z1p6s7z|26z91m3z9p|371z9m9s1m|0,0,0|2|2|33
Right Player Tenpai Chance: 9.5%, Expected Hand Value: 8411
Left Player Tenpai Chance: 17.9%, Expected Hand Value: 19394
Strategy: General
Consider call on 9p
Combination found: 9p|9p
Call accepted because it reduces shanten!
##### OWN TURN #####
Debug String: 7s6z|356788p345s55z|999p||8888s|9m21z1p6s7z|26z91m3z|371z9m9s1m|0,0,0|2|2|33
Right Player Tenpai Chance: 7.6%, Expected Hand Value: 8186
Left Player Tenpai Chance: 29.2%, Expected Hand Value: 19394
Strategy: General
Would fold this hand above 553.67 danger for 3p discard.
Tile Danger 599.66 of 🀛: 3p is too dangerous.
Hand is very dangerous, full fold.
Fold Tile Priorities:
Overall: Value Open: <481> Closed Value: <481> Riichi Value: <2208> Shanten: <1>
🀆: 5z: Priority: <2.758> Efficiency: <0.020> Yaku Open: <0.002> Yaku Closed: <0.002> Dora: <1.000> Waits: <0.197> Danger: <53.87> 2
🀠: 8p: Priority: <13.420> Efficiency: <0.070> Yaku Open: <0.150> Yaku Closed: <0.150> Dora: <1.000> Waits: <0.704> Danger: <258.48>
Discard: 5z
Thank you for a good project. There is a question during the play of the script, so I inevitably post the question here.
I'm playing scripts on two servers (global, Japan) and occasionally witness the bot making the wrong choice.
Please look at the below, console log from the Edge and MJ Log. At the end of the game, the bot saw another player's discard 4p leach.
However, bot was discard 7p instead of 4p in the hand.
This resulted in not only being Ron by that player, but also allowing One-shot.
There are questions about the bot's judgment, and I would like to ask if it is possible to improve.
[MJ Log]
Round : South 2
https://mahjongsoul.game.yo-star.com/?paipu=jkjomv-1yy5550x-6d42-659a-fhnj-pmfmiosopppz_a830397198_2
[Console Log]
userscript.html?name=AlphaJong.user.js&id=928ad15b-d66b-4a59-97ba-8934f6b56f4d:1161 Waiting for own turn, sleep 1 second.
userscript.html?name=AlphaJong.user.js&id=928ad15b-d66b-4a59-97ba-8934f6b56f4d:1161 ##### OWN TURN #####
userscript.html?name=AlphaJong.user.js&id=928ad15b-d66b-4a59-97ba-8934f6b56f4d:1161 Debug String: 6s|345666m334677p33s|||||515z9p199m|5z1m12z9p64z7p|6z21m26z1p7z2p|437z9m45s3m4p|0,0,0,1|4|2|38
userscript.html?name=AlphaJong.user.js&id=928ad15b-d66b-4a59-97ba-8934f6b56f4d:1161 Current Danger Level: 50
userscript.html?name=AlphaJong.user.js&id=928ad15b-d66b-4a59-97ba-8934f6b56f4d:1161 Strategy: General
userscript.html?name=AlphaJong.user.js&id=928ad15b-d66b-4a59-97ba-8934f6b56f4d:1161 Would fold this hand below 0.73 safety.
userscript.html?name=AlphaJong.user.js&id=928ad15b-d66b-4a59-97ba-8934f6b56f4d:1161 Tile Priorities:
2userscript.html?name=AlphaJong.user.js&id=928ad15b-d66b-4a59-97ba-8934f6b56f4d:1161 7p: Value: <1.629> Efficiency: <2.683> Yaku Open: <1.000> Yaku Closed: <1.000> Dora: <0.000> Waits: <0.736> Safety: 0.94
userscript.html?name=AlphaJong.user.js&id=928ad15b-d66b-4a59-97ba-8934f6b56f4d:1161 4p: Value: <1.613> Efficiency: <2.659> Yaku Open: <1.004> Yaku Closed: <1.004> Dora: <0.000> Waits: <0.389> Safety: 1.00
userscript.html?name=AlphaJong.user.js&id=928ad15b-d66b-4a59-97ba-8934f6b56f4d:1161 Discard: 7p
And the bots seem to tend overdo call when it's on the East wind(Oya) especially when there's no Yaku and hand contain 2 tile of W/G/R dragons. It seems to result in the playing in a tough direction, leaving out hand would be vulnerable in defense.
And this is just suggestion for bot's Tenpai situation.
How about when bot made Tenpai with high value (ex, over 3 han), not declare leach and waiting tile with Damaten strategy?
Thanks for good project again, I hope my opinion will help bot performance improvement.
Hello. I use Tampermonkey with Chrome. I found that variable isPlayerRiichi
in parameters.js and function isPlayerRiichi()
in api.js have the same name and Chrome throw an exception. I commented out isPlayerRiichi
variable (is it used?) and now it is working as expected.
Thank you for this script. I use it for gaining event points when very busy at work.
Hi, I have tested your script for a while and here's some suggestion on general strategy
-snip-
East 3
Turn 7: 788m 4678p 1256s 66z +3z
1s&2s is significantly better than 8m
Turn 10: 7m 34678p 12356s 66z +6z?
Is it really wise to Pong 6z?
East 4
4579m 3356p 779s 44z +5p
Turn 6&7: 4 pairs already, 7 pairs could be taken into consideration.
-snip-
East 3.0
Turn 8: 11m 2489p 6677s 777z +8p
Since the AI is not running 7pairs, it is weird to cut off 7z
South 2
Turn 7: 14557789p 34678s + 0p?
Pong 5p, No-Yaku except Tanyao.
Thanks for your reading.
I don't get points because I focus on defense. Thank you for letting me know about the offensive setting.
There seems to be an issue autostarting games since the latest update to the game.
I ran some WWYD puzzles as testcases, and I found some discrepancies between the bot and the solutions.
34567m2388p5779s1p; dora 2p
Bot returns 5s, but should be 7s because of higher Pinfu chance.
678889m40579p33s8p; dora 9s
Bot returns 9m, but should be 5p because of higher tile acceptance.
112m223677888p06s; dora 1p
Bot returns 1m, but should be 2m because of higher tile acceptance.
556m133345678p22s; dora 7p
Bot returns 1p, but should be 5m again because of higher tile acceptance.
345m233444p0667s4m; dora 9s
Bot returns 4m, but should be 3p. Tile acceptance again.
Judging by the differences, it seems like maybe there's something off about the ukeire formula, or maybe Yakus are being weighted too heavily.
Is there a build tool to pack all js source files to the release one file? I'm new to js, sorry to ask the stupid question.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.