foxes should now work correctly
authorarun <arun@nubati.net>
Mon, 12 Feb 2007 18:25:29 +0000 (18:25 +0000)
committerarun <arun>
Mon, 12 Feb 2007 18:25:29 +0000 (18:25 +0000)
functions.php
index.php
output.php

index 31167e9f78de1b4dd8097f8576234596f733f534..ce549c1fa2a865f87172588aa869a70ce4e152c8 100644 (file)
@@ -78,6 +78,7 @@ function compare_cards($a,$b,$game)
 
   global $CARDS;
   global $RULES;
 
   global $CARDS;
   global $RULES;
+  global $GAME;
 
   /* first map all cards to the odd number, 
    * this insure that the first card wins the trick 
 
   /* first map all cards to the odd number, 
    * this insure that the first card wins the trick 
@@ -93,6 +94,20 @@ function compare_cards($a,$b,$game)
     {
     case "normal":
     case "silent":
     {
     case "normal":
     case "silent":
+      if($RULES["schweinchen"]=="both" && $GAME["schweinchen"])
+       {
+         if($a == 19 || $a == 20 )
+           return 1;
+         if($b == 19 || $b == 20 )
+           return 0;
+       };
+      if($RULES["schweinchen"]=="second" && $GAME["schweinchen"]==3)
+       {
+         if($a == 19 || $a == 20 )
+           return 1;
+         if($b == 19 || $b == 20 )
+           return 0;
+       };
     case "trump":
     case "heart":
     case "spade":
     case "trump":
     case "heart":
     case "spade":
@@ -102,6 +117,7 @@ function compare_cards($a,$b,$game)
          return 0;        /* second one wins.*/
     }
   
          return 0;        /* second one wins.*/
     }
   
+  /* normal case */
   if(is_trump($a) && is_trump($b) && $a<=$b)
     return 1;
   else if(is_trump($a) && is_trump($b) )
   if(is_trump($a) && is_trump($b) && $a<=$b)
     return 1;
   else if(is_trump($a) && is_trump($b) )
@@ -221,6 +237,8 @@ function check_wedding($cards)
 
 function count_trump($cards)
 {
 
 function count_trump($cards)
 {
+  global $RULES;
+
   $trump = 0;
 
   /* count each trump */
   $trump = 0;
 
   /* count each trump */
@@ -228,14 +246,23 @@ function count_trump($cards)
     if( (int)($c) <27) 
       $trump++;
 
     if( (int)($c) <27) 
       $trump++;
 
-  /* subtract foxes */
-  if( in_array("19",$cards))
-    $trump--;
-  if( in_array("20",$cards) )
-    $trump--;
-  /* add one, in case the player has both foxes (schweinchen) */
-  if( in_array("19",$cards) && in_array("20",$cards) )
-    $trump++;
+  switch($RULES["schweinchen"])
+    {
+    case "none":
+      break;
+    case "second":
+    case "secondaftercall":
+      /* add one, in case the player has both foxes (schweinchen) */
+      if( in_array("19",$cards) && in_array("20",$cards) )
+       $trump++;
+    case "both":
+      /* subtract foxes */
+      if( in_array("19",$cards))
+       $trump--;
+      if( in_array("20",$cards) )
+       $trump--;
+      break;
+    }
 
   return $trump;
 }
 
   return $trump;
 }
@@ -391,11 +418,12 @@ function  create_array_of_random_numbers()
   $r = array();
   $a = array();
   
   $r = array();
   $a = array();
   
-  for($i=1;$i<49;$i++)
-    $a[$i]=$i;
-  
-  $r = array_rand($a,48);
+  for($i=0;$i<48;$i++)
+    $a[$i]=$i+1;
   
   
+#  $r = array_rand($a,48);
+  $r =$a; 
   return $r;
 }
 
   return $r;
 }
 
@@ -492,7 +520,7 @@ function set_gametype($gametype)
       $CARDS["clubs"]    = array('27','28','29','30','31','32','33','34');
       $CARDS["spades"]   = array('35','36','37','38','39','40','41','42');
       $CARDS["hearts"]   = array('43','44','45','46','47','48');
       $CARDS["clubs"]    = array('27','28','29','30','31','32','33','34');
       $CARDS["spades"]   = array('35','36','37','38','39','40','41','42');
       $CARDS["hearts"]   = array('43','44','45','46','47','48');
