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)
86 else if ($a_pnt < 100)
94 function check_tourn_points($hand_pts, $a_pnt, $a_seed, &$ret_s) {
95 $min_pts = $this->min_tourn_points($a_pnt);
97 if ($hand_pts < $min_pts) {
99 $seeds = array('coppe', 'ori', 'spade', 'bastoni');
100 $ret_s = sprintf("Hai chiamato un due di %s a %d ma in mano per quel seme hai %d punti-torneo, non puoi.",
101 $seeds[$a_seed], $a_pnt, $hand_pts);
107 function rules_asta(&$bri, $curtime, $action, $user, &$ret_s, $a_card, $a_pnt) {
109 Per le chiamate da 62 a 70 bisognerà avere 13 punti ( esempi.: asso e fante oppure tre
110 e cavallo oppure re, cavallo, fante, sette, sei, cinque, quattro) ;
111 Per chiamate da 71 ad 80 bisognerà avere 19 punti ( esempi.: asso, re, cavallo e 6
112 oppure tre, re, fante, 7, 6 e 5 );
113 Per chiamate da 81 a 90 bisognerà avere 23 punti ( esempi.: asso, tre e fante oppure
114 asso, re, cavallo, fante, 6, 5 e 4);
115 Per chiamate da 91 a 100 bisognerà avere 25 punti ( esempi.: asso, tre, re e 7 oppure
116 asso, tre, cavallo e fante );
117 Per chiamate da 101 a 120 bisognerà avere 28 punti ( esempi.:asso, tre, re e cavallo
118 oppure asso, tre, cavallo, 7, 6, 5 e 4 ).
121 $index_cur = $this->table->gstart % BIN5_PLAYERS_N;
123 // Abbandono dell'asta
125 log_wr("Abbandona l'asta.");
126 $this->table->asta_pla[$index_cur] = FALSE;
127 $user->asta_card = -1;
128 $this->table->asta_pla_n--;
130 if ($this->table->asta_card == -1 && $this->table->asta_pla_n == 1) {
131 // all abandon auction except one => move next bid to two and 71 points
132 $this->table->asta_card = 9;
133 $this->table->asta_pnt = 70;
138 else if ($a_card <= 9) {
142 if ($a_card >= 0 && $a_card < 9 && $a_card > $this->table->asta_card) {
145 else if ($a_card == 9 &&
146 $a_pnt > ($this->table->asta_pnt >= 61 ? $this->table->asta_pnt : 60)
148 $min_pts = $this->min_tourn_points($a_pnt);
150 $max_hand_pts = $this->tourn_points_max($user);
151 if ($max_hand_pts < $min_pts) {
153 $ret_s = sprintf("Hai chiamato un due a %d ma in mano hai al massimo %d punti-torneo, non puoi.",
154 $a_pnt, $max_hand_pts);
162 $user->asta_card = $a_card;
163 $this->table->asta_card = $a_card;
165 $user->asta_pnt = $a_pnt;
166 $this->table->asta_pnt = $a_pnt;
176 function rules_nextauct(&$bri, $curtime, $action, $user, $maxcard)
178 if (($this->table->asta_pla_n > ($maxcard > -1 ? 1 : 0)) &&
179 !($this->table->asta_card == 9 && $this->table->asta_pnt == 120)) {
188 function rules_checkchoose(&$bri, $curtime, $action, $user, &$ret_s, $a_brisco)
190 if (! parent::rules_checkchoose(&$bri, $curtime, $action, $user, &$ret_s, $a_brisco)) {
194 if ($this->table->asta_card == 9) {
195 $bri_seed = (int)($a_brisco / 10);
196 return $this->check_tourn_points($user->asta_tourn_pts[$bri_seed],
197 $this->table->asta_pnt, $bri_seed, $ret_s);
204 static function game_description($act, $form, $old_mult, $win = -1, $win_name = "?1?", $fri = -1, $fri_name = "?2?",
205 $old_pnt = -1, $old_asta_pnt = -1, $old_tourn_pts = -1)
207 GLOBAL $G_lang, $mlang_bin5_rules, $mlang_bin5_toge17_rules;
209 if ($form == 'html') {
214 $win_name = xcape($win_name);
215 $fri_name = xcape($fri_name);
224 if ($act == BIN5_RULES_OLDSCHEMA) {
227 else if ($act == BIN5_RULES_ALLPASS) {
228 return (sprintf($mlang_bin5_rules['info_alpa'][$G_lang],
229 $tg_br, $tg_hr, $tg_bo, $tg_bc));
231 else if ($act == BIN5_RULES_ABANDON) {
232 return (sprintf($mlang_bin5_rules['info_aban'][$G_lang],
233 $tg_br, $tg_hr, $tg_bo, $tg_bc,
237 $wol = static::game_result($old_asta_pnt, $old_pnt);
241 if ($win != $fri) { // not alone case
242 /* 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" */
244 $noty .= sprintf($mlang_bin5_toge17_rules['info_part'][$G_lang],
245 $tg_br, $tg_hr, $tg_bo, $tg_bc,
249 if ($old_pnt == 120) {
250 $noty .= sprintf($mlang_bin5_rules['info_capp'][$G_lang],
251 $tg_br, $tg_hr, $tg_bo, $tg_bc );
254 if ($old_asta_pnt > 61) {
255 $noty .= sprintf($mlang_bin5_rules['info_alea'][$G_lang],
256 $tg_br, $tg_hr, $tg_bo, $tg_bc,
257 $old_asta_pnt, $old_pnt,
258 ($wol == 1 ? $mlang_bin5_rules['info_win'][$G_lang] :
259 ($wol == 0 ? $mlang_bin5_rules['info_peer'][$G_lang] :
260 $mlang_bin5_rules['info_lost'][$G_lang])));
263 $noty .= sprintf($mlang_bin5_rules['info_more'][$G_lang],
264 $tg_br, $tg_hr, $tg_bo, $tg_bc,
266 ($wol == 1 ? $mlang_bin5_rules['info_win'][$G_lang] :
267 ($wol == 0 ? $mlang_bin5_rules['info_peer'][$G_lang] :
268 $mlang_bin5_rules['info_lost'][$G_lang])));
269 } // else of if ($old_asta_pnt > 61) {
270 } // else of if ($old_pnt == 120) {
271 } // if ($win != $fri) { // not alone case
273 $noty .= sprintf($mlang_bin5_toge17_rules['info_alon'][$G_lang],
274 $tg_br, $tg_hr, $tg_bo, $tg_bc,
277 if ($old_pnt == 120) {
278 $noty .= sprintf($mlang_bin5_rules['info_acap'][$G_lang],
279 $tg_br, $tg_hr, $tg_bo, $tg_bc);
282 if ($old_asta_pnt > 61) {
283 $noty .= sprintf($mlang_bin5_rules['info_aleaa'][$G_lang],
284 $tg_br, $tg_hr, $tg_bo, $tg_bc,
285 $old_asta_pnt, $old_pnt,
286 ($wol == 1 ? $mlang_bin5_rules['info_win'][$G_lang] :
287 ($wol == 0 ? $mlang_bin5_rules['info_peer'][$G_lang] :
288 $mlang_bin5_rules['info_lost'][$G_lang])));
291 $noty .= sprintf($mlang_bin5_rules['info_morea'][$G_lang],
292 $tg_br, $tg_hr, $tg_bo, $tg_bc,
294 ($wol == 1 ? $mlang_bin5_rules['info_win'][$G_lang] :
295 ($wol == 0 ? $mlang_bin5_rules['info_peer'][$G_lang] :
296 $mlang_bin5_rules['info_lost'][$G_lang])));
302 $old_multer = static::s_multer($old_mult, $old_asta_pnt);
303 if ($old_multer > 1) {
304 $noty .= sprintf($mlang_bin5_rules['info_omul'][$G_lang],
305 $tg_br, $tg_hr, $tg_bo, $tg_bc,
306 multoval($old_multer));
308 $noty .= sprintf('%2$s', $tg_br, $tg_hr);
312 } // class Rules_no_draw