From 44adf43ccb058fb76e7bdbb18917ca86a7f7ec29 Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Sun, 17 Jun 2007 18:55:34 +0200 Subject: NEW FEATURE: reuse random numbers from old games random numbers generated for old games are reused in case none of the players were in that old game. Will be interesting how different people play with the same hand ;) --- db.php | 15 +++++++++++++++ functions.php | 15 +++++++++++++-- index.php | 2 +- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/db.php b/db.php index 935c848..a444360 100644 --- 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 diff --git a/functions.php b/functions.php index 997ba43..4f33f1e 100644 --- a/functions.php +++ b/functions.php @@ -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; diff --git a/index.php b/index.php index a2cf35b..fa828da 100644 --- 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 */ -- cgit v1.2.3-18-g5258