3 * brisk - rules_together17.phh
5 * Copyright (C) 2017 Matteo Nastasi
6 * mailto: nastasi@alternativeoutput.it
7 * matteo.nastasi@milug.org
8 * web: http://www.alternativeoutput.it
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details. You should have received a
19 * copy of the GNU General Public License along with this program; if
20 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21 * Suite 330, Boston, MA 02111-1307, USA.
25 require_once("briskin5.phh");
26 require_once("rules_base.phh");
29 $mlang_bin5_toge17_rules =
31 // br, hr, b, /b, win, fri
32 'info_part' => array( 'it' => 'Ha chiamato %3$s%5$s%4$s (punti torneo %7$d), il socio era %3$s%6$s%4$s,%1$s',
33 'en' => 'The declarer was %3$s%5$s%4$s (tournment points %7$d), the partner was %3$s%6$s%4$s,%1$s'),
34 // br, hr, b, /b, win_name
35 'info_alon' => array( 'it' => '%3$s%5$s%4$s si è chiamato in mano (punti torneo %6$d),%1$s',
36 'en' => '%3$s%5$s%4$s play alone against each other (tournment points %6$d),%1$s')
39 class Rules_together17 extends Rules_no_draw {
40 function __construct($table)
42 parent::__construct($table);
46 function tourn_points(&$user, $user_pos)
48 $card = $this->table->card;
49 unset($user->asta_tourn_pts);
50 $user->asta_tourn_pts = array(0, 0, 0, 0);
51 if (BIN5_CARD_HAND == 8)
52 $tourn_values = array(11, 10, 4,3,2, 1,1,1,1,1);
54 $tourn_values = array(33, 30, 12,9,6, 3,3,3,3,3);
56 for ($i = 0 ; $i < BIN5_PLAYERS_N * BIN5_CARD_HAND ; $i++) {
58 if ($card[$i]->owner == $user_pos) {
59 $user->asta_tourn_pts[(int)($i / 10)] += $tourn_values[$i % 10];
64 function tourn_points_max($user)
67 for ($i = 0 ; $i < 4 ; $i++) {
68 if ($user->asta_tourn_pts[$i] > $mx) {
69 $mx = $user->asta_tourn_pts[$i];
76 function min_tourn_points($a_pnt)
84 else if ($a_pnt < 100)
92 function check_tourn_points($hand_pts, $a_pnt, $a_seed, &$ret_s) {
93 $min_pts = $this->min_tourn_points($a_pnt);
95 if ($hand_pts < $min_pts) {
97 $seeds = array('coppe', 'ori', 'spade', 'bastoni');
98 $ret_s = sprintf("Hai chiamato un due di %s a %d ma in mano per quel seme hai %d punti-torneo, non puoi.",
99 $seeds[$a_seed], $a_pnt, $hand_pts);
105 function rules_asta(&$bri, $curtime, $action, $user, &$ret_s, $a_card, $a_pnt) {
107 Per le chiamate da 62 a 70 bisognerà avere 13 punti ( esempi.: asso e fante oppure tre
108 e cavallo oppure re, cavallo, fante, sette, sei, cinque, quattro) ;
109 Per chiamate da 71 ad 80 bisognerà avere 19 punti ( esempi.: asso, re, cavallo e 6
110 oppure tre, re, fante, 7, 6 e 5 );
111 Per chiamate da 81 a 90 bisognerà avere 23 punti ( esempi.: asso, tre e fante oppure
112 asso, re, cavallo, fante, 6, 5 e 4);
113 Per chiamate da 91 a 100 bisognerà avere 25 punti ( esempi.: asso, tre, re e 7 oppure
114 asso, tre, cavallo e fante );
115 Per chiamate da 101 a 120 bisognerà avere 28 punti ( esempi.:asso, tre, re e cavallo
116 oppure asso, tre, cavallo, 7, 6, 5 e 4 ).
119 $index_cur = $this->table->gstart % BIN5_PLAYERS_N;
121 // Abbandono dell'asta
123 log_wr("Abbandona l'asta.");
124 $this->table->asta_pla[$index_cur] = FALSE;
125 $user->asta_card = -1;
126 $this->table->asta_pla_n--;
128 if ($this->table->asta_card == -1 && $this->table->asta_pla_n == 1) {
129 // all abandon auction except one => move next bid to two and 71 points
130 $this->table->asta_card = 9;
131 $this->table->asta_pnt = 70;
136 else if ($a_card <= 9) {
140 if ($a_card >= 0 && $a_card < 9 && $a_card > $this->table->asta_card) {
143 else if ($a_card == 9 &&
144 $a_pnt > ($this->table->asta_pnt >= 61 ? $this->table->asta_pnt : 60)
146 $min_pts = $this->min_tourn_points($a_pnt);
148 $max_hand_pts = $this->tourn_points_max($user);
149 if ($max_hand_pts < $min_pts) {
151 $ret_s = sprintf("Hai chiamato un due a %d ma in mano hai al massimo %d punti-torneo, non puoi.",
152 $a_pnt, $max_hand_pts);
160 $user->asta_card = $a_card;
161 $this->table->asta_card = $a_card;
163 $user->asta_pnt = $a_pnt;
164 $this->table->asta_pnt = $a_pnt;
174 function rules_nextauct(&$bri, $curtime, $action, $user, $maxcard)
176 if (($this->table->asta_pla_n > ($maxcard > -1 ? 1 : 0)) &&
177 !($this->table->asta_card == 9 && $this->table->asta_pnt == 120)) {
186 function rules_checkchoose(&$bri, $curtime, $action, $user, &$ret_s, $a_brisco)
188 if (! parent::rules_checkchoose(&$bri, $curtime, $action, $user, &$ret_s, $a_brisco)) {
192 if ($this->table->asta_card == 9) {
193 $bri_seed = (int)($a_brisco / 10);
194 return $this->check_tourn_points($user->asta_tourn_pts[$bri_seed],
195 $this->table->asta_pnt, $bri_seed, $ret_s);
202 static function game_description($act, $form, $old_mult, $win = -1, $win_name = "?1?", $fri = -1, $fri_name = "?2?",
203 $old_pnt = -1, $old_asta_pnt = -1, $old_tourn_pts = -1)
205 GLOBAL $G_lang, $mlang_bin5_rules, $mlang_bin5_toge17_rules;
207 if ($form == 'html') {
212 $win_name = xcape($win_name);
213 $fri_name = xcape($fri_name);
222 if ($act == BIN5_RULES_OLDSCHEMA) {
225 else if ($act == BIN5_RULES_ALLPASS) {
226 return (sprintf($mlang_bin5_rules['info_alpa'][$G_lang],
227 $tg_br, $tg_hr, $tg_bo, $tg_bc));
229 else if ($act == BIN5_RULES_ABANDON) {
230 return (sprintf($mlang_bin5_rules['info_aban'][$G_lang],
231 $tg_br, $tg_hr, $tg_bo, $tg_bc,
235 $wol = static::game_result($old_asta_pnt, $old_pnt);
239 if ($win != $fri) { // not alone case
240 /* MLANG: "<hr>Nell'ultima mano ha chiamato <b>%s</b>, il socio era <b>%s</b>,<br>", "hanno fatto <b>cappotto</b> EBBRAVI!.<hr>", "dovevano fare <b>%s</b> punti e ne hanno fatti <b>%d</b>: hanno <b>%s</b>.<hr>", "<hr>Nell'ultima mano <b>%s</b> si è chiamato in mano,<br>", "ha fatto <b>cappotto</b> EBBRAVO!.<hr>", "doveva fare <b>%s</b> punti e ne ha fatti <b>%d</b>: ha <b>%s</b>.<hr>", ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt : 'più di 60'), $table->old_pnt, ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso" */
242 $noty .= sprintf($mlang_bin5_toge17_rules['info_part'][$G_lang],
243 $tg_br, $tg_hr, $tg_bo, $tg_bc,
247 if ($old_pnt == 120) {
248 $noty .= sprintf($mlang_bin5_rules['info_capp'][$G_lang],
249 $tg_br, $tg_hr, $tg_bo, $tg_bc );
252 if ($old_asta_pnt > 61) {
253 $noty .= sprintf($mlang_bin5_rules['info_alea'][$G_lang],
254 $tg_br, $tg_hr, $tg_bo, $tg_bc,
255 $old_asta_pnt, $old_pnt,
256 ($wol == 1 ? $mlang_bin5_rules['info_win'][$G_lang] :
257 ($wol == 0 ? $mlang_bin5_rules['info_peer'][$G_lang] :
258 $mlang_bin5_rules['info_lost'][$G_lang])));
261 $noty .= sprintf($mlang_bin5_rules['info_more'][$G_lang],
262 $tg_br, $tg_hr, $tg_bo, $tg_bc,
264 ($wol == 1 ? $mlang_bin5_rules['info_win'][$G_lang] :
265 ($wol == 0 ? $mlang_bin5_rules['info_peer'][$G_lang] :
266 $mlang_bin5_rules['info_lost'][$G_lang])));
267 } // else of if ($old_asta_pnt > 61) {
268 } // else of if ($old_pnt == 120) {
269 } // if ($win != $fri) { // not alone case
271 $noty .= sprintf($mlang_bin5_toge17_rules['info_alon'][$G_lang],
272 $tg_br, $tg_hr, $tg_bo, $tg_bc,
275 if ($old_pnt == 120) {
276 $noty .= sprintf($mlang_bin5_rules['info_acap'][$G_lang],
277 $tg_br, $tg_hr, $tg_bo, $tg_bc);
280 if ($old_asta_pnt > 61) {
281 $noty .= sprintf($mlang_bin5_rules['info_aleaa'][$G_lang],
282 $tg_br, $tg_hr, $tg_bo, $tg_bc,
283 $old_asta_pnt, $old_pnt,
284 ($wol == 1 ? $mlang_bin5_rules['info_win'][$G_lang] :
285 ($wol == 0 ? $mlang_bin5_rules['info_peer'][$G_lang] :
286 $mlang_bin5_rules['info_lost'][$G_lang])));
289 $noty .= sprintf($mlang_bin5_rules['info_morea'][$G_lang],
290 $tg_br, $tg_hr, $tg_bo, $tg_bc,
292 ($wol == 1 ? $mlang_bin5_rules['info_win'][$G_lang] :
293 ($wol == 0 ? $mlang_bin5_rules['info_peer'][$G_lang] :
294 $mlang_bin5_rules['info_lost'][$G_lang])));
300 $old_multer = static::s_multer($old_mult, $old_asta_pnt);
301 if ($old_multer > 1) {
302 $noty .= sprintf($mlang_bin5_rules['info_omul'][$G_lang],
303 $tg_br, $tg_hr, $tg_bo, $tg_bc,
304 multoval($old_multer));
306 $noty .= sprintf('%2$s', $tg_br, $tg_hr);
310 } // class Rules_no_draw