more consistent matches descriptions
[brisk.git] / web / briskin5 / Obj / rules_together17.phh
1 <?php
2 /*
3  *  brisk - rules_together17.phh
4  *
5  *  Copyright (C) 2017 Matteo Nastasi
6  *                          mailto: nastasi@alternativeoutput.it
7  *                                  matteo.nastasi@milug.org
8  *                          web: http://www.alternativeoutput.it
9  *
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.
14  *
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.
22  *
23  */
24
25 require_once("briskin5.phh");
26 require_once("rules_base.phh");
27
28
29 $mlang_bin5_toge17_rules =
30     array(
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')
37           );
38
39 class Rules_together17 extends Rules_no_draw {
40     function __construct($table)
41     {
42         parent::__construct($table);
43         $this->id = 4;
44     }
45
46     function tourn_points(&$user, $user_pos)
47     {
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);
53         else
54             $tourn_values = array(33, 30, 12,9,6, 3,3,3,3,3);
55
56         for ($i = 0 ; $i < BIN5_PLAYERS_N * BIN5_CARD_HAND ; $i++) {
57
58             if ($card[$i]->owner == $user_pos) {
59                 $user->asta_tourn_pts[(int)($i / 10)] += $tourn_values[$i % 10];
60             }
61         }
62     }
63
64     function tourn_points_max($user)
65     {
66         $mx = 0;
67         for ($i = 0 ; $i < 4 ; $i++) {
68             if ($user->asta_tourn_pts[$i] > $mx) {
69                 $mx = $user->asta_tourn_pts[$i];
70             }
71         }
72
73         return $mx;
74     }
75
76     function min_tourn_points($a_pnt)
77     {
78         if ($a_pnt < 71)
79             $min_pts = 13;
80         else if ($a_pnt < 80)
81             $min_pts = 19;
82         else if ($a_pnt < 90)
83             $min_pts = 23;
84         else if ($a_pnt < 100)
85             $min_pts = 25;
86         else
87             $min_pts = 28;
88
89         return $min_pts;
90     }
91
92     function check_tourn_points($hand_pts, $a_pnt, $a_seed, &$ret_s) {
93         $min_pts = $this->min_tourn_points($a_pnt);
94
95         if ($hand_pts < $min_pts) {
96             // FIXME_LANG
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);
100             return FALSE;
101         }
102         return TRUE;
103     }
104
105     function rules_asta(&$bri, $curtime, $action, $user, &$ret_s, $a_card, $a_pnt) {
106         /*
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 ).
117         */
118
119         $index_cur = $this->table->gstart % BIN5_PLAYERS_N;
120
121         // Abbandono dell'asta
122         if ($a_card <= -1) {
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--;
127
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;
132             }
133
134             return TRUE;
135         }
136         else if ($a_card <= 9) {
137             $ret_s = "";
138
139             do {
140                 if ($a_card >= 0 && $a_card < 9 && $a_card > $this->table->asta_card) {
141                     ;
142                 }
143                 else if ($a_card == 9 &&
144                          $a_pnt > ($this->table->asta_pnt >= 61 ? $this->table->asta_pnt : 60)
145                          && $a_pnt <= 120) {
146                     $min_pts = $this->min_tourn_points($a_pnt);
147
148                     $max_hand_pts = $this->tourn_points_max($user);
149                     if ($max_hand_pts < $min_pts) {
150                         // FIXME_LANG
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);
153                         break;
154                     }
155                 }
156                 else {
157                     break;
158                 }
159
160                 $user->asta_card  = $a_card;
161                 $this->table->asta_card = $a_card;
162                 if ($a_card == 9) {
163                     $user->asta_pnt   = $a_pnt;
164                     $this->table->asta_pnt  = $a_pnt;
165                 }
166
167                 return TRUE;
168             } while (0);
169         }
170
171         return FALSE;
172     }
173
174     function rules_nextauct(&$bri, $curtime, $action, $user, $maxcard)
175     {
176         if (($this->table->asta_pla_n > ($maxcard > -1 ? 1 : 0)) &&
177             !($this->table->asta_card == 9 && $this->table->asta_pnt == 120)) {
178             return TRUE;
179         }
180         else {
181             return FALSE;
182         }
183
184     }
185
186     function rules_checkchoose(&$bri, $curtime, $action, $user, &$ret_s, $a_brisco)
187     {
188         if (! parent::rules_checkchoose(&$bri, $curtime, $action, $user, &$ret_s, $a_brisco)) {
189             return FALSE;
190         }
191
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);
196         }
197
198         return TRUE;
199     }
200
201
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)
204     {
205         GLOBAL $G_lang, $mlang_bin5_rules, $mlang_bin5_toge17_rules;
206
207         if ($form == 'html') {
208             $tg_br = "<br>";
209             $tg_hr = "<hr>";
210             $tg_bo = "<b>";
211             $tg_bc = "</b>";
212             $win_name = xcape($win_name);
213             $fri_name = xcape($fri_name);
214         }
215         else {
216             $tg_br = " ";
217             $tg_hr = " ";
218             $tg_bo = "";
219             $tg_bc = "";
220         }
221
222         if ($act == BIN5_RULES_OLDSCHEMA) {
223             return ("");
224         }
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));
228         }
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,
232                             $win_name));
233         }
234         else {
235             $wol = static::game_result($old_asta_pnt, $old_pnt);
236
237             $noty = "";
238
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 &egrave; 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&ugrave; di 60'), $table->old_pnt, ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso" */
241
242                 $noty .= sprintf($mlang_bin5_toge17_rules['info_part'][$G_lang],
243                                  $tg_br, $tg_hr, $tg_bo, $tg_bc,
244                                  $win_name,
245                                  $fri_name,
246                                  $old_tourn_pts);
247                 if ($old_pnt == 120) {
248                     $noty .= sprintf($mlang_bin5_rules['info_capp'][$G_lang],
249                                      $tg_br, $tg_hr, $tg_bo, $tg_bc );
250                 }
251                 else {
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])));
259                     }
260                     else {
261                         $noty .= sprintf($mlang_bin5_rules['info_more'][$G_lang],
262                                          $tg_br, $tg_hr, $tg_bo, $tg_bc,
263                                          $old_pnt,
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
270             else {
271                 $noty .= sprintf($mlang_bin5_toge17_rules['info_alon'][$G_lang],
272                                  $tg_br, $tg_hr, $tg_bo, $tg_bc,
273                                  $win_name,
274                                  $old_tourn_pts);
275                 if ($old_pnt == 120) {
276                     $noty .= sprintf($mlang_bin5_rules['info_acap'][$G_lang],
277                                      $tg_br, $tg_hr, $tg_bo, $tg_bc);
278                 }
279                 else {
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])));
287                     }
288                     else {
289                         $noty .= sprintf($mlang_bin5_rules['info_morea'][$G_lang],
290                                          $tg_br, $tg_hr, $tg_bo, $tg_bc,
291                                          $old_pnt,
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])));
295                     }
296                 }
297             }
298         }
299
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));
305         }
306         $noty .= sprintf('%2$s', $tg_br, $tg_hr);
307
308         return ($noty);
309     }
310 } // class Rules_no_draw
311
312 ?>