-      $CARDS["foxes"]    = array('21','22');
+      $CARDS["foxes"]    = array('19','20');
       if($RULES["dullen"]=='none')
        {
          $CARDS["trump"]    = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16', 
       if($RULES["dullen"]=='none')
        {
          $CARDS["trump"]    = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16', 
index eded836ac1c86f532853864c5cecc121c2269720..302ec69054b52d748b5eea1eb6cc665929ea86df 100644 (file)
--- a/index.php
+++ b/index.php
@@ -229,6 +229,19 @@ else if(myisset("me"))
     echo "schweinchen: ".$r[3]."<br />";
     echo "</div>\n";
     
     echo "schweinchen: ".$r[3]."<br />";
     echo "</div>\n";
     
+    /* does anyone have both foxes */
+    $GAME["schweinchen"]=0; 
+    for($i=1;$i<5;$i++)
+      {
+       $hash  = DB_get_hash_from_game_and_pos($gameid,$i);
+       $cards = DB_get_all_hand($hash);
+       if( in_array("19",$cards) && in_array("20",$cards) )
+         {
+           $GAME["schweinchen"]=1;
+           $GAME["schweinchen-who"]=$hash;
+         }
+      };
+        
 
     /* mystatus gets the player through the different stages of a game.
      * start:    yes/no
 
     /* mystatus gets the player through the different stages of a game.
      * start:    yes/no
@@ -486,17 +499,16 @@ else if(myisset("me"))
                break;
              if($usersick == "solo" && $gametype =="solo")
                break;
                break;
              if($usersick == "solo" && $gametype =="solo")
                break;
-           };    
+                         
+           };
+
+         if( $gametype != "solo")
+           if($GAME["schweinchen"] && $RULES["schweinchen"]=="both" )
+             echo DB_get_name_by_hash($GAME["schweinchen-who"])." has Schweinchen. <br />";
+         
          echo "<br />\n";
          
          echo "<br />\n";
          
-         /* check for Schweinchen (cards 21,22) */
-         if($RULES["schweinchen"]=="both")
-           {
-             set_gametype($gametype);
-             echo "TODO: check if one user has both foxes and output here ";
-           }    
-
-         /* finished the setup, go to next stage unless there is a case of poverty*/
+         /* finished the setup, set re/contra parties if possible, go to next stage unless there is a case of poverty*/
          switch($gametype)
            {
            case "solo":
          switch($gametype)
            {
            case "solo":
@@ -509,7 +521,8 @@ else if(myisset("me"))
              DB_set_hand_status_by_hash($me,'play');
              break;
            case "wedding":
              DB_set_hand_status_by_hash($me,'play');
              break;
            case "wedding":
-             echo "Don't know who will be Re and Contra, you need to figure that out at the end of the game yourself <br />\n";
+             echo "Don't know who will be Re and Contra, you need to ".
+               "figure that out at the end of the game yourself <br />\n";
              DB_set_hand_status_by_hash($me,'play');
              break;
            case "normal":
              DB_set_hand_status_by_hash($me,'play');
              break;
            case "normal":
@@ -567,7 +580,7 @@ else if(myisset("me"))
       else
        $gametype="normal";
       
       else
        $gametype="normal";
       
-      set_gametype($gametype);
+      set_gametype($gametype); /* this sets the $CARDS variable */
       
       /* get some infos about the game */
       $gamestatus = DB_get_game_status_by_gameid($gameid);
       
       /* get some infos about the game */
       $gamestatus = DB_get_game_status_by_gameid($gameid);
@@ -660,6 +673,10 @@ else if(myisset("me"))
          $trick   = $r[3];
          $comment = $r[4];
          
          $trick   = $r[3];
          $comment = $r[4];
          
+         /* check if first schweinchen has been played */
+         if($r[0] == 19 || $r[0] == 20 )
+           $GAME["schweinchen"]++;
+         
          /* save card to be able to find the winner of the trick later */
          $play[$seq] = array("card"=>$r[0],"pos"=>$pos); 
          
          /* save card to be able to find the winner of the trick later */
          $play[$seq] = array("card"=>$r[0],"pos"=>$pos); 
          
@@ -744,10 +761,24 @@ else if(myisset("me"))
          
          if($handcardid)
            {
          
          if($handcardid)
            {
+             $comment = "";
+
              /* mark card as played */
              mysql_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".
                          DB_quote_smart($card));
              
              /* mark card as played */
              mysql_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".
                          DB_quote_smart($card));
              
+             /* check for schweinchen */
+             echo "schweinchen = ".$GAME["schweinchen"]." --$card-<br />";
+             if($card == 19 || $card == 20 )
+               {
+                 $GAME["schweinchen"]++;
+                 if($GAME["schweinchen"]==3 && $RULES["schweinchen"]=="second" )
+                   $comment="Schweinchen! ";
+                 if($RULES["schweinchen"]=="both" )
+                   $comment="Schweinchen! ";
+                 echo "schweinchen = ".$GAME["schweinchen"]." ---<br />";
+               }
+
              /* get trick id or start new trick */
              $a = DB_get_current_trickid($gameid);
              $trickid  = $a[0];
              /* get trick id or start new trick */
              $a = DB_get_current_trickid($gameid);
              $trickid  = $a[0];
@@ -758,9 +789,11 @@ else if(myisset("me"))
              /* check for coment */
              if(myisset("comment"))
                {
              /* check for coment */
              if(myisset("comment"))
                {
-                 DB_insert_comment($_REQUEST["comment"],$playid,$myid);
+                 $comment.=$_REQUEST["comment"];
                };  
                };  
-             
+             if($comment != "")
+               DB_insert_comment($comment,$playid,$myid);
+
              /* display played card */
              echo "<div class=\"card\">";
              echo " you played  <br />";
              /* display played card */
              echo "<div class=\"card\">";
              echo " you played  <br />";
index d20d725af1fe1873da2bf9353868133ec0c8fbf9..ba3c47352b92987f6edd89588c5e86f13b8aa12e 100644 (file)
@@ -111,11 +111,10 @@ function output_form_for_new_game($names)
        echo "     <option>$name</option>\n";
     }
     echo "  </select>\n";
        echo "     <option>$name</option>\n";
     }
     echo "  </select>\n";
-    unset($names[$randkey]);
    }
 ?>   
    <h2> Rules </h2> 
    }
 ?>   
    <h2> Rules </h2> 
