NEW FEATURE: reuse random numbers from old games
[e-DoKo.git] / functions.php
index 893f916c68271ba1d0151b83ee288969034094e1..4f33f1e41c00019c5e569621f2193d14b2db6e03 100644 (file)
@@ -423,7 +423,7 @@ function card_value($card)
 }
 
 
-function  create_array_of_random_numbers()
+function  create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD)
 {
   global $debug;
 
@@ -446,10 +446,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;
@@ -656,7 +667,7 @@ function can_call($what,$hash)
   $gameid   = DB_get_gameid_by_hash($hash);
   $gametype = DB_get_gametype_by_gameid($gameid);
 
-  $NRcards  = count(DB_get_hand($me));
+  $NRcards  = count(DB_get_hand($hash));
   
   $NRallcards = 0;
   for ($i=1;$i<5;$i++)