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 */
82 /* first map all cards to the odd number,
83 * this insure that the first card wins the trick
84 * if they are the same card
86 if( $a/2 - (int)($a/2) != 0.5)
88 if( $b/2 - (int)($b/2) != 0.5)
91 /* some special cases */
100 if($RULES["dullen"]=="secondwins")
101 if($a==1 && $b==1) /* both 10 of hearts */
102 return 0; /* second one wins.*/
105 if(is_trump($a) && is_trump($b) && $a<=$b)
107 else if(is_trump($a) && is_trump($b) )
110 { /*$a is not a trump */
114 { /* both no trump */
117 $posA = pos_array($a,$CARDS["clubs"]);
118 $posB = pos_array($b,$CARDS["clubs"]);
126 $posA = pos_array($a,$CARDS["spades"]);
127 $posB = pos_array($b,$CARDS["spades"]);
135 $posA = pos_array($a,$CARDS["hearts"]);
136 $posB = pos_array($b,$CARDS["hearts"]);
144 $posA = pos_array($a,$CARDS["diamonds"]);
145 $posB = pos_array($b,$CARDS["diamonds"]);
152 /* not the same suit and no trump: a wins */
158 function get_winner($p,$mode)
160 /* get all 4 cards played in a trick, in the order they are played */
163 $c1pos = $tmp["pos"];
167 $c2pos = $tmp["pos"];
171 $c3pos = $tmp["pos"];
175 $c4pos = $tmp["pos"];
177 /* first card is better than all the rest */
178 if( compare_cards($c1,$c2,$mode) && compare_cards($c1,$c3,$mode) && compare_cards($c1,$c4,$mode) )
181 /* second card is better than first and better than the rest */
182 if( !compare_cards($c1,$c2,$mode) && compare_cards($c2,$c3,$mode) && compare_cards($c2,$c4,$mode) )
185 /* third card is better than first card and better than last */
186 if( !compare_cards($c1,$c3,$mode) && compare_cards($c3,$c4,$mode) )
187 /* if second card is better than first, third card needs to be even better */
188 if( !compare_cards($c1,$c2,$mode) && !compare_cards($c2,$c3,$mode) )
190 /* second is worse than first, e.g. not following suite */
191 else if (compare_cards($c1,$c2,$mode) )
194 /* non of the above */
198 function count_nines($cards)
202 foreach($cards as $c)
204 if($c == "25" || $c == "26") $nines++;
205 else if($c == "33" || $c == "34") $nines++;
206 else if($c == "41" || $c == "42") $nines++;
207 else if($c == "47" || $c == "48") $nines++;
213 function check_wedding($cards)
216 if( in_array("3",$cards) && in_array("4",$cards) )
222 function count_trump($cards)
226 /* count each trump */
227 foreach($cards as $c)
232 if( in_array("19",$cards))
234 if( in_array("20",$cards) )
236 /* add one, in case the player has both foxes (schweinchen) */
237 if( in_array("19",$cards) && in_array("20",$cards) )
243 function card_to_name($card)
249 return "ten of hearts";
252 return "queen of clubs";
255 return "queen of spades";
258 return "queen of hearts";
261 return "queen of diamonds";
264 return "jack of clubs";
267 return "jack of spades";
270 return "jack of hearts";
273 return "jack of diamonds";
276 return "ace of diamonds";
279 return "ten of diamonds";
282 return "king of diamonds";
285 return "nine of diamonds";;
288 return "ace of clubs";
291 return "ten of clubs";
294 return "king of clubs";
297 return "nine of clubs";
300 return "ace of spades";
303 return "ten of spades";
306 return "king of spades";
309 return "nine of spades";
312 return "ace of hearts";
315 return "king of hearts";
318 return "nine of hearts";
320 return "something went wrong, please contact the admin. Error: code1. $card <br />";
324 function card_value($card)
334 case 9: /* diamonds */
337 case 11: /* clubes */
339 case 13: /* spades */
341 case 15: /* hearts */
343 case 17: /* diamonds */
346 case 19: /* diamonds */
350 case 35: /* spades */
352 case 43: /* hearts */
357 case 21: /* diamonds */
361 case 37: /* spades */
364 case 23: /* diamonds */
368 case 39: /* spades */
370 case 45: /* hearts */
373 case 25: /* diamonds */
377 case 41: /* spades */
379 case 47: /* hearts */
383 echo "something went wrong, please contact the admin. ErrorCode: 2 - $card<br>";
389 function create_array_of_random_numbers()
397 $r = array_rand($a,48);
405 function display_cards($me,$myturn)
410 function return_timezone($offset)
415 $zone = "Europe/Berlin";
418 $zone = "America/Vancouver";
421 $zone = "Pacific/Auckland";
424 $zone = "Europe/London";
430 function have_suit($cards,$c)
435 if(in_array($c,$CARDS["trump"]))
436 $suite = $CARDS["trump"];
437 else if(in_array($c,$CARDS["clubs"]))
438 $suite = $CARDS["clubs"];
439 else if(in_array($c,$CARDS["spades"]))
440 $suite = $CARDS["spades"];
441 else if(in_array($c,$CARDS["hearts"]))
442 $suite = $CARDS["hearts"];
443 else if(in_array($c,$CARDS["diamonds"]))
444 $suite = $CARDS["diamonds"];
446 foreach($cards as $card)
448 if(in_array($card,$suite))
455 function same_type($card,$c)
460 /* figure out what kind of card c is */
461 if(in_array($c,$CARDS["trump"]))
462 $suite = $CARDS["trump"];
463 else if(in_array($c,$CARDS["clubs"]))
464 $suite = $CARDS["clubs"];
465 else if(in_array($c,$CARDS["spades"]))
466 $suite = $CARDS["spades"];
467 else if(in_array($c,$CARDS["hearts"]))
468 $suite = $CARDS["hearts"];
469 else if(in_array($c,$CARDS["diamonds"]))
470 $suite = $CARDS["diamonds"];
472 /* card is the same suid return 1 */
473 if(in_array($card,$suite))
479 function set_gametype($gametype)
489 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
490 '17','18','19','20','21','22','23','24','25','26');
491 $CARDS["diamonds"] = array();
492 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
493 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
494 $CARDS["hearts"] = array('43','44','45','46','47','48');
495 $CARDS["foxes"] = array('21','22');
496 if($RULES["dullen"]=='none')
498 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
499 '17','18','19','20','21','22','23','24','25','26');
500 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
504 $CARDS["trump"] = array('3','4','5','6','7','8','9','10');
505 $CARDS["clubs"] = array('27','28','29','30','31','32','11','12','33','34');
506 $CARDS["spades"] = array('35','36','37','38','39','40','13','14','41','42');
507 $CARDS["hearts"] = array('43','44', '1', '2','45','46','15','16','47','48');
508 $CARDS["diamonds"] = array('19','20','21','22','23','24','17','18','25','26');
509 $CARDS["foxes"] = array();
512 $CARDS["trump"] = array('11','12','13','14','15','16','17','18');
513 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','33','34');
514 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','41','42');
515 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','47','48');
516 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','25','26');
517 $CARDS["foxes"] = array();
520 $CARDS["trump"] = array();
521 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','11','12','33','34');
522 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','13','14','41','42');
523 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','15','16','47','48');
524 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','17','18','25','26');
525 $CARDS["foxes"] = array();
528 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
529 '17','18','27','28','29','30','31','32','33','34');
530 $CARDS["clubs"] = array();
531 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
532 $CARDS["hearts"] = array('43','44','45','46','47','48');
533 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
534 $CARDS["foxes"] = array();
535 if($RULES["dullen"]=='none')
537 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
538 '17','18','27','28','29','30','31','32','33','34');
539 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
543 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
544 '17','18','35','36','37','38','39','40','41','42');
545 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
546 $CARDS["spades"] = array();
547 $CARDS["hearts"] = array('43','44','45','46','47','48');
548 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
549 $CARDS["foxes"] = array();
550 if($RULES["dullen"]=='none')
552 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
553 '17','18','35','36','37','38','39','40','41','42');
554 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
558 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
559 '17','18','43','44','45','46','47','48');
560 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
561 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
562 $CARDS["hearts"] = array();
563 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
564 $CARDS["foxes"] = array();
565 if($RULES["dullen"]=='none')
567 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
568 '17','18','43','44','1','2','45','46','47','48');
574 function mysort($cards,$gametype)
576 usort ( $cards, "sort_comp" );
580 function sort_comp($a,$b)
585 $ALL = array_merge($CARDS["trump"],$CARDS["diamonds"],$CARDS["clubs"],
586 $CARDS["hearts"],$CARDS["spades"],$CARDS["diamonds"]);
588 return pos_array($a,$ALL)-pos_array($b,$ALL);