3 function mymail($To,$Subject,$message)
9 $message = str_replace("\n","<br />\n",$message);
10 $message = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
11 "<a href=\"\\0\">\\0</a>", $message);
12 //$message = ereg_replace("(http.*)[ <>]","<a href=\"\\1\">\\1 </a>",$message);
14 echo "<br />To: $To<br />Subject: $Subject <br />$message<br />\n";
17 mail($To,$Subject,$message);
23 /* returns 1 if all names passed as args are defined by a GET or POST statement,
28 $args = func_get_args();
30 foreach($args as $arg)
32 $ok = $ok * isset($_REQUEST[$arg]);
33 /*echo "$arg: ok = $ok <br />";
39 function pos_array($c,$arr)
60 if(in_array($c,$CARDS["trump"]))
66 function is_same_suite($c1,$c2)
70 if(in_array($c1,$CARDS["trump"] ) && in_array($c2,$CARDS["trump"] ) ) return 1;
71 if(in_array($c1,$CARDS["clubs"] ) && in_array($c2,$CARDS["clubs"] ) ) return 1;
72 if(in_array($c1,$CARDS["hearts"] ) && in_array($c2,$CARDS["hearts"] ) ) return 1;
73 if(in_array($c1,$CARDS["spades"] ) && in_array($c2,$CARDS["spades"] ) ) return 1;
74 if(in_array($c1,$CARDS["diamonds"]) && in_array($c2,$CARDS["diamonds"]) ) return 1;
79 function compare_cards($a,$b,$game)
81 /* if "a" is higher than "b" return 1, else 0, "a" being the card first played */
87 /* first map all cards to the odd number,
88 * this insure that the first card wins the trick
89 * if they are the same card
91 if( $a/2 - (int)($a/2) != 0.5)
93 if( $b/2 - (int)($b/2) != 0.5)
96 /* some special cases */
101 if($RULES["schweinchen"]=="both" && $GAME["schweinchen"])
103 if($a == 19 || $a == 20 )
105 if($b == 19 || $b == 20 )
108 if($RULES["schweinchen"]=="second" && $GAME["schweinchen"]==3)
110 if($a == 19 || $a == 20 )
112 if($b == 19 || $b == 20 )
119 if($RULES["dullen"]=="secondwins")
120 if($a==1 && $b==1) /* both 10 of hearts */
121 return 0; /* second one wins.*/
125 if(is_trump($a) && is_trump($b) && $a<=$b)
127 else if(is_trump($a) && is_trump($b) )
130 { /*$a is not a trump */
134 { /* both no trump */
137 $posA = pos_array($a,$CARDS["clubs"]);
138 $posB = pos_array($b,$CARDS["clubs"]);
146 $posA = pos_array($a,$CARDS["spades"]);
147 $posB = pos_array($b,$CARDS["spades"]);
155 $posA = pos_array($a,$CARDS["hearts"]);
156 $posB = pos_array($b,$CARDS["hearts"]);
164 $posA = pos_array($a,$CARDS["diamonds"]);
165 $posB = pos_array($b,$CARDS["diamonds"]);
172 /* not the same suit and no trump: a wins */
178 function get_winner($p,$mode)
180 /* get all 4 cards played in a trick, in the order they are played */
183 $c1pos = $tmp["pos"];
187 $c2pos = $tmp["pos"];
191 $c3pos = $tmp["pos"];
195 $c4pos = $tmp["pos"];
197 /* first card is better than all the rest */
198 if( compare_cards($c1,$c2,$mode) && compare_cards($c1,$c3,$mode) && compare_cards($c1,$c4,$mode) )
201 /* second card is better than first and better than the rest */
202 if( !compare_cards($c1,$c2,$mode) && compare_cards($c2,$c3,$mode) && compare_cards($c2,$c4,$mode) )
205 /* third card is better than first card and better than last */
206 if( !compare_cards($c1,$c3,$mode) && compare_cards($c3,$c4,$mode) )
207 /* if second card is better than first, third card needs to be even better */
208 if( !compare_cards($c1,$c2,$mode) && !compare_cards($c2,$c3,$mode) )
210 /* second is worse than first, e.g. not following suite */
211 else if (compare_cards($c1,$c2,$mode) )
214 /* non of the above */
218 function count_nines($cards)
222 foreach($cards as $c)
224 if($c == "25" || $c == "26") $nines++;
225 else if($c == "33" || $c == "34") $nines++;
226 else if($c == "41" || $c == "42") $nines++;
227 else if($c == "47" || $c == "48") $nines++;
233 function check_wedding($cards)
236 if( in_array("3",$cards) && in_array("4",$cards) )
242 function count_trump($cards)
248 /* count each trump */
249 foreach($cards as $c)
253 switch($RULES["schweinchen"])
258 case "secondaftercall":
259 /* add one, in case the player has both foxes (schweinchen) */
260 if( in_array("19",$cards) && in_array("20",$cards) )
264 if( in_array("19",$cards))
266 if( in_array("20",$cards) )
274 function card_to_name($card)
280 return "ten of hearts";
283 return "queen of clubs";
286 return "queen of spades";
289 return "queen of hearts";
292 return "queen of diamonds";
295 return "jack of clubs";
298 return "jack of spades";
301 return "jack of hearts";
304 return "jack of diamonds";
307 return "ace of diamonds";
310 return "ten of diamonds";
313 return "king of diamonds";
316 return "nine of diamonds";;
319 return "ace of clubs";
322 return "ten of clubs";
325 return "king of clubs";
328 return "nine of clubs";
331 return "ace of spades";
334 return "ten of spades";
337 return "king of spades";
340 return "nine of spades";
343 return "ace of hearts";
346 return "king of hearts";
349 return "nine of hearts";
351 return "something went wrong, please contact the admin. Error: code1. $card <br />";
355 function card_value($card)
365 case 9: /* diamonds */
368 case 11: /* clubes */
370 case 13: /* spades */
372 case 15: /* hearts */
374 case 17: /* diamonds */
377 case 19: /* diamonds */
381 case 35: /* spades */
383 case 43: /* hearts */
388 case 21: /* diamonds */
392 case 37: /* spades */
395 case 23: /* diamonds */
399 case 39: /* spades */
401 case 45: /* hearts */
404 case 25: /* diamonds */
408 case 41: /* spades */
410 case 47: /* hearts */
414 echo "something went wrong, please contact the admin. ErrorCode: 2 - $card<br>";
420 function create_array_of_random_numbers()
428 $r[ 0]=1; $r[12]=47; $r[24]=13; $r[36]=37;
429 $r[ 1]=2; $r[13]=48; $r[25]=14; $r[37]=38;
430 $r[ 2]=3; $r[14]=27; $r[26]=15; $r[38]=39;
431 $r[ 3]=4; $r[15]=16; $r[27]=28; $r[39]=40;
432 $r[ 4]=5; $r[16]=17; $r[28]=29; $r[40]=41;
433 $r[ 5]=18; $r[17]=6; $r[29]=30; $r[41]=42;
434 $r[ 6]=19; $r[18]=7; $r[30]=31; $r[42]=43;
435 $r[ 7]=20; $r[19]=8; $r[31]=32; $r[43]=44;
436 $r[ 8]=45; $r[20]=9; $r[32]=21; $r[44]=33;
437 $r[ 9]=46; $r[21]=10; $r[33]=22; $r[45]=34;
438 $r[10]=35; $r[22]=11; $r[34]=23; $r[46]=25;
439 $r[11]=36; $r[23]=12; $r[35]=24; $r[47]=26;
455 function display_cards($me,$myturn)
460 function return_timezone($offset)
465 $zone = "Europe/Berlin";
468 $zone = "America/Vancouver";
471 $zone = "Pacific/Auckland";
474 $zone = "Europe/London";
480 function have_suit($cards,$c)
485 if(in_array($c,$CARDS["trump"]))
486 $suite = $CARDS["trump"];
487 else if(in_array($c,$CARDS["clubs"]))
488 $suite = $CARDS["clubs"];
489 else if(in_array($c,$CARDS["spades"]))
490 $suite = $CARDS["spades"];
491 else if(in_array($c,$CARDS["hearts"]))
492 $suite = $CARDS["hearts"];
493 else if(in_array($c,$CARDS["diamonds"]))
494 $suite = $CARDS["diamonds"];
496 foreach($cards as $card)
498 if(in_array($card,$suite))
505 function same_type($card,$c)
510 /* figure out what kind of card c is */
511 if(in_array($c,$CARDS["trump"]))
512 $suite = $CARDS["trump"];
513 else if(in_array($c,$CARDS["clubs"]))
514 $suite = $CARDS["clubs"];
515 else if(in_array($c,$CARDS["spades"]))
516 $suite = $CARDS["spades"];
517 else if(in_array($c,$CARDS["hearts"]))
518 $suite = $CARDS["hearts"];
519 else if(in_array($c,$CARDS["diamonds"]))
520 $suite = $CARDS["diamonds"];
522 /* card is the same suid return 1 */
523 if(in_array($card,$suite))
529 function set_gametype($gametype)
542 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
543 '17','18','19','20','21','22','23','24','25','26');
544 $CARDS["diamonds"] = array();
545 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
546 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
547 $CARDS["hearts"] = array('43','44','45','46','47','48');
548 $CARDS["foxes"] = array('19','20');
549 if($RULES["dullen"]=='none')
551 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
552 '17','18','19','20','21','22','23','24','25','26');
553 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
557 $CARDS["trump"] = array('3','4','5','6','7','8','9','10');
558 $CARDS["clubs"] = array('27','28','29','30','31','32','11','12','33','34');
559 $CARDS["spades"] = array('35','36','37','38','39','40','13','14','41','42');
560 $CARDS["hearts"] = array('43','44', '1', '2','45','46','15','16','47','48');
561 $CARDS["diamonds"] = array('19','20','21','22','23','24','17','18','25','26');
562 $CARDS["foxes"] = array();
565 $CARDS["trump"] = array('11','12','13','14','15','16','17','18');
566 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','33','34');
567 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','41','42');
568 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','47','48');
569 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','25','26');
570 $CARDS["foxes"] = array();
573 $CARDS["trump"] = array();
574 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','11','12','33','34');
575 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','13','14','41','42');
576 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','15','16','47','48');
577 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','17','18','25','26');
578 $CARDS["foxes"] = array();
581 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
582 '17','18','27','28','29','30','31','32','33','34');
583 $CARDS["clubs"] = array();
584 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
585 $CARDS["hearts"] = array('43','44','45','46','47','48');
586 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
587 $CARDS["foxes"] = array();
588 if($RULES["dullen"]=='none')
590 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
591 '17','18','27','28','29','30','31','32','33','34');
592 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
596 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
597 '17','18','35','36','37','38','39','40','41','42');
598 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
599 $CARDS["spades"] = array();
600 $CARDS["hearts"] = array('43','44','45','46','47','48');
601 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
602 $CARDS["foxes"] = array();
603 if($RULES["dullen"]=='none')
605 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
606 '17','18','35','36','37','38','39','40','41','42');
607 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
611 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
612 '17','18','43','44','45','46','47','48');
613 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
614 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
615 $CARDS["hearts"] = array();
616 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
617 $CARDS["foxes"] = array();
618 if($RULES["dullen"]=='none')
620 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
621 '17','18','43','44','1','2','45','46','47','48');
627 function mysort($cards,$gametype)
629 usort ( $cards, "sort_comp" );
633 function sort_comp($a,$b)
638 $ALL = array_merge($CARDS["trump"],$CARDS["diamonds"],$CARDS["clubs"],
639 $CARDS["hearts"],$CARDS["spades"],$CARDS["diamonds"]);
641 return pos_array($a,$ALL)-pos_array($b,$ALL);
644 function can_call($what,$hash)