-      
+      <p> Some areas are grayed out which means that the rule is not implemented yet and therefore cannot be selected </p>
       <p> ten of hearts: 
          <ul>
          <li> <input type="radio" name="dullen" value="none" /> just normal non-trump  </li>
       <p> ten of hearts: 
          <ul>
          <li> <input type="radio" name="dullen" value="none" /> just normal non-trump  </li>
@@ -123,20 +122,20 @@ function output_form_for_new_game($names)
          <li> <input type="radio" name="dullen" value="secondwins" checked="checked" /> second ten of hearts wins the trick </li>
          </ul>
       </p>
          <li> <input type="radio" name="dullen" value="secondwins" checked="checked" /> second ten of hearts wins the trick </li>
          </ul>
       </p>
-      <p> schweinchen (both foxes): 
+      <p> schweinchen (both foxes), only in normal games or silent solos
         <ul>
         <ul>
-        <li> <input type="radio" name="schweinchen" value="none" /> none </li>
+        <li> <input type="radio" name="schweinchen" value="none" checked="checked" /> none </li>
         <li> <input type="radio" name="schweinchen" value="both" /> 
               both become highest trump (automatic call at beginning of the game)
         <li> <input type="radio" name="schweinchen" value="both" /> 
               both become highest trump (automatic call at beginning of the game)
-              (does not work yet) </li>
-        <li> <input type="radio" name="schweinchen" value="second" checked="checked" /> 
-              first one normal, second one becomes highest (call during the game) (does not work yet) </li>
-        <li> <input type="radio" name="schweinchen" value="secondaftercall"  /> 
-             second one become highest only in case re/contra was announced 
-            (does not work yet)</li>
-      </ul>
+        </li>
+        <li> <input type="radio" name="schweinchen" value="second" /> 
+              first one normal, second one becomes highest (call during the game) </li>
+        <li> <input type="radio" name="schweinchen" value="secondaftercall"  disabled="disabled" /> 
+      second one become highest only in case re/contra was announced (not working yet)
+        </li>
+        </ul>
       </p>
       </p>
-   
+      
    <input type="submit" value="start game" />
  </form>
 <?php
    <input type="submit" value="start game" />
  </form>
 <?php