index_wr 'auction' refactoring
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Sat, 4 Mar 2017 17:56:59 +0000 (18:56 +0100)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Sat, 4 Mar 2017 17:56:59 +0000 (18:56 +0100)
TODO.txt
web/briskin5/Obj/briskin5.phh
web/briskin5/Obj/rules_together17.phh [new file with mode: 0644]
web/briskin5/index_wr.php

index 03d018e..c58de34 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -21,6 +21,7 @@
      DONE - show current rules
      DONE - select tournment dropdown menu (send a 'cont' like message for each change)
      - increase constraint for rules change
+     - strange 4 abandoned rule for auction
      - check of max points
      - check of suit at the end of bet
      - new rules for 'together for fun' turnment
index d1bbbcc..3eadc14 100644 (file)
@@ -1720,6 +1720,7 @@ function show_table(&$bri, &$user, $sendstep, $is_transition, $is_again)
                             $table->asta_card);
         }
         else {
+            // FIXME - RULES to be able to abandon table
             /* show auction */
             if ($table_pos == ($table->gstart % BIN5_PLAYERS_N) &&
                 $table->asta_win == -1)
diff --git a/web/briskin5/Obj/rules_together17.phh b/web/briskin5/Obj/rules_together17.phh
new file mode 100644 (file)
index 0000000..0570868
--- /dev/null
@@ -0,0 +1,111 @@
+<?php
+/*
+ *  brisk - rules_together17.phh
+ *
+ *  Copyright (C) 2017 Matteo Nastasi
+ *                          mailto: nastasi@alternativeoutput.it
+ *                                  matteo.nastasi@milug.org
+ *                          web: http://www.alternativeoutput.it
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details. You should have received a
+ * copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc, 59 Temple Place -
+ * Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+require_once("briskin5.phh");
+require_once("rules_base.phh");
+
+class Rules_together17 extends Rules_no_draw {
+    function __construct($table)
+    {
+        parent::__construct($table);
+        $this->id = 4;
+    }
+
+    function tourn_points(&$user, $user_pos)
+    {
+        $card = $this->table->card;
+        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]; 
+            }
+        }
+    }
+
+    function tourn_points_max($user)
+    {
+        
+        $mx = 0;
+        for ($i = 0 ; $i < 4 ; $i++) {
+            error_log("tourn_pts_max ");
+            error_log(print_r($user->asta_tourn_pts, TRUE));
+            if ($user->asta_tourn_pts[$i] > $mx) {
+                $mx = $user->asta_tourn_pts[$i];
+            }
+        }
+
+        return $mx;
+    }
+
+    function rules_asta(&$bri, $curtime, $action, $user, &$ret_s, $a_card, $a_pnt) {
+        /*
+Per le chiamate da 62 a 70 bisognerà avere 13 punti ( esempi.: asso e fante oppure tre
+e cavallo oppure re, cavallo, fante, sette, sei, cinque, quattro) ;
+Per chiamate da 71 ad 80 bisognerà avere 19 punti ( esempi.: asso, re, cavallo e 6
+oppure tre, re, fante, 7, 6 e 5 );
+Per chiamate da 81 a 90 bisognerà avere 23 punti ( esempi.: asso, tre e fante oppure
+asso, re, cavallo, fante, 6, 5 e 4);
+Per chiamate da 91 a 100 bisognerà avere 25 punti ( esempi.: asso, tre, re e 7 oppure
+asso, tre, cavallo e fante );
+Per chiamate da 101 a 120 bisognerà avere 28 punti ( esempi.:asso, tre, re e cavallo
+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;
+            }
+
+            return TRUE;
+        }
+        return FALSE;
+    }
+
+} // class Rules_no_draw
+
+?>
\ No newline at end of file
index ee5d304..8719466 100644 (file)
@@ -181,11 +181,17 @@ function bin5_index_wr_main(&$bin5, $remote_addr_full, $get, $post, $cookie)
                 }
             }
             else if ($argz[0] == 'asta') {
-                $again = TRUE;
-
+                $success = FALSE;
                 $index_cur = $table->gstart % BIN5_PLAYERS_N;
-                if ($user->table_pos == $index_cur &&
-                    $table->asta_pla[$index_cur]) {
+                do {
+                    $ret_s = '';
+
+                    if ($user->table_pos != $index_cur ||
+                        !$table->asta_pla[$index_cur]) {
+                        $ret_s = 'grave inconsistenza';
+                        break;
+                    }
+
                     $a_card = $argz[1];
                     $a_pnt  = $argz[2];
 
@@ -197,139 +203,127 @@ function bin5_index_wr_main(&$bin5, $remote_addr_full, $get, $post, $cookie)
                         $table->asta_pla[$index_cur] = FALSE;
                         $user->asta_card  = -1;
                         $table->asta_pla_n--;
-                        $again = FALSE;
                     }
                     else if ($a_card <= 9) {
-                        $ret_s = "";
-                        if ($table->rules->engine(&$bin5, $curtime, BIN5_RULES_ASTA, $user, $ret_s, $a_card, $a_pnt)) {
-                            $again = FALSE;
-                        }
-
-                        if ($again == FALSE) {
-                            log_wr("NUOVI ORZI.");
-                            $user->asta_card  = $a_card;
-                            $table->asta_card = $a_card;
-                            if ($a_card == 9) {
-                                $user->asta_pnt   = $a_pnt;
-                                $table->asta_pnt  = $a_pnt;
-                            }
+                        if (!$table->rules->engine(&$bin5, $curtime, BIN5_RULES_ASTA, $user, $ret_s, $a_card, $a_pnt)) {
+                            break;
                         }
                     }
+                    else {
+                        break;
+                    }
 
-                    if ($again) { // Qualcosa non andato bene, rifare
-                        $ret = sprintf('gst.st = %d; asta_pnt_set(%d);', $user->step+1,
-                                       ($table->asta_pnt > 60 ? $table->asta_pnt + 1 : 61) );
-                        if ($ret_s != "") {
-                            $ret .= show_notify($ret_s, 0, $mlang_indwr['btn_close'][$G_lang], 400, 150);
-                        }
-                        $user->comm[$user->step % COMM_N] = $ret;
-                        $user->step_inc();
+                    /* next step */
+                    $showst = "show_astat(";
+                    for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
+                        $user_cur = &$bin5->user[$table->player[$i]];
+                        $showst .= sprintf("%s%d", ($i == 0 ? "" : ", "),
+                                           ($user_cur->asta_card < 9 ? $user_cur->asta_card : $user_cur->asta_pnt));
+                    }
+                    if (BIN5_PLAYERS_N == 3)
+                        $showst .= ",-2,-2";
+                    $showst .= ");";
 
