Skip to content

Commit

Permalink
Fix score calculation in 3 player mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimboom7 committed May 22, 2022
1 parent 3c3843f commit 1e7f65c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/ai_offense.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,11 @@ function getHandValues(hand, discardedTile) {
var waits = 0; //Waits when in Tenpai (Or fractions of it when 1 shanten)
var fu = 0;

var kita = 0;
if (getNumberOfPlayers() == 3) {
kita = getNumberOfKitaOfPlayer(0) * getTileDoraValue({ index: 4, type: 3 });
}

var waitTiles = [];
var tileCombinations = []; //List of combinations for second step to save calculation time

Expand Down Expand Up @@ -559,12 +564,12 @@ function getHandValues(hand, discardedTile) {
doraValue += thisDora * factor;
yaku.open += thisYaku.open * factor;
yaku.closed += thisYaku.closed * factor;
expectedScore.open += calculateScore(0, thisYaku.open + thisDora, thisFu) * factor;
expectedScore.closed += calculateScore(0, thisYaku.closed + thisDora, thisFu) * factor;
expectedScore.open += calculateScore(0, thisYaku.open + thisDora + kita, thisFu) * factor;
expectedScore.closed += calculateScore(0, thisYaku.closed + thisDora + kita, thisFu) * factor;
numberOfTotalCombinations += factor;
}

expectedScore.riichi += calculateScore(0, thisYaku.closed + thisDora + 1 + 0.2 + getUradoraChance(), thisFu) * thisWait * factor;
expectedScore.riichi += calculateScore(0, thisYaku.closed + thisDora + kita + 1 + 0.2 + getUradoraChance(), thisFu) * thisWait * factor;
numberOfTotalWaitCombinations += factor * thisWait;
if (!tile1Furiten) {
hand.pop();
Expand Down Expand Up @@ -657,8 +662,8 @@ function getHandValues(hand, discardedTile) {
doraValue += thisDora * combFactor;
yaku.open += thisYaku.open * combFactor;
yaku.closed += thisYaku.closed * combFactor;
expectedScore.open += calculateScore(0, thisYaku.open + thisDora) * combFactor;
expectedScore.closed += calculateScore(0, thisYaku.closed + thisDora) * combFactor;
expectedScore.open += calculateScore(0, thisYaku.open + thisDora + kita) * combFactor;
expectedScore.closed += calculateScore(0, thisYaku.closed + thisDora + kita) * combFactor;
numberOfTotalCombinations += combFactor;
}

Expand Down Expand Up @@ -692,12 +697,7 @@ function getHandValues(hand, discardedTile) {
}

if (baseShanten > 0) { //When not tenpai
expectedScore.riichi = calculateScore(0, yaku.closed + doraValue + 1 + 0.2 + getUradoraChance());
}

if (getNumberOfPlayers() == 3) {
var kita = getNumberOfKitaOfPlayer(0) * getTileDoraValue({ index: 4, type: 3 });
doraValue += kita;
expectedScore.riichi = calculateScore(0, yaku.closed + doraValue + kita + 1 + 0.2 + getUradoraChance());
}

var danger = 0;
Expand Down
4 changes: 4 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,10 @@ function calculateScore(player, han, fu = 30) {
score *= 1.5;
}

if (getNumberOfPlayers() == 3) {
score *= 0.75;
}

return score;
}

Expand Down

0 comments on commit 1e7f65c

Please sign in to comment.