From 60c430e888143e246eecce2788a05084c3aa0600 Mon Sep 17 00:00:00 2001 From: ho94949 Date: Thu, 4 Feb 2021 21:05:50 +0900 Subject: [PATCH] Modified Yacht bug, L/S Straight order --- .gitignore | 1 + README.md | 19 ++++++++++--------- src/calc.cc | 44 ++++++++++++++++++++++++-------------------- src/calc.hh | 13 +++++++++---- src/main.cc | 20 ++++++++++++++++---- src/print.cc | 2 +- src/rule.cc | 24 ++++++++++++------------ 7 files changed, 73 insertions(+), 50 deletions(-) diff --git a/.gitignore b/.gitignore index 8665c50..5aa9506 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,7 @@ eval.bin op.bin +data.bin # Main executable main \ No newline at end of file diff --git a/README.md b/README.md index ba4dda8..77597ce 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ AI of [Yacht Dice](https://en.wikipedia.org/wiki/Yacht_(dice_game)). This AI maximizes expected value of yacht. This AI Do not consider opponent, thus not maximizing winning probability. -Expected score value of Yacht dice game with optimal play is 185.317430, way more than average person playing. +Expected score value of Yacht dice game with optimal play is 191.774369, way more than average person playing. ## Requirement @@ -14,7 +14,7 @@ Expected score value of Yacht dice game with optimal play is 185.317430, way mor ## Rules -Yacht dice game has many variations, and this game uses following rule. +Yacht dice game has many variations, and this game uses following rules. - One, Two, Three, Four, Five, Six - For any combination, score is the sum of dice with chosen number. @@ -23,10 +23,10 @@ Yacht dice game has many variations, and this game uses following rule. - If combination includes four dice showing the same face, score is the sum of all dice. - Full House - If combination is given ans two of one number and three of another, score is the sum of all dice. -- L. Straight - - If combination is 5 consecutive numbers, score is 30. - S. Straight - If combination has 4 consecutive numbers, score is 15. +- L. Straight + - If combination is 5 consecutive numbers, score is 30. - Yacht - If all five dices are showing same face, score is 50. @@ -34,15 +34,16 @@ You can modify these rules in [rule.hh](https://github.com/ho94949/yacht-dice/bl ## Build & Execution -1. Build all `*.cc` files in `src` or use `./compile.sh`. `./main` will be produced in root directory. -2. `./main calc` produces pre-calculation files, `eval.bin` and `op.bin`. (Total 200MB) +1. Build all `*.cc` files in `src`, or just execute `./compile.sh`. If you execute `./compile.sh`, `./main` will be produced in root directory. +2. `./main calc` produces pre-calculation files, `data.bin`. (Total 200MB) 1. Calculation takes 20 minutes, 1.7GB of memory on Intel(R) Core(TM) i5-10400 CPU @ 2.90GHz. - 2. pre-computed `eval.bin` and `op.bin` can be downloaded in "Release" tab. -3. `./main` loads `eval.bin` and `op.bin` if they exists. +3. `./main` loads `data.bin` if they exists. + +Win10 64bit binary and pre-computed `data.bin` can be downloaded in [Releases](https://github.com/ho94949/yacht-dice/releases) tab. ## Usage -This program shows tabular interface of yacht dice game. +This program shows tabular interface of yacht dice game. Score is your earned score, while estimation is expected value of optimal play. - `Input your dice (? more re-rolls)` - You should enter 5 space-separated integer, when dice rolled. - This program shows recommended dice to keep. (In most program, Click can be used to keep dices.) diff --git a/src/calc.cc b/src/calc.cc index aad87cc..e74d773 100644 --- a/src/calc.cc +++ b/src/calc.cc @@ -12,42 +12,46 @@ double dpave[1< score(12); + std::vector score(TOTAL_SUIT); int curval = 0, bonus = 0; - for(int i=0; i<12; ++i) + for(int i=0; i -std::string names[] = {"One", "Two", "Three", "Four", "Five", "Six", "Choice", "Four Card", "Full House", "L.Straight", "S.Straight", "Yacht"}; +std::string names[] = {"One", "Two", "Three", "Four", "Five", "Six", "Choice", "Four Card", "Full House", "S.Straight", "L.Straight", "Yacht"}; void print(int selection, const std::vector& score) { diff --git a/src/rule.cc b/src/rule.cc index 6ff6696..488f1f9 100644 --- a/src/rule.cc +++ b/src/rule.cc @@ -36,16 +36,6 @@ int FullHouse(Dices d) else return 0; } -int LStraight(Dices d) -{ - std::sort(d.begin(), d.end()); - if( d[0] + 1 == d[1] && - d[1] + 1 == d[2] && - d[2] + 1 == d[3] && - d[3] + 1 == d[4] ) return 30; - else return 0; -} - int SStraight(Dices d) { bool a[DICE_NO+1]; @@ -56,12 +46,22 @@ int SStraight(Dices d) else return 0; } +int LStraight(Dices d) +{ + std::sort(d.begin(), d.end()); + if( d[0] + 1 == d[1] && + d[1] + 1 == d[2] && + d[2] + 1 == d[3] && + d[3] + 1 == d[4] ) return 30; + else return 0; +} + int Yacht(Dices d) { - for(int v: d) if(v == d[0]) return 0; + for(int v: d) if(v != d[0]) return 0; return 50; } std::function scoring[TOTAL_SUIT] = { - Ones, Twos, Threes, Fours, Fives, Sixes, Choice, FourCards, FullHouse, LStraight, SStraight, Yacht + Ones, Twos, Threes, Fours, Fives, Sixes, Choice, FourCards, FullHouse, SStraight, LStraight, Yacht }; \ No newline at end of file