-                        log_wr("Ripetere.");
+                    $maxcard = -2;
+                    for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
+                        $user_cur = &$bin5->user[$table->player[$i]];
+                        if ($maxcard < $user_cur->asta_card)
+                            $maxcard = $user_cur->asta_card;
                     }
-                    else {
-                        /* next step */
-                        $showst = "show_astat(";
-                        for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
-                            $user_cur = &$bin5->user[$table->player[$i]];
-                            $showst .= sprintf("%s%d", ($i == 0 ? "" : ", "),
-                                               ($user_cur->asta_card < 9 ? $user_cur->asta_card : $user_cur->asta_pnt));
+
+                    if (($table->asta_pla_n > ($maxcard > -1 ? 1 : 0)) &&
+                        !($table->asta_card == 9 && $table->asta_pnt == 120)) {
+                        log_wr("ALLOPPA QUI");
+                        for ($i = 1 ; $i < BIN5_PLAYERS_N ; $i++) {
+                            $index_next = ($table->gstart + $i) % BIN5_PLAYERS_N;
+                            if ($table->asta_pla[$index_next]) {
+                                log_wr("GSTART 1");
+                                $table->gstart += $i;
+                                break;
+                            }
                         }
-                        if (BIN5_PLAYERS_N == 3)
-                            $showst .= ",-2,-2";
-                        $showst .= ");";
 
-                        $maxcard = -2;
+
                         for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
                             $user_cur = &$bin5->user[$table->player[$i]];
-                            if ($maxcard < $user_cur->asta_card)
-                                $maxcard = $user_cur->asta_card;
+                            $ret = sprintf('gst.st = %d; %s', $user_cur->step+1, $showst);
+                            if ($user_cur->table_pos == ($table->gstart % BIN5_PLAYERS_N))
+                                $ret .= sprintf('dispose_asta(%d,%d, %s); remark_on();',
+                                                $table->asta_card + 1, $table->asta_pnt+1, ($user_cur->handpt <= 2 ? "true" : "false"));
+                            else
+                                $ret .= sprintf('dispose_asta(%d,%d, %s); remark_off();',
+                                                $table->asta_card + 1, -($table->asta_pnt+1), ($user_cur->handpt <= 2 ? "true" : "false"));
+                            $user_cur->comm[$user_cur->step % COMM_N] = $ret;
+                            $user_cur->step_inc();
                         }
+                    }
+                    else if ($table->asta_pla_n == 0) {
+                        log_wr("PASSANO TUTTI!");
 
-                        if (($table->asta_pla_n > ($maxcard > -1 ? 1 : 0)) &&
-                            !($table->asta_card == 9 && $table->asta_pnt == 120)) {
-                            log_wr("ALLOPPA QUI");
-                            for ($i = 1 ; $i < BIN5_PLAYERS_N ; $i++) {
-                                $index_next = ($table->gstart + $i) % BIN5_PLAYERS_N;
-                                if ($table->asta_pla[$index_next]) {
-                                    log_wr("GSTART 1");
-                                    $table->gstart += $i;
-                                    break;
-                                }
-                            }
-
-
+                        if ($table->rules->engine(&$bin5, $curtime, BIN5_RULES_ALLPASS, $user)) {
                             for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
                                 $user_cur = &$bin5->user[$table->player[$i]];
-                                $ret = sprintf('gst.st = %d; %s', $user_cur->step+1, $showst);
-                                if ($user_cur->table_pos == ($table->gstart % BIN5_PLAYERS_N))
-                                    $ret .= sprintf('dispose_asta(%d,%d, %s); remark_on();',
-                                                    $table->asta_card + 1, $table->asta_pnt+1, ($user_cur->handpt <= 2 ? "true" : "false"));
-                                else
-                                    $ret .= sprintf('dispose_asta(%d,%d, %s); remark_off();',
-                                                    $table->asta_card + 1, -($table->asta_pnt+1), ($user_cur->handpt <= 2 ? "true" : "false"));
+
+                                $ret = sprintf('gst.st = %d;', $user_cur->step+1);
+                                $ret .= show_table(&$bin5,&$user_cur,$user_cur->step+1, TRUE, TRUE);
                                 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
                                 $user_cur->step_inc();
                             }
                         }
-                        else if ($table->asta_pla_n == 0) {
-                            log_wr("PASSANO TUTTI!");
-
-                            if ($table->rules->engine(&$bin5, $curtime, BIN5_RULES_ALLPASS, $user)) {
-                                for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
-                                    $user_cur = &$bin5->user[$table->player[$i]];
-
-                                    $ret = sprintf('gst.st = %d;', $user_cur->step+1);
-                                    $ret .= show_table(&$bin5,&$user_cur,$user_cur->step+1, TRUE, TRUE);
-                                    $user_cur->comm[$user_cur->step % COMM_N] = $ret;
-                                    $user_cur->step_inc();
-                                }
-                            }
+                    }
+                    else {
+                        log_wr("FINITA !");
+                        // if a_pnt == 120 supergame ! else abbandono
+                        if ($a_pnt == 120 || $user->asta_card != -1) {
+                            $chooser = $index_cur;
+                            for ($i = 1 ; $i < BIN5_PLAYERS_N ; $i++)
+                                if ($i != $chooser)
+                                    $table->asta_pla[$i] = FALSE;
                         }
                         else {
-                            log_wr("FINITA !");
-                            // if a_pnt == 120 supergame ! else abbandono
-                            if ($a_pnt == 120 || $user->asta_card != -1) {
-                                $chooser = $index_cur;
-                                for ($i = 1 ; $i < BIN5_PLAYERS_N ; $i++)
-                                    if ($i != $chooser)
-                                        $table->asta_pla[$i] = FALSE;
-                            }
-                            else {
-                                /*
-                                  $user->comm[$user->step % COMM_N] = sprintf( "gst.st = %d; dispose_asta(%d, %d, false); remark_off();",
-                                  $user->step+1, $table->asta_card + 1,-($table->asta_pnt));
-                                  $user->step_inc();
-                                */
-                                for ($i = 1 ; $i < BIN5_PLAYERS_N ; $i++) {
-                                    $chooser = ($table->gstart + $i) % BIN5_PLAYERS_N;
-                                    if ($table->asta_pla[$chooser]) {
-                                        break;
-                                    }
+                            /*
+                              $user->comm[$user->step % COMM_N] = sprintf( "gst.st = %d; dispose_asta(%d, %d, false); remark_off();",
+                              $user->step+1, $table->asta_card + 1,-($table->asta_pnt));
+                              $user->step_inc();
+                            */
+                            for ($i = 1 ; $i < BIN5_PLAYERS_N ; $i++) {
+                                $chooser = ($table->gstart + $i) % BIN5_PLAYERS_N;
+                                if ($table->asta_pla[$chooser]) {
+                                    break;
                                 }
                             }
-                            $table->asta_win = $chooser;
-
-                            for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
-                                $user_cur = &$bin5->user[$table->player[$i]];
-                                $ret = sprintf('gst.st = %d; %s dispose_asta(%d, %d, false);', $user_cur->step+1, $showst,
-                                               $table->asta_card + 1,-($table->asta_pnt));
+                        }
+                        $table->asta_win = $chooser;
 
-                                if ($i == $chooser) {
-                                    $ret .= "choose_seed(". $table->asta_card."); remark_on();";
-                                }
-                                else {
-                                    $ret .= "remark_off();";
-                                }
+                        for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
+                            $user_cur = &$bin5->user[$table->player[$i]];
+                            $ret = sprintf('gst.st = %d; %s dispose_asta(%d, %d, false);', $user_cur->step+1, $showst,
+                                           $table->asta_card + 1,-($table->asta_pnt));
 
-                                $user_cur->comm[$user_cur->step % COMM_N] = $ret;
-                                $user_cur->step_inc();
+                            if ($i == $chooser) {
+                                $ret .= "choose_seed(". $table->asta_card."); remark_on();";
+                            }
+                            else {
+                                $ret .= "remark_off();";
                             }
+
+                            $user_cur->comm[$user_cur->step % COMM_N] = $ret;
+                            $user_cur->step_inc();
                         }
                     }
-                }
-                else {
-                    log_wr("NON CI SIAMO");
+                    $success = TRUE;
+                } while(FALSE);
+
+                if (!$success) {
+                    $ret = sprintf('gst.st = %d; asta_pnt_set(%d);', $user->step+1,
+                                   ($table->asta_pnt > 60 ? $table->asta_pnt + 1 : 61) );
+                    if ($ret_s != "") {
+                        $ret .= show_notify($ret_s, 0, $mlang_indwr['btn_close'][$G_lang], 400, 150);
+                    }
+                    $user->comm[$user->step % COMM_N] = $ret;
+                    $user->step_inc();
+
+                    log_wr("Ripetere.");
                 }
             }
             /*  asta::choose */