summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarun <arun@nubati.net>2007-02-07 17:48:24 +0000
committerarun <arun>2007-02-07 17:48:24 +0000
commit9fd03423a0e5e26397250e8924d2be0e01e2ceaf (patch)
treeb4275c469a7c7966b0cd7048b1135148d73f8239
parent7ecd66ab61eb1f0e8d32e75570b4809b57ae79d5 (diff)
downloade-DoKo-9fd03423a0e5e26397250e8924d2be0e01e2ceaf.tar.gz
e-DoKo-9fd03423a0e5e26397250e8924d2be0e01e2ceaf.tar.bz2
e-DoKo-9fd03423a0e5e26397250e8924d2be0e01e2ceaf.zip
fixed: bug in routine to figure out the next player
added rulesets (change in database): at the beginning of a game differnt rules can be chosen
-rw-r--r--create_database.sql28
-rw-r--r--css/standard.css6
-rw-r--r--db.php42
-rw-r--r--functions.php71
-rw-r--r--index.php113
-rw-r--r--output.php29
6 files changed, 240 insertions, 49 deletions
diff --git a/create_database.sql b/create_database.sql
index bec2325..e4476ef 100644
--- a/create_database.sql
+++ b/create_database.sql
@@ -74,6 +74,7 @@ CREATE TABLE `Game` (
`solo` enum('trumpless','jack','queen','trump','club','spade','heart','silent') default NULL,
`startplayer` tinyint(4) default '1',
`status` enum('pre','play','gameover') default NULL,
+ `ruleset` int(11) default NULL,
`session` int(11) default NULL,
`id` int(11) NOT NULL auto_increment,
UNIQUE KEY `id` (`id`)
@@ -89,6 +90,33 @@ LOCK TABLES `Game` WRITE;
UNLOCK TABLES;
/*!40000 ALTER TABLE `Game` ENABLE KEYS */;
+
+--
+-- Table structure for table `Ruleset`
+--
+
+DROP TABLE IF EXISTS `Rulesets`;
+CREATE TABLE `Rulesets` (
+ `mod_date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
+ `create_date` timestamp NOT NULL default '0000-00-00 00:00:00',
+ `dullen` enum('none','firstwins','secondwins') default 'secondwins',
+ `schweinchen` enum ('none','both','second','secondaftercall') default 'second',
+ `id` int(11) NOT NULL auto_increment,
+ UNIQUE KEY `id` (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+
+--
+-- Dumping data for table `Rulesets`
+--
+
+
+/*!40000 ALTER TABLE `Rulesets` DISABLE KEYS */;
+LOCK TABLES `Rulesets` WRITE;
+UNLOCK TABLES;
+/*!40000 ALTER TABLE `Rulesets` ENABLE KEYS */;
+
+
+
--
-- Table structure for table `Hand`
--
diff --git a/css/standard.css b/css/standard.css
index 0edabfb..664b17c 100644
--- a/css/standard.css
+++ b/css/standard.css
@@ -238,6 +238,12 @@ ul.tricks li div div.card3 span{
border-top:0;
}
+.ruleset {
+ float:right;
+ border:2px solid gray;
+ border-top:0;
+}
+
.time {
float:left;
border:2px solid gray;
diff --git a/db.php b/db.php
index 8feb186..8843712 100644
--- a/db.php
+++ b/db.php
@@ -321,13 +321,13 @@ function DB_get_cards_by_trick($id)
$cards = array();
$i = 1;
- $result = mysql_query("SELECT card_id FROM Play LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id ".
+ $result = mysql_query("SELECT card_id,position FROM Play LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id ".
"LEFT JOIN Hand ON Hand.id=Hand_Card.hand_id ".
"WHERE trick_id=".
- DB_quote_smart($id)." ORDER BY position ASC");
+ DB_quote_smart($id)." ORDER BY sequence ASC");
while($r = mysql_fetch_array($result,MYSQL_NUM))
{
- $cards[$i]=$r[0];
+ $cards[$i]=array("card"=>$r[0],"pos"=>$r[1]);
$i++;
}
@@ -525,6 +525,17 @@ function DB_set_startplayer_by_gameid($id,$p)
return;
}
+function DB_get_ruleset_by_gameid($id)
+{
+ $result = mysql_query("SELECT ruleset FROM Game WHERE id=".DB_quote_smart($id));
+ $r = mysql_fetch_array($result,MYSQL_NUM);
+
+ if($r)
+ return $r[0];
+ else
+ return NULL;
+}
+
function DB_get_session_by_gameid($id)
{
$result = mysql_query("SELECT session FROM Game WHERE id=".DB_quote_smart($id));
@@ -547,5 +558,30 @@ function DB_get_max_session()
return 0;
}
+function DB_get_ruleset($dullen,$schweinchen)
+{
+ $r = array();
+
+ $result = mysql_query("SELECT id FROM Rulesets WHERE".
+ " dullen=".DB_quote_smart($dullen)." AND ".
+ " schweinchen=".DB_quote_smart($schweinchen));
+ if($result)
+ $r = mysql_fetch_array($result,MYSQL_NUM);
+
+ if($r)
+ return $r[0]; /* found ruleset */
+ else
+ {
+ /* create new one */
+ $result = mysql_query("INSERT INTO Rulesets VALUES (NULL, NULL, ".
+ DB_quote_smart($dullen).",".
+ DB_quote_smart($schweinchen).
+ ", NULL)");
+ if($result)
+ return mysql_insert_id();
+ };
+
+ return -1; /* something went wrong */
+}
?> \ No newline at end of file
diff --git a/functions.php b/functions.php
index 45416a7..162b544 100644
--- a/functions.php
+++ b/functions.php
@@ -77,6 +77,7 @@ function compare_cards($a,$b,$game)
/* if "a" is higher than "b" return 1, else 0, "a" being the card first played */
global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
+ global $RULES;
/* first map all cards to the odd number,
* this insure that the first card wins the trick
@@ -91,8 +92,14 @@ function compare_cards($a,$b,$game)
switch($game)
{
case "normal":
- if($a==1 && $b==1) /* both 10 of hearts */
- return 0; /* second one wins. TODO should be able to set this at the start of a new game */
+ case "silent":
+ case "trump":
+ case "heart":
+ case "spade":
+ case "club":
+ if($RULES["dullen"]=="secondwins")
+ if($a==1 && $b==1) /* both 10 of hearts */
+ return 0; /* second one wins.*/
}
if(is_trump($a) && is_trump($b) && $a<=$b)
@@ -150,31 +157,42 @@ function compare_cards($a,$b,$game)
function get_winner($p,$mode)
{
- /* get all 4 cards played in a trick */
- $c1 = $p[1];
- $c2 = $p[2];
- $c3 = $p[3];
- $c4 = $p[4];
+ /* get all 4 cards played in a trick, in the order they are played */
+ $tmp = $p[1];
+ $c1 = $tmp["card"];
+ $c1pos = $tmp["pos"];
+
+ $tmp = $p[2];
+ $c2 = $tmp["card"];
+ $c2pos = $tmp["pos"];
+
+ $tmp = $p[3];
+ $c3 = $tmp["card"];
+ $c3pos = $tmp["pos"];
+
+ $tmp = $p[4];
+ $c4 = $tmp["card"];
+ $c4pos = $tmp["pos"];
/* first card is better than all the rest */
if( compare_cards($c1,$c2,$mode) && compare_cards($c1,$c3,$mode) && compare_cards($c1,$c4,$mode) )
- return 1;
+ return $c1pos;
/* second card is better than first and better than the rest */
if( !compare_cards($c1,$c2,$mode) && compare_cards($c2,$c3,$mode) && compare_cards($c2,$c4,$mode) )
- return 2;
+ return $c2pos;
/* third card is better than first card and better than last */
if( !compare_cards($c1,$c3,$mode) && compare_cards($c3,$c4,$mode) )
/* if second card is better than first, third card needs to be even better */
if( !compare_cards($c1,$c2,$mode) && !compare_cards($c2,$c3,$mode) )
- return 3;
+ return $c3pos;
/* second is worse than first, e.g. not following suite */
else if (compare_cards($c1,$c2,$mode) )
- return 3;
+ return $c3pos;
/* non of the above */
- return 4;
+ return $c4pos;
}
function count_nines($cards)
@@ -307,9 +325,6 @@ function card_value($card)
{
switch($card)
{
- case 1: /* heart */
- case 2:
- return 10;
case 3: /* clubes */
case 4:
case 5: /* spades */
@@ -337,6 +352,8 @@ function card_value($card)
case 43: /* hearts */
case 44:
return 11;
+ case 1: /* heart */
+ case 2:
case 21: /* diamonds */
case 22:
case 29: /* clubs */
@@ -462,6 +479,7 @@ function same_type($card,$c)
function set_gametype($gametype)
{
global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
+ global $RULES;
switch($gametype)
{
@@ -474,6 +492,12 @@ function set_gametype($gametype)
$CLUBS = array('27','28','29','30','31','32','33','34');
$SPADES = array('35','36','37','38','39','40','41','42');
$HEARTS = array('43','44','45','46','47','48');
+ if($RULES["dullen"]=='none')
+ {
+ $TRUMP = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
+ '17','18','19','20','21','22','23','24','25','26');
+ $HEARTS = array('43','44','1','2','45','46','47','48');
+ }
break;
case "queen":
$TRUMP = array('3','4','5','6','7','8','9','10');
@@ -503,6 +527,12 @@ function set_gametype($gametype)
$SPADES = array('35','36','37','38','39','40','41','42');
$HEARTS = array('43','44','45','46','47','48');
$DIAMONDS = array('19','20','21','22','23','24','25','26');
+ if($RULES["dullen"]=='none')
+ {
+ $TRUMP = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
+ '17','18','27','28','29','30','31','32','33','34');
+ $HEARTS = array('43','44','1','2','45','46','47','48');
+ }
break;
case "spade":
$TRUMP = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
@@ -511,6 +541,12 @@ function set_gametype($gametype)
$SPADES = array();
$HEARTS = array('43','44','45','46','47','48');
$DIAMONDS = array('19','20','21','22','23','24','25','26');
+ if($RULES["dullen"]=='none')
+ {
+ $TRUMP = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
+ '17','18','35','36','37','38','39','40','41','42');
+ $HEARTS = array('43','44','1','2','45','46','47','48');
+ }
break;
case "heart":
$TRUMP = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
@@ -519,6 +555,11 @@ function set_gametype($gametype)
$SPADES = array('35','36','37','38','39','40','41','42');
$HEARTS = array();
$DIAMONDS = array('19','20','21','22','23','24','25','26');
+ if($RULES["dullen"]=='none')
+ {
+ $TRUMP = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
+ '17','18','43','44','1','2','45','46','47','48');
+ }
break;
}
}
diff --git a/index.php b/index.php
index 84ce6f0..bd5702e 100644
--- a/index.php
+++ b/index.php
@@ -31,12 +31,15 @@ if(myisset("new"))
output_form_for_new_game($names);
}
/*check if everything is ready to set up a new game */
-else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD" ))
+ else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen" ))
{
$PlayerA = $_REQUEST["PlayerA"];
$PlayerB = $_REQUEST["PlayerB"];
$PlayerC = $_REQUEST["PlayerC"];
$PlayerD = $_REQUEST["PlayerD"];
+
+ $dullen = $_REQUEST["dullen"];
+ $schweinchen = $_REQUEST["schweinchen"];
$EmailA = DB_get_email_by_name($PlayerA);
$EmailB = DB_get_email_by_name($PlayerB);
@@ -58,25 +61,38 @@ else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD" ))
$randomNR = create_array_of_random_numbers();
$randomNRstring = join(":",$randomNR);
+ /* get ruleset information or create new one */
+ $ruleset = DB_get_ruleset($dullen,$schweinchen);
+ if($ruleset <0)
+ {
+ echo "Error defining ruleset: $ruleset";
+ exit();
+ };
+
/* create game */
$followup = NULL;
if(myisset("followup") )
{
$followup= $_REQUEST["followup"];
$session = DB_get_session_by_gameid($followup);
+ $ruleset = DB_get_ruleset_by_gameid($followup); /* just copy ruleset from old game,
+ this way no manipulation is possible */
if($session)
- mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre','$session' ,NULL)");
+ mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre',".
+ "'$ruleset','$session' ,NULL)");
else
{
/* get max session */
$max = DB_get_max_session();
$max++;
- mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre','$max' ,NULL)");
+ mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre',".
+ "'$ruleset','$max' ,NULL)");
mysql_query("UPDATE Game SET session='".$max."' WHERE id=".DB_quote_smart($followup));
}
}
else
- mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre', NULL ,NULL)");
+ mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre', ".
+ "'$ruleset',NULL ,NULL)");
$game_id = mysql_insert_id();
/* create hash */
@@ -201,6 +217,19 @@ else if(myisset("me"))
/* display the game number */
echo "<p class=\"gamenumber\"> Game $gameid </p>\n";
+ /* display rule set */
+ echo "<div class=\"ruleset\">\n Rules: <br />";
+ $result = mysql_query("SELECT * FROM Rulesets LEFT JOIN Game ON Game.ruleset=Rulesets.id WHERE Game.id='$gameid'" );
+ $r = mysql_fetch_array($result,MYSQL_NUM);
+
+ $RULES["dullen"]=$r[2];
+ $RULES["schweinchen"]=$r[3];
+
+ echo "10ofhearts : ".$r[2]."<br />";
+ echo "schweinchen: ".$r[3]."<br />";
+ echo "</div>\n";
+
+
/* mystatus gets the player through the different stages of a game.
* start: yes/no
* init: check values from start,
@@ -219,9 +248,9 @@ else if(myisset("me"))
DB_set_hand_status_by_hash($me,'init');
break;
case 'init':
- if( !myisset("in","update") )
+ if( !myisset("in") )
{
- echo "you need to answer both question";
+ echo "you need to answer the question";
DB_set_hand_status_by_hash($me,'start');
}
else
@@ -244,13 +273,11 @@ else if(myisset("me"))
}
else
{
- echo "thanks for joining the game... please scroll down";
- echo "TODO: make this page nicer<br />";
- echo "TODO: set card pref<br />";
+ echo "thanks for joining the game...";
$mycards = DB_get_hand($me);
sort($mycards);
- echo "<p class=\"mycards\" style=\"margin-top:12em;\">your cards are: <br />\n";
+ echo "<p class=\"mycards\" style=\"margin-top:8em;\">your cards are: <br />\n";
foreach($mycards as $card)
display_card($card);
echo "</p>\n";
@@ -265,8 +292,6 @@ else if(myisset("me"))
case 'check':
echo "checking if you selected solo or nines...<br />".
- " if you have a wedding, please send an email to the other players. <br />".
- " if you have poverty you need to play a normal game,sorry...<br />".
" Please click <a href=\"$host?me=$me\">here</a> to finish the setup.<br />";
if(!myisset("solo","wedding","poverty","nines") )
{
@@ -303,17 +328,19 @@ else if(myisset("me"))
else if($_REQUEST["wedding"] == "yes")
{
/* TODO: add silent solo somewhere*/
- echo "wedding was chosen<br />\n";
+ echo "wedding was chosen, can't handle it at the moment, you need to send out".
+ " an email by hand to the other players<br />\n";
DB_set_sickness_by_hash($me,"wedding");
}
else if($_REQUEST["poverty"] == "yes")
{
- echo "poverty was chosen<br />\n";
+ echo "poverty was chosen. Unfortunately this is not implemented yet,".
+ " so you need to play a normal game... sorry<br />\n";
DB_set_sickness_by_hash($me,"poverty");
}
else if($_REQUEST["nines"] == "yes")
{
- echo "nines was chosen<br />\n";
+ echo "Nines was chosen. If no is playing solo, this game will be canceled.<br />\n";
DB_set_sickness_by_hash($me,"nines");
}
}
@@ -332,20 +359,19 @@ else if(myisset("me"))
echo "<br />checking if someone else selected solo or nines... wedding and poverty not handled at the moment<br />".
" Please click <a href=\"$host?me=$me\">here</a> to finish the setup.<br />";
- /* only set this after all poverty, etc. are handled*/
- DB_set_hand_status_by_hash($me,'play');
-
- /* check if the game can start */
+ /* check if everyone has reached this stage */
$userids = DB_get_all_userid_by_gameid($gameid);
$ok=1;
foreach($userids as $user)
- if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='play')
- $ok=0;
-
+ {
+ $userstat = DB_get_hand_status_by_userid_and_gameid($user,$gameid);
+ if($userstat!='poverty' && $userstat!='play')
+ $ok=0;
+ };
+
if($ok)
{
- DB_set_game_status_by_gameid($gameid,'play');
-
+ echo "Everyone has finished checking their cards, the game can now start...<br />";
/* check what kind of game we are playing */
$gametype = DB_get_gametype_by_gameid($gameid);
$startplayer = DB_get_startplayer_by_gameid($gameid);
@@ -399,9 +425,38 @@ else if(myisset("me"))
echo "$name has a Vorbehalt. <br />" ;
}
}
-
/* if gamestatus == normal, set wedding */
+ /* check for solo, output vorbehalt */
+ $solo = 0;
+ foreach($userids as $user)
+ {
+ if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'solo')
+ {
+ $solo++;
+ $name = DB_get_name_by_userid($user);
+ echo "$name has a Vorbehalt. <br />" ;
+ }
+ }
+
+ /* finished the setup, go to next stage */
+ DB_set_hand_status_by_hash($me,'play');
+ }
+ else
+ {
+ echo "You need to wait for the others, the game can only start after everyone finished checking their cards.<br />";
+ };
+
+ /* check if all players are ready to play */
+ $ok=1;
+ foreach($userids as $user)
+ if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='play')
+ $ok=0;
+
+ if($ok)
+ {
+ /* only set this after all poverty, etc. are handled*/
+ DB_set_game_status_by_gameid($gameid,'play');
}
break;
@@ -520,7 +575,7 @@ else if(myisset("me"))
$comment = $r[4];
/* save card to be able to find the winner of the trick later */
- $play[$pos] = $r[0];
+ $play[$seq] = array("card"=>$r[0],"pos"=>$pos);
if($seq==1)
{
@@ -654,7 +709,7 @@ else if(myisset("me"))
/* get points of last trick and save it */
$points = 0;
foreach($play as $card)
- $points = $points + card_value($card);
+ $points = $points + card_value($card["card"]);
$winnerid = DB_get_handid_by_gameid_and_position($gameid,$winner);
if($winnerid>0)
mysql_query("INSERT INTO Score VALUES (NULL, '$gameid', '$winnerid', '$points')");
@@ -691,7 +746,7 @@ else if(myisset("me"))
* a few lines further up */
$points = 0;
foreach($play as $card)
- $points = $points + card_value($card);
+ $points = $points + card_value($card["card"]);
$winnerid = DB_get_handid_by_gameid_and_position($gameid,$winner);
if($winnerid>0)
@@ -810,7 +865,7 @@ else if(myisset("me"))
if($result)
$r = mysql_fetch_array($result,MYSQL_NUM);
- if(!$session || $gameid==$r)
+ if(!$session || $gameid==$r[0])
{
/* suggest a new game with the same people in it, just rotated once */
$names = DB_get_all_names_by_gameid($gameid);
diff --git a/output.php b/output.php
index bfebf4a..721858f 100644
--- a/output.php
+++ b/output.php
@@ -70,12 +70,16 @@ function output_register()
function output_ask_for_new_game($playerA,$playerB,$playerC,$playerD,$oldgameid)
{
+ global $RULES;
+
echo "Do you want to continue playing?(This will start a new game, with the next person as dealer.)\n";
echo "<form action=\"index.php\" method=\"post\">\n";
echo " <input type=\"hidden\" name=\"PlayerA\" value=\"$playerA\" />\n";
echo " <input type=\"hidden\" name=\"PlayerB\" value=\"$playerB\" />\n";
echo " <input type=\"hidden\" name=\"PlayerC\" value=\"$playerC\" />\n";
echo " <input type=\"hidden\" name=\"PlayerD\" value=\"$playerD\" />\n";
+ echo " <input type=\"hidden\" name=\"dullen\" value=\"".$RULES["dullen"]."\" />\n";
+ echo " <input type=\"hidden\" name=\"schweinchen\" value=\"".$RULES["schweinchen"]."\" />\n";
echo " <input type=\"hidden\" name=\"followup\" value=\"$oldgameid\" />\n";
echo " <input type=\"submit\" value=\"keep playing\" />\n";
echo "</form>\n";
@@ -86,9 +90,11 @@ function output_ask_for_new_game($playerA,$playerB,$playerC,$playerD,$oldgameid)
function output_form_for_new_game($names)
{
?>
+ <h2> Players </h2>
<p>Please select four players (or use the randomly pre-selected names)</p>
<form action="index.php" method="post">
<?php
+ /* ask for player names */
foreach( array("PlayerA","PlayerB","PlayerC","PlayerD") as $player)
{
srand((float) microtime() * 10000000);
@@ -108,7 +114,24 @@ function output_form_for_new_game($names)
unset($names[$randkey]);
}
?>
-
+ <h2> Rules </h2>
+
+ <p> ten of hearts:
+ <ul>
+ <li> <input type="radio" name="dullen" value="none" /> just normal non-trump </li>
+ <li> <input type="radio" name="dullen" value="firstwins" /> first ten of hearts wins the trick </li>
+ <li> <input type="radio" name="dullen" value="secondwins" checked="checked" /> second ten of hearts wins the trick </li>
+ </ul>
+ </p>
+ <p> schweinchen (both foxes):
+ <ul>
+ <li> <input type="radio" name="schweinchen" value="none" /> none </li>
+ <li> <input type="radio" name="schweinchen" value="both" /> both become highest trump (call at beginning of the game)(doesn't work yet) </li>
+ <li> <input type="radio" name="schweinchen" value="second" checked="checked" /> first one normal, second one becomes highest (call during the game) (doesn't work yet) </li>
+ <li> <input type="radio" name="schweinchen" value="secondaftercall" /> second one become highest only in case re/contra was announced (doesn't work yet)</li>
+ </ul>
+ </p>
+
<input type="submit" value="start game" />
</form>
<?php
@@ -207,10 +230,12 @@ function check_want_to_play($me)
yes<input type="radio" name="in" value="yes" />
no<input type="radio" name="in" value="no" /> <br />
+<?php
+/*
Do you want to get an email for every card played or only if it your move?
every card<input type="radio" name="update" value="card" />
only on my turn<input type="radio" name="update" value="turn" /> <br />
-<?php
+*/
echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />\n";
echo "\n";
echo "<input type=\"submit\" value=\"count me in\" />\n";