Merge branch 'dealing-reuse'
authorArun Persaud <arun@nubati.net>
Sun, 17 Jun 2007 16:57:21 +0000 (18:57 +0200)
committerArun Persaud <arun@nubati.net>
Sun, 17 Jun 2007 16:57:21 +0000 (18:57 +0200)
db.php
functions.php
index.php

diff --git a/db.php b/db.php
index 935c8486660d3d8453596dc65fac6db4f587fe7d..a44436043228c57c132c9367425e58756aa6bfaf 100644 (file)
--- a/db.php
+++ b/db.php
@@ -764,4 +764,19 @@ function DB_get_PREF($myid)
     return;
 }
 
+function DB_get_unused_randomnumbers($userstr)
+{
+  $queryresult = mysql_query("SELECT randomnumbers,Game.id FROM Game ".
+                            "  LEFT JOIN Hand ON Hand.game_id=Game.id ".
+                            "                 AND  user_id not in (".$userstr.")".
+                            "  GROUP BY  Game.id ".
+                            "  HAVING num=4");
+  
+  $r = mysql_fetch_array($queryresult,MYSQL_NUM);
+  if($r)
+    return $r[0];
+  else
+    return "";
+}
+
 ?>
\ No newline at end of file
index 39cc2a5555c8d9ddc23503b01a1f33bd4263bad9..3a650a2d94ca3dadb31f418595a962b84d528719 100644 (file)
@@ -422,7 +422,7 @@ function card_value($card)
 }
 
 
-function  create_array_of_random_numbers()
+function  create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD)
 {
   global $debug;
 
@@ -445,10 +445,21 @@ function  create_array_of_random_numbers()
     }
   else
     {
+      /* check if we can find a game were non of the player was involved and return 
+       * cards insted 
+       */
+      $userstr = implode(",",array($useridA,$useridB,$useridC,$useridD));
+      $randomnumbers = DB_get_unused_randomnumbers($userstr);
+      $randomnumbers = explode(":",$randomnumbers);
+      
+      if(sizeof($randomnumbers)==48)
+       return $randomnumbers;
+      
+      /* need to create new numbers */
       for($i=0;$i<48;$i++)
        $r[$i]=$i+1;
       
-      shuffle($r);
+      shuffle($r); 
     };
 
   return $r;
index 291d93097e1699c1165eb543d16205c8400ef2aa..dd1ce58889d298ef2ef1ba658b8be8ec21fa19b9 100644 (file)
--- a/index.php
+++ b/index.php
@@ -72,7 +72,7 @@ if(myisset("new"))
     $useridD  = DB_get_userid_by_name($PlayerD);
     
     /* create random numbers */
-    $randomNR       = create_array_of_random_numbers();
+    $randomNR       = create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD);
     $randomNRstring = join(":",$randomNR);
     
     /* get ruleset information or create new one */