From 850378a3e2da48d387dc565cc6e3c2b47f12e34d Mon Sep 17 00:00:00 2001
From: Arun Persaud
Date: Sat, 13 Mar 2010 15:59:07 -0800
Subject: [PATCH] NEW FEATURE: having only low trump (fox and below) can now be
a Vorbehalt
The low trump can either be treated as poverty or similar to 5 nines, that is the game is canceled unless someone plays a solo.
Also minor code cleanup.
---
create_database.sql | 7 ++--
include/db.php | 15 ++++---
include/functions.php | 52 +++++++++++++++++++----
include/game.php | 98 +++++++++++++++++++++++++++++--------------
include/newgame.php | 5 ++-
include/output.php | 40 +++++++++++++++---
update_db.php | 16 ++++++-
7 files changed, 176 insertions(+), 57 deletions(-)
diff --git a/create_database.sql b/create_database.sql
index e9577c9..71a6dfc 100644
--- a/create_database.sql
+++ b/create_database.sql
@@ -48,7 +48,7 @@ CREATE TABLE `Version` (
/*!40000 ALTER TABLE `Card` DISABLE KEYS */;
LOCK TABLES `Version` WRITE;
-INSERT INTO `Version` VALUES (1);
+INSERT INTO `Version` VALUES (2);
UNLOCK TABLES;
/*!40000 ALTER TABLE `Version` ENABLE KEYS */;
@@ -141,7 +141,7 @@ CREATE TABLE `Game` (
`sickness` int(11) default NULL,
`startplayer` tinyint(4) default '1',
`player` int(11) default NULL,
- `status` enum('pre','play','gameover','cancel-timedout','cancel-nines','cancel-trump','cancel-noplay') default NULL,
+ `status` enum('pre','play','gameover','cancel-timedout','cancel-nines','cancel-trump','cancel-noplay','cancel-lowtrump') default NULL,
`ruleset` int(11) default NULL,
`session` int(11) default NULL,
`id` int(11) NOT NULL auto_increment,
@@ -171,6 +171,7 @@ CREATE TABLE `Rulesets` (
`dullen` enum('none','firstwins','secondwins') default 'secondwins',
`schweinchen` enum ('none','both','second','secondaftercall') default 'second',
`call` enum ('1st-own-card','5th-card','9-cards') default '1st-own-card',
+ `lowtrump` enum('poverty','cancel','none') default 'poverty',
`id` int(11) NOT NULL auto_increment,
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
@@ -200,7 +201,7 @@ CREATE TABLE `Hand` (
`status` enum('start','init','check','poverty','play','gameover') default 'start',
`position` tinyint(4) NOT NULL default '0',
`party` enum('re','contra') default NULL,
- `sickness` enum('wedding','nines','poverty','solo') default NULL,
+ `sickness` enum('wedding','nines','poverty','solo','lowtrump') default NULL,
`solo` enum('trumpless','jack','queen','trump','club','spade','heart','silent') default NULL,
`point_call` enum('120','90','60','30','0') default NULL,
UNIQUE KEY `id` (`id`),
diff --git a/include/db.php b/include/db.php
index 5503a4a..2a927f5 100644
--- a/include/db.php
+++ b/include/db.php
@@ -30,7 +30,7 @@ if(!isset($HOST))
function DB_open()
{
- $version_needed = 1;
+ $version_needed = 2;
global $DB,$DB_user,$DB_host,$DB_database,$DB_password;
$DB = @mysql_connect($DB_host,$DB_user, $DB_password);
@@ -703,14 +703,15 @@ function DB_get_hashes_by_session($session,$user)
return $r;
}
-function DB_get_ruleset($dullen,$schweinchen,$call)
+function DB_get_ruleset($dullen,$schweinchen,$call,$lowtrump)
{
$r = array();
$result = DB_query("SELECT id FROM Rulesets WHERE".
" dullen=".DB_quote_smart($dullen)." AND ".
" Rulesets.call=".DB_quote_smart($call)." AND ".
- " schweinchen=".DB_quote_smart($schweinchen));
+ " schweinchen=".DB_quote_smart($schweinchen)." AND ".
+ " lowtrump=".DB_quote_smart($lowtrump));
if($result)
$r = DB_fetch_array($result);
@@ -722,6 +723,7 @@ function DB_get_ruleset($dullen,$schweinchen,$call)
$result = DB_query("INSERT INTO Rulesets VALUES (NULL, NULL, ".
DB_quote_smart($dullen).",".
DB_quote_smart($schweinchen).",".
+ DB_quote_smart($lowtrump).",".
DB_quote_smart($call).
", NULL)");
if($result)
@@ -834,9 +836,10 @@ function DB_get_RULES($gameid)
" LEFT JOIN Game ON Game.ruleset=Rulesets.id ".
" WHERE Game.id='$gameid'" );
- $RULES["dullen"] = $r[2];
- $RULES["schweinchen"] = $r[3];
- $RULES["call"] = $r[4];
+ $RULES['dullen'] = $r[2];
+ $RULES['schweinchen'] = $r[3];
+ $RULES['lowtrump'] = $r[4];
+ $RULES['call'] = $r[5];
return $RULES;
}
diff --git a/include/functions.php b/include/functions.php
index 173ccd4..a06f3d4 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -455,6 +455,39 @@ function count_trump($cards,$status='pregame')
return $trump;
}
+function check_low_trump($cards)
+{
+ global $RULES;
+
+ if($RULES['lowtrump']=='none')
+ return 0;
+
+ /* check if we have low trump */
+
+ $lowtrump=1;
+ foreach($cards as $card)
+ {
+ /* card a trump, but not a diamond? */
+ if( $card<19 )
+ $lowtrump=0;
+ }
+
+ /* handle case where player has schweinchen */
+ if( in_array("19",$cards) && in_array("20",$cards) )
+ switch($RULES["schweinchen"])
+ {
+ case "both":
+ case "second":
+ case "secondaftercall":
+ $lowtrump=0;
+ break;
+ case "none":
+ break;
+ }
+
+ return $lowtrump;
+}
+
function create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD)
{
global $debug;
@@ -467,12 +500,12 @@ function create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD)
$r[ 1]=2; $r[13]=23; $r[25]=14; $r[37]=38;
$r[ 2]=3; $r[14]=27; $r[26]=15; $r[38]=39;
$r[ 3]=4; $r[15]=16; $r[27]=28; $r[39]=40;
- $r[ 4]=5; $r[16]=17; $r[28]=29; $r[40]=41;
+ $r[ 4]=5; $r[16]=17; $r[28]=29; $r[40]=21;
$r[ 5]=18; $r[17]=6; $r[29]=30; $r[41]=42;
- $r[ 6]=21; $r[18]=7; $r[30]=31; $r[42]=43;
- $r[ 7]=22; $r[19]=8; $r[31]=32; $r[43]=44;
- $r[ 8]=45; $r[20]=9; $r[32]=19; $r[44]=33;
- $r[ 9]=46; $r[21]=10; $r[33]=20; $r[45]=24;
+ $r[ 6]=41; $r[18]=7; $r[30]=31; $r[42]=43;
+ $r[ 7]=22; $r[19]=8; $r[31]=32; $r[43]=20;
+ $r[ 8]=45; $r[20]=9; $r[32]=33; $r[44]=19;
+ $r[ 9]=46; $r[21]=10; $r[33]=44; $r[45]=24;
$r[10]=35; $r[22]=11; $r[34]=48; $r[46]=25;
$r[11]=36; $r[23]=12; $r[35]=34; $r[47]=26;
}
@@ -933,7 +966,7 @@ function display_table ()
echo " Schweinchen. ";
if($GT=="poverty" && $party=="re")
- if($sickness=="poverty")
+ if($sickness=="poverty" || ($RULES['lowtrump']=='poverty' && $sickness=='lowtrump'))
{
$userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
$cards = DB_get_all_hand($userhash);
@@ -948,7 +981,7 @@ function display_table ()
if($GT=="dpoverty")
if($party=="re")
- if($sickness=="poverty")
+ if($sickness=="poverty" || ($RULES['lowtrump']=='poverty' && $sickness=='lowtrump'))
{
$userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
$cards = DB_get_all_hand($userhash);
@@ -961,7 +994,7 @@ function display_table ()
else
echo " \" title=\"poverty partner\" />";
else
- if($sickness=="poverty")
+ if($sickness=="poverty" || ($RULES['lowtrump']=='poverty' && $sickness=='lowtrump'))
{
$userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
$cards = DB_get_all_hand($userhash);
@@ -1438,6 +1471,9 @@ function cancel_game($why,$gameid)
case 'noplay':
DB_query("UPDATE Game SET status='cancel-noplay' WHERE id=$gameid");
break;
+ case 'lowtrump':
+ DB_query("UPDATE Game SET status='cancel-lowtrump' WHERE id=$gameid");
+ break;
}
/* set each player to gameover */
$result = DB_query("SELECT id FROM Hand WHERE game_id=".DB_quote_smart($gameid));
diff --git a/include/game.php b/include/game.php
index 93ab461..3cc1d65 100644
--- a/include/game.php
+++ b/include/game.php
@@ -223,6 +223,7 @@ if($session)
echo " 10ofhearts : {$RULES['dullen']} \n";
echo " schweinchen: {$RULES['schweinchen']} \n";
echo " call: {$RULES['call']} \n";
+ echo " lowtrump: {$RULES['lowtrump']} \n";
echo " \n \n";
/* show score */
@@ -400,7 +401,7 @@ switch($mystatus)
$mycards = DB_get_hand($me);
$mycards = mysort($mycards,$gametype);
- if(!myisset('solo','wedding','poverty','nines') )
+ if(!myisset('solo','wedding','poverty','nines','lowtrump') )
{
/* output sickness of other playes, in case the already selected and are sitting in front of the current player */
echo "\n
\n";
@@ -439,9 +440,10 @@ switch($mystatus)
/* check if someone selected more than one sickness */
$Nsickness = 0;
if($_REQUEST['solo']!='No') $Nsickness++;
- if($_REQUEST['wedding'] == 'yes') $Nsickness++;
- if($_REQUEST['poverty'] == 'yes') $Nsickness++;
- if($_REQUEST['nines'] == 'yes') $Nsickness++;
+ if($_REQUEST['wedding'] == 'yes') $Nsickness++;
+ if($_REQUEST['poverty'] == 'yes') $Nsickness++;
+ if($_REQUEST['nines'] == 'yes') $Nsickness++;
+ if($_REQUEST['lowtrump'] == 'yes') $Nsickness++;
if($Nsickness>1)
{
@@ -503,6 +505,16 @@ switch($mystatus)
" is playing solo, this game will be canceled. \n";
DB_set_sickness_by_hash($me,'nines');
}
+ else if($_REQUEST['lowtrump'] == 'yes')
+ {
+ if($RULES['lowtrump']=='cancel')
+ echo "What? You just don't want to play a game because you have low trump? Well, if no one".
+ " is playing solo, this game will be canceled. \n";
+ else
+ echo "Don't think you can win with low trumps...? ok, poverty chosen . \n";
+
+ DB_set_sickness_by_hash($me,'lowtrump');
+ }
echo "
\n";
@@ -592,7 +604,7 @@ switch($mystatus)
$startplayer = DB_get_startplayer_by_gameid($gameid);
/* check for sickness */
- $nines = 0;
+ $cancel = 0;
$poverty = 0;
$wedding = 0;
$solo = 0;
@@ -600,12 +612,13 @@ switch($mystatus)
{
$name = DB_get_name('userid',$user);
$usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
- if($usersick == 'nines')
+ if($usersick == 'nines' || ($RULES['lowtrump']=='cancel' && $usersick=='lowtrump') )
{
- $nines = $user;
+ $cancel = $user;
+ $cancelsick = $usersick;
break; /* no need to check for other poverties, since only solo can win and that is already set */
}
- else if($usersick == 'poverty')
+ else if($usersick == 'poverty' || ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump'))
$poverty++;
else if($usersick == 'wedding')
$wedding=$user;
@@ -618,13 +631,35 @@ switch($mystatus)
{
/* do nothing */
}
- else if($nines)
+ else if($cancel)
{
/* cancel game */
- $message = "The game has been canceled because ".DB_get_name('userid',$nines).
- " has five or more nines and nobody is playing solo.\n\n".
- "To redeal either start a new game or, in case the game was part of a tournament,\n".
- "go to the last game and use the link at the bottom of the page to redeal.\n\n";
+ if($cancelsick == 'nines')
+ {
+ $message = "The game has been canceled because ".DB_get_name('userid',$cancel).
+ " has five or more nines and nobody is playing solo.\n\n".
+ "To redeal either start a new game or, in case the game was part of a tournament,\n".
+ "go to the last game and use the link at the bottom of the page to redeal.\n\n";
+
+ /* update game status */
+ cancel_game('nines',$gameid);
+
+ echo "
The game has been canceled because ".DB_get_name('userid',$cancel).
+ " has five or more nines and nobody is playing solo.
\n";
+ }
+ else if ($cancelsick == 'lowtrump')
+ {
+ $message = "The game has been canceled because ".DB_get_name('userid',$cancel).
+ " has low trump and nobody is playing solo.\n\n".
+ "To redeal either start a new game or, in case the game was part of a tournament,\n".
+ "go to the last game and use the link at the bottom of the page to redeal.\n\n";
+
+ /* update game status */
+ cancel_game('lowtrump',$gameid);
+
+ echo "
The game has been canceled because ".DB_get_name('userid',$cancel).
+ " has low trump and nobody is playing solo.
\n";
+ };
$userids = DB_get_all_userid_by_gameid($gameid);
foreach($userids as $user)
@@ -633,11 +668,6 @@ switch($mystatus)
mymail($user,$subject,$message);
}
- /* update game status */
- cancel_game('nines',$gameid);
-
- echo "
The game has been canceled because ".DB_get_name('userid',$nines).
- " has five or more nines and nobody is playing solo.
\n";
echo "\n";
break;
}
@@ -649,7 +679,7 @@ switch($mystatus)
if(!$who)
{
$firstsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
- if($firstsick == 'poverty')
+ if($firstsick == 'poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
DB_set_sickness_by_gameid($gameid,2); /* who needs to be asked first */
else
DB_set_sickness_by_gameid($gameid,1); /* who needs to be asked first */
@@ -663,10 +693,10 @@ switch($mystatus)
if(!$who)
{
$firstsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
- if($firstsick == 'poverty')
+ if($firstsick == 'poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
{
- $seconsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
- if($secondsick == 'poverty')
+ $secondsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
+ if($secondsick == 'poverty' || ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump'))
DB_set_sickness_by_gameid($gameid,30); /* who needs to be asked first */
else
DB_set_sickness_by_gameid($gameid,20); /* who needs to be asked first */
@@ -726,7 +756,7 @@ switch($mystatus)
case 'dpoverty':
/* set person with poverty to play status */
$usersick = DB_get_sickness_by_userid_and_gameid($userid,$gameid);
- if($usersick == 'poverty')
+ if($usersick == 'poverty' || ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump'))
DB_set_hand_status_by_hash($userhash,'play');
/* set status of first player to be asked to poverty */
@@ -806,6 +836,7 @@ switch($mystatus)
echo "\n";
break;
}
+ echo "\n";
case 'poverty':
/* user only gets here in a poverty game, several things have to be handled here:
* A) ask, if user wants to take trump
@@ -919,7 +950,7 @@ switch($mystatus)
$userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
$userparty = DB_get_party_by_hash($userhash);
- if($usersick=='poverty' && !$userparty)
+ if(($usersick=='poverty'|| ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump')) && !$userparty)
{
$hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
$cards = DB_get_hand($hash);
@@ -927,7 +958,10 @@ switch($mystatus)
$nrtrump = 0;
foreach($cards as $card)
if($card<27) $nrtrump++;
- echo "Player $name has $nrtrump trump. Do you want to take them?".
+ $low='';
+ if($usersick=='lowtrump')
+ $low='low';
+ echo "Player $name has $nrtrump $low trump. Do you want to take them?".
"Yes \n";
}
}
@@ -956,9 +990,9 @@ switch($mystatus)
/* don't ask people who have poverty */
$next=1;
- if($firstsick=='poverty')
+ if($firstsick=='poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
{
- if($secondsick=='poverty')
+ if($secondsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump'))
$next=3;
else
$next=2;
@@ -1073,8 +1107,8 @@ switch($mystatus)
$secondsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+2,$gameid);
$next=1;
- if($firstsick=='poverty')
- if($secondsick=='poverty')
+ if($firstsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
+ if($secondsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump'))
$next=3;
else
$next=2;
@@ -1097,7 +1131,7 @@ switch($mystatus)
echo "
The game has been canceled because one player wasn't responding.
If this was a mistake all 4 players need to send an Email to $ADMIN_NAME at $ADMIN_EMAIL requesting that the game should be restarted.
";
break;
case 'cancel-nines':
- case 'cancel-timedout':
echo "
The game has been canceled because one player had too many nines.
";
break;
+ case 'cancel-lowtrump':
+ echo "
The game has been canceled because one player had low trump.
";
+ break;
case 'cancel-trump':
echo "
The game has been canceled because nobody wanted to take the trump.
";
break;
diff --git a/include/newgame.php b/include/newgame.php
index d7a2d7f..f06bebe 100644
--- a/include/newgame.php
+++ b/include/newgame.php
@@ -40,7 +40,7 @@ else
DB_update_user_timestamp($myid);
- if( !myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","callrule" ))
+ if( !myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","callrule","lowtrump" ))
{
/* only get players that want to be in new games */
$names = DB_get_all_user_names_open_for_games();
@@ -80,6 +80,7 @@ else
$dullen = $_REQUEST["dullen"];
$schweinchen = $_REQUEST["schweinchen"];
$call = $_REQUEST["callrule"];
+ $lowtrump = $_REQUEST["lowtrump"];
/* get the emails addresses of the players */
$EmailA = DB_get_email('name',$PlayerA);
@@ -142,7 +143,7 @@ else
else /* no follow up, start a new session */
{
/* get ruleset information or create new one */
- $ruleset = DB_get_ruleset($dullen,$schweinchen,$call);
+ $ruleset = DB_get_ruleset($dullen,$schweinchen,$call,$lowtrump);
if($ruleset <0)
{
myerror("Error defining ruleset: $ruleset");
diff --git a/include/output.php b/include/output.php
index 018372b..135fe13 100644
--- a/include/output.php
+++ b/include/output.php
@@ -123,10 +123,19 @@ function output_form_for_new_game($names)
+
Low trump
+
+ Player can't trump a fox, that is none of his trump is higher than a fox.
+
+
Scoring-related
(not yet implemented)
@@ -205,10 +214,11 @@ function display_link_card($card,$dir="english",$type="card")
function output_check_for_sickness($me,$mycards)
{
+ global $RULES;
?>
Thanks for joining the game...
- do you want to play solo?
+ Do you want to play solo?