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()
424 # $r = array_rand($a,48);
433 function display_cards($me,$myturn)
438 function return_timezone($offset)
443 $zone = "Europe/Berlin";
446 $zone = "America/Vancouver";
449 $zone = "Pacific/Auckland";
452 $zone = "Europe/London";
458 function have_suit($cards,$c)
463 if(in_array($c,$CARDS["trump"]))
464 $suite = $CARDS["trump"];
465 else if(in_array($c,$CARDS["clubs"]))
466 $suite = $CARDS["clubs"];
467 else if(in_array($c,$CARDS["spades"]))
468 $suite = $CARDS["spades"];
469 else if(in_array($c,$CARDS["hearts"]))
470 $suite = $CARDS["hearts"];
471 else if(in_array($c,$CARDS["diamonds"]))
472 $suite = $CARDS["diamonds"];
474 foreach($cards as $card)
476 if(in_array($card,$suite))
483 function same_type($card,$c)
488 /* figure out what kind of card c is */
489 if(in_array($c,$CARDS["trump"]))
490 $suite = $CARDS["trump"];
491 else if(in_array($c,$CARDS["clubs"]))
492 $suite = $CARDS["clubs"];
493 else if(in_array($c,$CARDS["spades"]))
494 $suite = $CARDS["spades"];
495 else if(in_array($c,$CARDS["hearts"]))
496 $suite = $CARDS["hearts"];
497 else if(in_array($c,$CARDS["diamonds"]))
498 $suite = $CARDS["diamonds"];
500 /* card is the same suid return 1 */
501 if(in_array($card,$suite))
507 function set_gametype($gametype)
517 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
518 '17','18','19','20','21','22','23','24','25','26');
519 $CARDS["diamonds"] = array();
520 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
521 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
522 $CARDS["hearts"] = array('43','44','45','46','47','48');
523 $CARDS["foxes"] = array('19','20');
524 if($RULES["dullen"]=='none')
526 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
527 '17','18','19','20','21','22','23','24','25','26');
528 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
532 $CARDS["trump"] = array('3','4','5','6','7','8','9','10');
533 $CARDS["clubs"] = array('27','28','29','30','31','32','11','12','33','34');
534 $CARDS["spades"] = array('35','36','37','38','39','40','13','14','41','42');
535 $CARDS["hearts"] = array('43','44', '1', '2','45','46','15','16','47','48');
536 $CARDS["diamonds"] = array('19','20','21','22','23','24','17','18','25','26');
537 $CARDS["foxes"] = array();
540 $CARDS["trump"] = array('11','12','13','14','15','16','17','18');
541 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','33','34');
542 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','41','42');
543 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','47','48');
544 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','25','26');
545 $CARDS["foxes"] = array();
548 $CARDS["trump"] = array();
549 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','11','12','33','34');
550 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','13','14','41','42');
551 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','15','16','47','48');
552 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','17','18','25','26');
553 $CARDS["foxes"] = array();
556 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
557 '17','18','27','28','29','30','31','32','33','34');
558 $CARDS["clubs"] = array();
559 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
560 $CARDS["hearts"] = array('43','44','45','46','47','48');
561 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
562 $CARDS["foxes"] = array();
563 if($RULES["dullen"]=='none')
565 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
566 '17','18','27','28','29','30','31','32','33','34');
567 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
571 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
572 '17','18','35','36','37','38','39','40','41','42');
573 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
574 $CARDS["spades"] = array();
575 $CARDS["hearts"] = array('43','44','45','46','47','48');
576 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
577 $CARDS["foxes"] = array();
578 if($RULES["dullen"]=='none')
580 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
581 '17','18','35','36','37','38','39','40','41','42');
582 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
586 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
587 '17','18','43','44','45','46','47','48');
588 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
589 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
590 $CARDS["hearts"] = array();
591 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
592 $CARDS["foxes"] = array();
593 if($RULES["dullen"]=='none')
595 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
596 '17','18','43','44','1','2','45','46','47','48');
602 function mysort($cards,$gametype)
604 usort ( $cards, "sort_comp" );
608 function sort_comp($a,$b)
613 $ALL = array_merge($CARDS["trump"],$CARDS["diamonds"],$CARDS["clubs"],
614 $CARDS["hearts"],$CARDS["spades"],$CARDS["diamonds"]);
616 return pos_array($a,$ALL)-pos_array($b,$ALL);