3 * brisk - rules_old_rules.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");
28 class Rules_old_rules extends Rules {
29 function __construct($table)
31 parent::__construct($table);
35 static function asta2mult($asta_pnt)
39 else if ($asta_pnt > 100)
41 else if ($asta_pnt > 90)
43 else if ($asta_pnt > 80)
45 else if ($asta_pnt > 70)
50 static function s_multer($mult, $pnt)
52 return (pow(2, $mult) * static::asta2mult($pnt));
55 static function s_point_calc($pnt_done, $mult, $pnt_req, $is_allpoints)
57 return ($pnt_done * static::s_multer($mult, $pnt_req) * ($is_allpoints ? 2 : 1));
60 function multer($is_new)
63 return (static::s_multer($this->table->mult, $this->table->asta_pnt));
66 return (static::s_multer($this->table->old_mult, $this->table->old_asta_pnt));
70 static function game_result($asta_pnt, $pnt)
72 $sixty = (BIN5_PLAYERS_N == 3 ? 30 : 60);
73 if ($asta_pnt == 61) {
76 else if ($pnt == $sixty)
82 if ($pnt >= $asta_pnt)
89 function rules_asta(&$bri, $curtime, $action, $user, &$ret_s, $a_card, $a_pnt)
91 $index_cur = $this->table->gstart % BIN5_PLAYERS_N;
93 // Abbandono dell'asta
95 log_wr("Abbandona l'asta.");
96 $this->table->asta_pla[$index_cur] = FALSE;
97 $user->asta_card = -1;
98 $this->table->asta_pla_n--;
102 else if ($a_card <= 9) {
106 if ($a_card >= 0 && $a_card < 9 && $a_card > $this->table->asta_card)
108 else if ($a_card == 9 && $a_pnt > ($this->table->asta_pnt >= 61 ? $this->table->asta_pnt : 60)
114 $user->asta_card = $a_card;
115 $this->table->asta_card = $a_card;
117 $user->asta_pnt = $a_pnt;
118 $this->table->asta_pnt = $a_pnt;
128 function rules_nextauct(&$bri, $curtime, $action, $user, $maxcard)
130 if (($this->table->asta_pla_n > ($maxcard > -1 ? 1 : 0)) &&
131 !($this->table->asta_card == 9 && $this->table->asta_pnt == 120)) {
140 function engine(&$bri, $curtime, $action, $user, &$opt1 = NULL, &$opt2 = NULL, &$opt3 = NULL)
142 GLOBAL $G_all_points, $G_dbasetype;
144 $table = $this->table;
147 if ($action == BIN5_RULES_ASTA) {
148 return ($this->rules_asta($bri, $curtime, $action, $user, &$opt1, $opt2, $opt3));
150 else if ($action == BIN5_RULES_NEXTAUCT) {
151 return ($this->rules_nextauct($bri, $curtime, $action, $user, $opt1));
153 else if ($action == BIN5_RULES_ALLPASS) { // return TRUE if all correct
154 $table->old_act = $action;
155 $table->old_asta_win = -1;
158 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
163 // $table->game_next(1);
164 $table->game_init(&$bri->user);
166 else if ($action == BIN5_RULES_ABANDON) { // return TRUE if all correct
167 if (!($user->handpt <= 2)) {
170 $table->old_act = $action;
171 log_wr(sprintf("GIOCO FINITO !!!"));
172 $table->old_asta_win = $user->table_pos;
176 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
180 // Non si cambia mazzo se si abbandona la partita
182 // $table->game_next(0);
183 $table->game_init(&$bri->user);
185 else if ($action == BIN5_RULES_FINISH) { // return TRUE if all correct
186 $table->old_act = $action;
190 if ($table->asta_pnt == 60)
191 $table->asta_pnt = 61;
193 $table->old_reason = "";
195 // count points for the temporary 2 teams
196 for ($i = 0 ; $i < (BIN5_CARD_HAND * BIN5_PLAYERS_N) ; $i++) {
197 $ctt = $table->card[$i]->value % 10;
198 $own = $table->card[$i]->owner;
199 if ($own == $table->asta_win || $own == $table->friend)
200 $pro += $G_all_points[$ctt];
203 log_wr(sprintf("PRO: [%d]", $pro));
206 if (static::game_result($table->asta_pnt, $pro) == 0) {
207 $table->points[$table->points_n % MAX_POINTS] = array();
208 for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
209 $table->points[$table->points_n % MAX_POINTS][$i] = 0;
213 $table->old_pnt = $pro;
214 $table->old_asta_win = $table->asta_win;
220 if (static::game_result($table->asta_pnt, $pro) == 1)
225 // TAG: POINTS_MANAGEMENT
226 $table->points[$table->points_n % MAX_POINTS] = array();
227 for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
228 if ($i == $table->asta_win)
229 $pnt = ($i == $table->friend ? 4 : 2);
230 else if ($i == $table->friend)
235 log_wr(sprintf("PRO: pt[%d][%d] = %d", $table->points_n % MAX_POINTS, $i, $pnt));
237 $pnt_sav = static::s_point_calc($pnt * $sig, 0, $table->asta_pnt, ($pro == 120));
238 $pnt_tab = static::s_point_calc($pnt * $sig, $table->mult, $table->asta_pnt, ($pro == 120));
240 $table->points[$table->points_n % MAX_POINTS][$i] = $pnt_tab;
241 $table->total[$i] += $pnt_tab;
242 $pnts_sav[$i] = $pnt_sav;
245 $table->old_pnt = $pro;
246 $table->old_asta_win = $table->asta_win;
254 $table->game_next($game_delta);
256 $plist = "$table->table_token|$user->table_orig|$table->player_n";
259 for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
260 $user_cur = &$bri->user[$table->player[$i]];
263 $ucodes[$i] = $user_cur->code_get();
266 $plist .= '|'.xcapelt($user_cur->name).'|'.$pnts_sav[$i];
267 $codes .= '|'.xcapelt($user_cur->code_get());
270 log_legal($curtime, $user->ip, $user, "STAT:BRISKIN5:FINISH_GAME", $plist);
272 $table->old_asta_pnt = $table->asta_pnt;
273 // $table->old_mazzo is managed by ->game_next();
274 // $table->old_mult, $table->old_pnt, $table->old_reason and $table->old_asta_win are specific
276 $table->old_friend = $table->friend;
277 $table->old_tourn_pts = $table->tourn_pts;
279 $table->old_reason = static::game_description($action, 'html', $table->old_mult,
280 $table->old_asta_win,
281 ($table->old_asta_win != -1 ?
282 $bri->user[$table->player[$table->old_asta_win]]->name : ""),
284 ($table->old_friend != -1 ?
285 $bri->user[$table->player[$table->old_friend]]->name : ""),
286 $table->old_pnt, $table->old_asta_pnt, $table->old_tourn_pts);
289 if ($user->table_orig < TABLES_AUTH_N) {
290 require_once("../Obj/dbase_".$G_dbasetype.".phh");
292 if (($bdb = BriskDB::create()) != FALSE) {
293 $bdb->bin5_points_save($curtime, $table, $user->table_orig, $action, $ucodes, $pnts_sav);
297 log_points($user->ip, $curtime, $user, "STAT:BRISKIN5:FINISH_GAME", "DATABASE CONNECTION FAILED");
299 log_points($user->ip, $curtime, $user, "STAT:BRISKIN5:FINISH_GAME", $plist);
302 $table->game_init(&$bri->user);
307 static function game_description($act, $form, $old_mult, $win = -1, $win_name = "?1?", $fri = -1, $fri_name = "?2?",
308 $old_pnt = -1, $old_asta_pnt = -1, $old_tourn_pts = -1)
310 GLOBAL $G_lang, $mlang_bin5_rules;
312 if ($form == 'html') {
317 $win_name = xcape($win_name);
318 $fri_name = xcape($fri_name);
327 if ($act == BIN5_RULES_OLDSCHEMA) {
330 else if ($act == BIN5_RULES_ALLPASS) {
331 return (sprintf($mlang_bin5_rules['info_alpa'][$G_lang],
332 $tg_br, $tg_hr, $tg_bo, $tg_bc));
334 else if ($act == BIN5_RULES_ABANDON) {
335 return (sprintf($mlang_bin5_rules['info_aban'][$G_lang],
336 $tg_br, $tg_hr, $tg_bo, $tg_bc,
340 $wol = static::game_result($old_asta_pnt, $old_pnt);
344 if ($win != $fri) { // not alone case
345 /* 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" */
347 $noty .= sprintf($mlang_bin5_rules['info_part'][$G_lang],
348 $tg_br, $tg_hr, $tg_bo, $tg_bc,
352 if ($old_pnt == 120) {
353 $noty .= sprintf($mlang_bin5_rules['info_capp'][$G_lang],
354 $tg_br, $tg_hr, $tg_bo, $tg_bc );
357 if ($old_asta_pnt > 61) {
358 $noty .= sprintf($mlang_bin5_rules['info_alea'][$G_lang],
359 $tg_br, $tg_hr, $tg_bo, $tg_bc,
360 $old_asta_pnt, $old_pnt,
361 ($wol == 1 ? $mlang_bin5_rules['info_win'][$G_lang] :
362 ($wol == 0 ? $mlang_bin5_rules['info_peer'][$G_lang] :
363 $mlang_bin5_rules['info_lost'][$G_lang])));
366 $noty .= sprintf($mlang_bin5_rules['info_more'][$G_lang],
367 $tg_br, $tg_hr, $tg_bo, $tg_bc,
369 ($wol == 1 ? $mlang_bin5_rules['info_win'][$G_lang] :
370 ($wol == 0 ? $mlang_bin5_rules['info_peer'][$G_lang] :
371 $mlang_bin5_rules['info_lost'][$G_lang])));
372 } // else of if ($old_asta_pnt > 61) {
373 } // else of if ($old_pnt == 120) {
374 } // if ($win != $fri) { // not alone case
376 $noty .= sprintf($mlang_bin5_rules['info_alon'][$G_lang],
377 $tg_br, $tg_hr, $tg_bo, $tg_bc,
380 if ($old_pnt == 120) {
381 $noty .= sprintf($mlang_bin5_rules['info_acap'][$G_lang],
382 $tg_br, $tg_hr, $tg_bo, $tg_bc);
385 if ($old_asta_pnt > 61) {
386 $noty .= sprintf($mlang_bin5_rules['info_aleaa'][$G_lang],
387 $tg_br, $tg_hr, $tg_bo, $tg_bc,
388 $old_asta_pnt, $old_pnt,
389 ($wol == 1 ? $mlang_bin5_rules['info_win'][$G_lang] :
390 ($wol == 0 ? $mlang_bin5_rules['info_peer'][$G_lang] :
391 $mlang_bin5_rules['info_lost'][$G_lang])));
394 $noty .= sprintf($mlang_bin5_rules['info_morea'][$G_lang],
395 $tg_br, $tg_hr, $tg_bo, $tg_bc,
397 ($wol == 1 ? $mlang_bin5_rules['info_win'][$G_lang] :
398 ($wol == 0 ? $mlang_bin5_rules['info_peer'][$G_lang] :
399 $mlang_bin5_rules['info_lost'][$G_lang])));
405 $old_multer = static::s_multer($old_mult, $old_asta_pnt);
406 if ($old_multer > 1) {
407 $noty .= sprintf($mlang_bin5_rules['info_omul'][$G_lang],
408 $tg_br, $tg_hr, $tg_bo, $tg_bc,
409 multoval($old_multer));
411 $noty .= sprintf('%2$s', $tg_br, $tg_hr);
415 } // class Rules_old_rules