Skip to content

Commit

Permalink
Make honba customisable via Ruleset settings in Event
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesterboxboy committed Jan 14, 2025
1 parent 1997e30 commit bbf58d2
Show file tree
Hide file tree
Showing 20 changed files with 146 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
.phpunit.result.cache
php-errors.log
tmp/*.log
package-lock.json

.env.e2e

Expand Down
27 changes: 27 additions & 0 deletions Common/generated/Common/RulesetConfig.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Common/generated/GPBMetadata/Proto/Atoms.php
Binary file not shown.
1 change: 1 addition & 0 deletions Common/proto/atoms.proto
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ message RulesetConfig {
repeated int32 yaku_with_pao = 35;
bool with_yakitori = 36;
int32 yakitori_penalty = 37;
int32 honba_value= 38;
}

// Generics
Expand Down
10 changes: 6 additions & 4 deletions Common/rulesets/ema.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Common;

require_once __DIR__ . '/../YakuMap.php';
Expand All @@ -25,15 +26,16 @@

return (new RulesetConfig())
->setUma((new Uma())
->setPlace1(15000)
->setPlace2(5000)
->setPlace3(-5000)
->setPlace4(-15000)
->setPlace1(15000)
->setPlace2(5000)
->setPlace3(-5000)
->setPlace4(-15000)
)
->setUmaType(UmaType::UMA_TYPE_UMA_SIMPLE)
->setEqualizeUma(true)
->setWithWinningDealerHonbaSkipped(false)
->setOka(0)
->setHonbaValue(300)
->setReplacementPlayerFixedPoints(-15000)
->setReplacementPlayerOverrideUma(-15000)
->setAllowedYaku(YakuMap::listExcept([
Expand Down
2 changes: 2 additions & 0 deletions Common/rulesets/jpmlA.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Common;

require_once __DIR__ . '/../YakuMap.php';
Expand Down Expand Up @@ -49,6 +50,7 @@
->setEqualizeUma(true)
->setWithWinningDealerHonbaSkipped(false)
->setOka(0)
->setHonbaValue(300)
->setReplacementPlayerFixedPoints(-15000)
->setReplacementPlayerOverrideUma(-15000)
->setAllowedYaku(YakuMap::listExcept([
Expand Down
10 changes: 6 additions & 4 deletions Common/rulesets/rrc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Common;

require_once __DIR__ . '/../YakuMap.php';
Expand All @@ -25,15 +26,16 @@

return (new RulesetConfig())
->setUma((new Uma())
->setPlace1(15000)
->setPlace2(5000)
->setPlace3(-5000)
->setPlace4(-15000)
->setPlace1(15000)
->setPlace2(5000)
->setPlace3(-5000)
->setPlace4(-15000)
)
->setUmaType(UmaType::UMA_TYPE_UMA_SIMPLE)
->setEqualizeUma(true)
->setWithWinningDealerHonbaSkipped(false)
->setOka(0)
->setHonbaValue(300)
->setReplacementPlayerFixedPoints(-15000)
->setReplacementPlayerOverrideUma(-15000)
->setAllowedYaku(YakuMap::listExcept([
Expand Down
10 changes: 6 additions & 4 deletions Common/rulesets/tenhounet.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Common;

require_once __DIR__ . '/../YakuMap.php';
Expand All @@ -25,15 +26,16 @@

return (new RulesetConfig())
->setUma((new Uma())
->setPlace1(15000)
->setPlace2(5000)
->setPlace3(-5000)
->setPlace4(-15000)
->setPlace1(15000)
->setPlace2(5000)
->setPlace3(-5000)
->setPlace4(-15000)
)
->setUmaType(UmaType::UMA_TYPE_UMA_SIMPLE)
->setEqualizeUma(false)
->setWithWinningDealerHonbaSkipped(false)
->setOka(20000)
->setHonbaValue(300)
->setReplacementPlayerFixedPoints(-15000)
->setReplacementPlayerOverrideUma(-15000)
->setAllowedYaku(YakuMap::listExcept([
Expand Down
10 changes: 6 additions & 4 deletions Common/rulesets/wrc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Common;

require_once __DIR__ . '/../YakuMap.php';
Expand All @@ -25,15 +26,16 @@

return (new RulesetConfig())
->setUma((new Uma())
->setPlace1(15000)
->setPlace2(5000)
->setPlace3(-5000)
->setPlace4(-15000)
->setPlace1(15000)
->setPlace2(5000)
->setPlace3(-5000)
->setPlace4(-15000)
)
->setUmaType(UmaType::UMA_TYPE_UMA_SIMPLE)
->setEqualizeUma(true)
->setWithWinningDealerHonbaSkipped(false)
->setOka(0)
->setHonbaValue(300)
->setReplacementPlayerFixedPoints(-15000)
->setReplacementPlayerOverrideUma(-15000)
->setAllowedYaku(YakuMap::listExcept([
Expand Down
17 changes: 17 additions & 0 deletions Forseti/app/clients/proto/atoms.pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ export interface RulesetConfig {
maxPenalty: number;
minPenalty: number;
oka: number;
honbaValue: number
penaltyStep: number;
replacementPlayerFixedPoints: number;
replacementPlayerOverrideUma: number;
Expand Down Expand Up @@ -7720,6 +7721,7 @@ export const RulesetConfig = {
maxPenalty: 0,
minPenalty: 0,
oka: 0,
honbaValue: 0,
penaltyStep: 0,
replacementPlayerFixedPoints: 0,
replacementPlayerOverrideUma: 0,
Expand Down Expand Up @@ -7851,6 +7853,9 @@ export const RulesetConfig = {
if (msg.yakitoriPenalty) {
writer.writeInt32(37, msg.yakitoriPenalty);
}
if (msg.honbaValue) {
writer.writeInt32(38, msg.honbaValue);
}
return writer;
},

Expand Down Expand Up @@ -8020,6 +8025,10 @@ export const RulesetConfig = {
msg.yakitoriPenalty = reader.readInt32();
break;
}
case 38: {
msg.honbaValue = reader.readInt32();
break;
}
default: {
reader.skipField();
break;
Expand Down Expand Up @@ -14400,6 +14409,7 @@ export const RulesetConfigJSON = {
maxPenalty: 0,
minPenalty: 0,
oka: 0,
honbaValue: 0,
penaltyStep: 0,
replacementPlayerFixedPoints: 0,
replacementPlayerOverrideUma: 0,
Expand Down Expand Up @@ -14537,6 +14547,9 @@ export const RulesetConfigJSON = {
if (msg.yakitoriPenalty) {
json["yakitoriPenalty"] = msg.yakitoriPenalty;
}
if (msg.honbaValue) {
json["honbaValue"] = msg.honbaValue;
}
return json;
},

Expand Down Expand Up @@ -14669,6 +14682,10 @@ export const RulesetConfigJSON = {
if (_oka_) {
msg.oka = protoscript.parseNumber(_oka_);
}
const _honbaValue_ = json["honbaValue"] ?? json["honba_value"];
if ( _honbaValue_ ) {
msg.honbaValue = protoscript.parseNumber(_honbaValue_);
}
const _penaltyStep_ = json["penaltyStep"] ?? json["penalty_step"];
if (_penaltyStep_) {
msg.penaltyStep = protoscript.parseNumber(_penaltyStep_);
Expand Down
8 changes: 8 additions & 0 deletions Forseti/app/pages/OwnedEventsEdit/RulesetSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ export const RulesetSettings: React.FC<RulesetSettingsProps> = ({ form, i18n })
min={0}
{...form.getInputProps('ruleset.oka')}
/>
<NumberInput
icon={<IconCash size='1rem' />}
label={i18n._t('Honba Value')}
description={i18n._t( 'Value of one honba stick')}
defaultValue={300}
min={0}
{...form.getInputProps('ruleset.honbaValue')}
/>
<UmaSelect form={form} i18n={i18n} />
<Checkbox
label={i18n._t('Equalize uma')}
Expand Down
1 change: 1 addition & 0 deletions Forseti/app/pages/OwnedEventsEdit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const OwnedEventsEdit: React.FC<{ params: { id?: string } }> = ({ params:
endingPolicy: EndingPolicy.ENDING_POLICY_EP_UNSPECIFIED,
startRating: 0,
startPoints: 30000,
honbaValue: 300,
replacementPlayerFixedPoints: -15000, // tourn
withYakitori: false,
yakitoriPenalty: 0,
Expand Down
2 changes: 1 addition & 1 deletion Mimir/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ clean_test_db:
.PHONY: enable_debug
enable_debug:
@echo -ne "zend_extension=xdebug.so\n \
xdebug.mode=debug\n \
xdebug.mode=develop,debug\n \
xdebug.client_host=172.17.0.1\n \
xdebug.client_port=9001\n" > /etc/php83/conf.d/50_xdebug.ini
$(shell kill -SIGUSR2 `ps ax | grep php-fpm | grep master | awk '{print $$1}'`)
Expand Down
29 changes: 16 additions & 13 deletions Mimir/src/helpers/PointsCalc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Mimir;

class PointsCalc
Expand Down Expand Up @@ -76,6 +77,7 @@ public static function ron(
int $totalRiichiInRound = 0,
): array {
self::resetPaymentsInfo();
$honbaValue = $rules->rules()->getHonbaValue();
$pointsDiff = self::_calcPoints($rules, $han, $fu, false, $isDealer);

if (empty($winnerId) || empty($loserId)) {
Expand Down Expand Up @@ -130,14 +132,14 @@ public static function ron(
if ($rules->rules()->getDoubleronHonbaAtamahane() && $closestWinner) {
// on tenhou we had to give all honba sticks to closest winner only
if ($winnerId == $closestWinner) {
$currentScores[$winnerId] += 300 * $honba;
$currentScores[$loserId] -= 300 * $honba;
self::$_lastPaymentsInfo['honba'][$winnerId . '<-' . $loserId] = 300 * $honba;
$currentScores[$winnerId] += $honbaValue * $honba;
$currentScores[$loserId] -= $honbaValue * $honba;
self::$_lastPaymentsInfo['honba'][$winnerId . '<-' . $loserId] = $honbaValue * $honba;
}
} else {
$currentScores[$winnerId] += 300 * $honba;
$currentScores[$loserId] -= 300 * $honba;
self::$_lastPaymentsInfo['honba'][$winnerId . '<-' . $loserId] = 300 * $honba;
$currentScores[$winnerId] += $honbaValue * $honba;
$currentScores[$loserId] -= $honbaValue * $honba;
self::$_lastPaymentsInfo['honba'][$winnerId . '<-' . $loserId] = $honbaValue * $honba;
}

return $currentScores;
Expand Down Expand Up @@ -171,6 +173,7 @@ public static function tsumo(
?int $paoPlayerId
) {
self::resetPaymentsInfo();
$honbaValue = $rules->rules()->getHonbaValue();

if (empty($winnerId)) {
throw new InvalidParametersException('Tsumo must have winner');
Expand Down Expand Up @@ -201,7 +204,7 @@ public static function tsumo(
continue;
}
$currentScores[$playerId] += $pointsDiff['dealer'] ?? 0;
self::$_lastPaymentsInfo['direct'][$winnerId . '<-' . $playerId] = -($pointsDiff['dealer'] ?? 0);
self::$_lastPaymentsInfo['direct'][$winnerId . '<-' . $playerId] = - ($pointsDiff['dealer'] ?? 0);
}
} else {
foreach ($currentScores as $playerId => $value) {
Expand All @@ -210,10 +213,10 @@ public static function tsumo(
}
if ($playerId == $currentDealer) {
$currentScores[$playerId] += $pointsDiff['dealer'] ?? 0;
self::$_lastPaymentsInfo['direct'][$winnerId . '<-' . $playerId] = -($pointsDiff['dealer'] ?? 0);
self::$_lastPaymentsInfo['direct'][$winnerId . '<-' . $playerId] = - ($pointsDiff['dealer'] ?? 0);
} else {
$currentScores[$playerId] += $pointsDiff['player'] ?? 0;
self::$_lastPaymentsInfo['direct'][$winnerId . '<-' . $playerId] = -($pointsDiff['player'] ?? 0);
self::$_lastPaymentsInfo['direct'][$winnerId . '<-' . $playerId] = - ($pointsDiff['player'] ?? 0);
}
}
}
Expand All @@ -230,14 +233,14 @@ public static function tsumo(
$currentScores[$winnerId] += 1000 * count($riichiIds);
$currentScores[$winnerId] += 1000 * $riichiBetsCount;
self::$_lastPaymentsInfo['riichi'][$winnerId . '<-'] = 1000 * $riichiBetsCount;
$currentScores[$winnerId] += 300 * $honba;
$currentScores[$winnerId] += $honbaValue * $honba;

foreach ($currentScores as $playerId => $value) {
if ($playerId == $winnerId) {
continue;
}
$currentScores[$playerId] -= 100 * $honba;
self::$_lastPaymentsInfo['honba'][$winnerId . '<-' . $playerId] = 100 * $honba;
$currentScores[$playerId] -= ($honbaValue / 300) * $honba;
self::$_lastPaymentsInfo['honba'][$winnerId . '<-' . $playerId] = ($honbaValue / 3) * $honba;
}

return $currentScores;
Expand Down Expand Up @@ -522,7 +525,7 @@ public static function assignRiichiBets(array $rounds, int $loserId, int $riichi
$winners[$round->getWinnerId()] = [];
foreach ($bets as $k => $player) {
if (isset($winners[$player])) {
$winners[$player] []= $round->getWinnerId(); // winner always gets back his bet
$winners[$player][] = $round->getWinnerId(); // winner always gets back his bet
unset($bets[$k]);
}
}
Expand Down
Loading

0 comments on commit bbf58d2

Please sign in to comment.