From 6a939415c569cb6b078b3dab42be2d35c7238d4f Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Tue, 7 Mar 2017 07:31:43 +0100 Subject: [PATCH] refactored rules_asta() method --- web/briskin5/Obj/rules_old_rules.phh | 2 + web/briskin5/Obj/rules_together17.phh | 84 ++++++++++++++++++--------- web/briskin5/index_wr.php | 14 +---- 3 files changed, 60 insertions(+), 40 deletions(-) diff --git a/web/briskin5/Obj/rules_old_rules.phh b/web/briskin5/Obj/rules_old_rules.phh index 417cdf3..29d9833 100644 --- a/web/briskin5/Obj/rules_old_rules.phh +++ b/web/briskin5/Obj/rules_old_rules.phh @@ -88,6 +88,8 @@ class Rules_old_rules extends Rules { function rules_asta(&$bri, $curtime, $action, $user, &$ret_s, $a_card, $a_pnt) { + $index_cur = $this->table->gstart % BIN5_PLAYERS_N; + // Abbandono dell'asta if ($a_card <= -1) { log_wr("Abbandona l'asta."); diff --git a/web/briskin5/Obj/rules_together17.phh b/web/briskin5/Obj/rules_together17.phh index 0570868..c5221ef 100644 --- a/web/briskin5/Obj/rules_together17.phh +++ b/web/briskin5/Obj/rules_together17.phh @@ -38,21 +38,18 @@ class Rules_together17 extends Rules_no_draw { unset($user->asta_tourn_pts); $user->asta_tourn_pts = array(0, 0, 0, 0); $tourn_values = array(11, 10, 4,3,2, 1,1,1,1,1); - - error_log("QUI CI SIAMO: PRE"); + for ($i = 0 ; $i < BIN5_PLAYERS_N * BIN5_CARD_HAND ; $i++) { - error_log("QUI CI SIAMO: LOOP"); - + if ($card[$i]->owner == $user_pos) { - error_log("QUI CI SIAMO: ASSIGN"); - $user->asta_tourn_pts[(int)($i / 10)] += $tourn_values[$i % 10]; + $user->asta_tourn_pts[(int)($i / 10)] += $tourn_values[$i % 10]; } } } function tourn_points_max($user) { - + $mx = 0; for ($i = 0 ; $i < 4 ; $i++) { error_log("tourn_pts_max "); @@ -79,30 +76,61 @@ Per chiamate da 101 a 120 bisognerà avere 28 punti ( esempi.:asso, tre, re e ca oppure asso, tre, cavallo, 7, 6, 5 e 4 ). */ - if ($a_card >= 0 && $a_card < 9 && $a_card > $this->table->asta_card) - return TRUE; - else if ($a_card == 9 && - $a_pnt > ($this->table->asta_pnt >= 61 ? $this->table->asta_pnt : 60) && $a_pnt <= 120) { - if ($a_pnt < 71) - $min_pts = 13; - else if ($a_pnt < 80) - $min_pts = 19; - else if ($a_pnt < 90) - $min_pts = 23; - else if ($a_pnt < 100) - $min_pts = 25; - else - $min_pts = 28; - - $max_hand_pts = $this->tourn_points_max($user); - if ($max_hand_pts < $min_pts) { - $ret_s = sprintf("Hai chiamato un due a %d ma in mano hai al massimo %d punti-torneo, non puoi.", - $a_pnt, $max_hand_pts); - return FALSE; - } + $index_cur = $this->table->gstart % BIN5_PLAYERS_N; + + // Abbandono dell'asta + if ($a_card <= -1) { + log_wr("Abbandona l'asta."); + $this->table->asta_pla[$index_cur] = FALSE; + $user->asta_card = -1; + $this->table->asta_pla_n--; return TRUE; } + else if ($a_card <= 9) { + $ret_s = ""; + + do { + if ($a_card >= 0 && $a_card < 9 && $a_card > $this->table->asta_card) { + return TRUE; + } + else if ($a_card == 9 && + $a_pnt > ($this->table->asta_pnt >= 61 ? $this->table->asta_pnt : 60) + && $a_pnt <= 120) { + if ($a_pnt < 71) + $min_pts = 13; + else if ($a_pnt < 80) + $min_pts = 19; + else if ($a_pnt < 90) + $min_pts = 23; + else if ($a_pnt < 100) + $min_pts = 25; + else + $min_pts = 28; + + $max_hand_pts = $this->tourn_points_max($user); + if ($max_hand_pts < $min_pts) { + // FIXME_LANG + $ret_s = sprintf("Hai chiamato un due a %d ma in mano hai al massimo %d punti-torneo, non puoi.", + $a_pnt, $max_hand_pts); + break; + } + } + else { + break; + } + + $user->asta_card = $a_card; + $this->table->asta_card = $a_card; + if ($a_card == 9) { + $user->asta_pnt = $a_pnt; + $this->table->asta_pnt = $a_pnt; + } + + return TRUE; + } while (0); + } + return FALSE; } diff --git a/web/briskin5/index_wr.php b/web/briskin5/index_wr.php index 8719466..e3bd11a 100644 --- a/web/briskin5/index_wr.php +++ b/web/briskin5/index_wr.php @@ -198,20 +198,10 @@ function bin5_index_wr_main(&$bin5, $remote_addr_full, $get, $post, $cookie) log_wr("CI SIAMO a_card ".$a_card." asta_card ".$table->asta_card); // Abbandono dell'asta - if ($a_card <= -1) { - log_wr("Abbandona l'asta."); - $table->asta_pla[$index_cur] = FALSE; - $user->asta_card = -1; - $table->asta_pla_n--; - } - else if ($a_card <= 9) { - if (!$table->rules->engine(&$bin5, $curtime, BIN5_RULES_ASTA, $user, $ret_s, $a_card, $a_pnt)) { + if (!$table->rules->engine(&$bin5, $curtime, BIN5_RULES_ASTA, $user, + $ret_s, $a_card, $a_pnt)) { break; } - } - else { - break; - } /* next step */ $showst = "show_astat("; -- 2.17.1