3 function mymail($To,$Subject,$message)
9 $message = str_replace("\n","<br />",$message);
10 echo "<br />To: $To<br />Subject: $Subject <br />$message<br />\n";
13 mail($To,$Subject,$message);
19 /* returns 1 if all names passed as args are defined by a GET or POST statement,
24 $args = func_get_args();
26 foreach($args as $arg)
28 $ok = $ok * isset($_REQUEST[$arg]);
29 /*echo "$arg: ok = $ok <br />";
35 function pos_array($c,$arr)
56 if(in_array($c,$CARDS["trump"]))
62 function is_same_suite($c1,$c2)
66 if(in_array($c1,$CARDS["trump"] ) && in_array($c2,$CARDS["trump"] ) ) return 1;
67 if(in_array($c1,$CARDS["clubs"] ) && in_array($c2,$CARDS["clubs"] ) ) return 1;
68 if(in_array($c1,$CARDS["hearts"] ) && in_array($c2,$CARDS["hearts"] ) ) return 1;
69 if(in_array($c1,$CARDS["spades"] ) && in_array($c2,$CARDS["spades"] ) ) return 1;
70 if(in_array($c1,$CARDS["diamonds"]) && in_array($c2,$CARDS["diamonds"]) ) return 1;
75 function compare_cards($a,$b,$game)
77 /* if "a" is higher than "b" return 1, else 0, "a" being the card first played */
83 /* first map all cards to the odd number,
84 * this insure that the first card wins the trick
85 * if they are the same card
87 if( $a/2 - (int)($a/2) != 0.5)
89 if( $b/2 - (int)($b/2) != 0.5)
92 /* some special cases */
97 if($RULES["schweinchen"]=="both" && $GAME["schweinchen"])
99 if($a == 19 || $a == 20 )
101 if($b == 19 || $b == 20 )
104 if($RULES["schweinchen"]=="second" && $GAME["schweinchen"]==3)
106 if($a == 19 || $a == 20 )
108 if($b == 19 || $b == 20 )
115 if($RULES["dullen"]=="secondwins")
116 if($a==1 && $b==1) /* both 10 of hearts */
117 return 0; /* second one wins.*/
121 if(is_trump($a) && is_trump($b) && $a<=$b)
123 else if(is_trump($a) && is_trump($b) )
126 { /*$a is not a trump */
130 { /* both no trump */
133 $posA = pos_array($a,$CARDS["clubs"]);
134 $posB = pos_array($b,$CARDS["clubs"]);
142 $posA = pos_array($a,$CARDS["spades"]);
143 $posB = pos_array($b,$CARDS["spades"]);
151 $posA = pos_array($a,$CARDS["hearts"]);
152 $posB = pos_array($b,$CARDS["hearts"]);
160 $posA = pos_array($a,$CARDS["diamonds"]);
161 $posB = pos_array($b,$CARDS["diamonds"]);
168 /* not the same suit and no trump: a wins */
174 function get_winner($p,$mode)
176 /* get all 4 cards played in a trick, in the order they are played */
179 $c1pos = $tmp["pos"];
183 $c2pos = $tmp["pos"];
187 $c3pos = $tmp["pos"];
191 $c4pos = $tmp["pos"];
193 /* first card is better than all the rest */
194 if( compare_cards($c1,$c2,$mode) && compare_cards($c1,$c3,$mode) && compare_cards($c1,$c4,$mode) )
197 /* second card is better than first and better than the rest */
198 if( !compare_cards($c1,$c2,$mode) && compare_cards($c2,$c3,$mode) && compare_cards($c2,$c4,$mode) )
201 /* third card is better than first card and better than last */
202 if( !compare_cards($c1,$c3,$mode) && compare_cards($c3,$c4,$mode) )
203 /* if second card is better than first, third card needs to be even better */
204 if( !compare_cards($c1,$c2,$mode) && !compare_cards($c2,$c3,$mode) )
206 /* second is worse than first, e.g. not following suite */
207 else if (compare_cards($c1,$c2,$mode) )
210 /* non of the above */
214 function count_nines($cards)
218 foreach($cards as $c)
220 if($c == "25" || $c == "26") $nines++;
221 else if($c == "33" || $c == "34") $nines++;
222 else if($c == "41" || $c == "42") $nines++;
223 else if($c == "47" || $c == "48") $nines++;
229 function check_wedding($cards)
232 if( in_array("3",$cards) && in_array("4",$cards) )
238 function count_trump($cards)
244 /* count each trump */
245 foreach($cards as $c)
249 switch($RULES["schweinchen"])
254 case "secondaftercall":
255 /* add one, in case the player has both foxes (schweinchen) */
256 if( in_array("19",$cards) && in_array("20",$cards) )
260 if( in_array("19",$cards))
262 if( in_array("20",$cards) )
270 function card_to_name($card)
276 return "ten of hearts";
279 return "queen of clubs";
282 return "queen of spades";
285 return "queen of hearts";
288 return "queen of diamonds";
291 return "jack of clubs";
294 return "jack of spades";
297 return "jack of hearts";
300 return "jack of diamonds";
303 return "ace of diamonds";
306 return "ten of diamonds";
309 return "king of diamonds";
312 return "nine of diamonds";;
315 return "ace of clubs";
318 return "ten of clubs";
321 return "king of clubs";
324 return "nine of clubs";
327 return "ace of spades";
330 return "ten of spades";
333 return "king of spades";
336 return "nine of spades";
339 return "ace of hearts";
342 return "king of hearts";
345 return "nine of hearts";
347 return "something went wrong, please contact the admin. Error: code1. $card <br />";
351 function card_value($card)
361 case 9: /* diamonds */
364 case 11: /* clubes */
366 case 13: /* spades */
368 case 15: /* hearts */
370 case 17: /* diamonds */
373 case 19: /* diamonds */
377 case 35: /* spades */
379 case 43: /* hearts */
384 case 21: /* diamonds */
388 case 37: /* spades */
391 case 23: /* diamonds */
395 case 39: /* spades */
397 case 45: /* hearts */
400 case 25: /* diamonds */
404 case 41: /* spades */
406 case 47: /* hearts */
410 echo "something went wrong, please contact the admin. ErrorCode: 2 - $card<br>";
416 function create_array_of_random_numbers()
425 $a[ 0]=1; $a[12]=47; $a[24]=13; $a[36]=37;
426 $a[ 1]=2; $a[13]=48; $a[25]=14; $a[37]=38;
427 $a[ 2]=3; $a[14]=27; $a[26]=15; $a[38]=39;
428 $a[ 3]=4; $a[15]=16; $a[27]=28; $a[39]=40;
429 $a[ 4]=5; $a[16]=17; $a[28]=29; $a[40]=41;
430 $a[ 5]=6; $a[17]=18; $a[29]=30; $a[41]=42;
431 $a[ 6]=7; $a[18]=19; $a[30]=31; $a[42]=43;
432 $a[ 7]=8; $a[19]=20; $a[31]=32; $a[43]=44;
433 $a[ 8]=9; $a[20]=45; $a[32]=21; $a[44]=33;
434 $a[ 9]=10; $a[21]=46; $a[33]=22; $a[45]=34;
435 $a[10]=11; $a[22]=35; $a[34]=23; $a[46]=25;
436 $a[11]=12; $a[23]=36; $a[35]=24; $a[47]=26;
454 function display_cards($me,$myturn)
459 function return_timezone($offset)
464 $zone = "Europe/Berlin";
467 $zone = "America/Vancouver";
470 $zone = "Pacific/Auckland";
473 $zone = "Europe/London";
479 function have_suit($cards,$c)
484 if(in_array($c,$CARDS["trump"]))
485 $suite = $CARDS["trump"];
486 else if(in_array($c,$CARDS["clubs"]))
487 $suite = $CARDS["clubs"];
488 else if(in_array($c,$CARDS["spades"]))
489 $suite = $CARDS["spades"];
490 else if(in_array($c,$CARDS["hearts"]))
491 $suite = $CARDS["hearts"];
492 else if(in_array($c,$CARDS["diamonds"]))
493 $suite = $CARDS["diamonds"];
495 foreach($cards as $card)
497 if(in_array($card,$suite))
504 function same_type($card,$c)
509 /* figure out what kind of card c is */
510 if(in_array($c,$CARDS["trump"]))
511 $suite = $CARDS["trump"];
512 else if(in_array($c,$CARDS["clubs"]))
513 $suite = $CARDS["clubs"];
514 else if(in_array($c,$CARDS["spades"]))
515 $suite = $CARDS["spades"];
516 else if(in_array($c,$CARDS["hearts"]))
517 $suite = $CARDS["hearts"];
518 else if(in_array($c,$CARDS["diamonds"]))
519 $suite = $CARDS["diamonds"];
521 /* card is the same suid return 1 */
522 if(in_array($card,$suite))
528 function set_gametype($gametype)
541 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
542 '17','18','19','20','21','22','23','24','25','26');
543 $CARDS["diamonds"] = array();
544 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
545 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
546 $CARDS["hearts"] = array('43','44','45','46','47','48');
547 $CARDS["foxes"] = array('19','20');
548 if($RULES["dullen"]=='none')
550 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
551 '17','18','19','20','21','22','23','24','25','26');
552 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
556 $CARDS["trump"] = array('3','4','5','6','7','8','9','10');
557 $CARDS["clubs"] = array('27','28','29','30','31','32','11','12','33','34');
558 $CARDS["spades"] = array('35','36','37','38','39','40','13','14','41','42');
559 $CARDS["hearts"] = array('43','44', '1', '2','45','46','15','16','47','48');
560 $CARDS["diamonds"] = array('19','20','21','22','23','24','17','18','25','26');
561 $CARDS["foxes"] = array();
564 $CARDS["trump"] = array('11','12','13','14','15','16','17','18');
565 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','33','34');
566 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','41','42');
567 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','47','48');
568 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','25','26');
569 $CARDS["foxes"] = array();
572 $CARDS["trump"] = array();
573 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','11','12','33','34');
574 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','13','14','41','42');
575 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','15','16','47','48');
576 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','17','18','25','26');
577 $CARDS["foxes"] = array();
580 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
581 '17','18','27','28','29','30','31','32','33','34');
582 $CARDS["clubs"] = array();
583 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
584 $CARDS["hearts"] = array('43','44','45','46','47','48');
585 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
586 $CARDS["foxes"] = array();
587 if($RULES["dullen"]=='none')
589 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
590 '17','18','27','28','29','30','31','32','33','34');
591 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
595 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
596 '17','18','35','36','37','38','39','40','41','42');
597 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
598 $CARDS["spades"] = array();
599 $CARDS["hearts"] = array('43','44','45','46','47','48');
600 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
601 $CARDS["foxes"] = array();
602 if($RULES["dullen"]=='none')
604 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
605 '17','18','35','36','37','38','39','40','41','42');
606 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
610 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
611 '17','18','43','44','45','46','47','48');
612 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
613 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
614 $CARDS["hearts"] = array();
615 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
616 $CARDS["foxes"] = array();
617 if($RULES["dullen"]=='none')
619 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
620 '17','18','43','44','1','2','45','46','47','48');
626 function mysort($cards,$gametype)
628 usort ( $cards, "sort_comp" );
632 function sort_comp($a,$b)
637 $ALL = array_merge($CARDS["trump"],$CARDS["diamonds"],$CARDS["clubs"],
638 $CARDS["hearts"],$CARDS["spades"],$CARDS["diamonds"]);
640 return pos_array($a,$ALL)-pos_array($b,$ALL);