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,$TRUMP))
62 function is_same_suite($c1,$c2)
64 global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
66 if(in_array($c1,$TRUMP ) && in_array($c2,$TRUMP ) ) return 1;
67 if(in_array($c1,$CLUBS ) && in_array($c2,$CLUBS ) ) return 1;
68 if(in_array($c1,$HEARTS ) && in_array($c2,$HEARTS ) ) return 1;
69 if(in_array($c1,$SPADES ) && in_array($c2,$SPADES ) ) return 1;
70 if(in_array($c1,$DIAMONDS) && in_array($c2,$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 */
79 global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
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,$CLUBS);
118 $posB = pos_array($b,$CLUBS);
126 $posA = pos_array($a,$SPADES);
127 $posB = pos_array($b,$SPADES);
135 $posA = pos_array($a,$HEARTS);
136 $posB = pos_array($b,$HEARTS);
144 $posA = pos_array($a,$DIAMONDS);
145 $posB = pos_array($b,$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.";
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)
432 global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
435 if(in_array($c,$TRUMP))
437 else if(in_array($c,$CLUBS))
439 else if(in_array($c,$SPADES))
441 else if(in_array($c,$HEARTS))
443 else if(in_array($c,$DIAMONDS))
446 foreach($cards as $card)
448 if(in_array($card,$suit))
455 function same_type($card,$c)
457 global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
460 /* figure out what kind of card c is */
461 if(in_array($c,$TRUMP))
463 else if(in_array($c,$CLUBS))
465 else if(in_array($c,$SPADES))
467 else if(in_array($c,$HEARTS))
469 else if(in_array($c,$DIAMONDS))
472 /* card is the same suid return 1 */
473 if(in_array($card,$suit))
479 function set_gametype($gametype)
481 global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
489 $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');
492 $CLUBS = array('27','28','29','30','31','32','33','34');
493 $SPADES = array('35','36','37','38','39','40','41','42');
494 $HEARTS = array('43','44','45','46','47','48');
495 if($RULES["dullen"]=='none')
497 $TRUMP = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
498 '17','18','19','20','21','22','23','24','25','26');
499 $HEARTS = array('43','44','1','2','45','46','47','48');
503 $TRUMP = array('3','4','5','6','7','8','9','10');
504 $CLUBS = array('27','28','29','30','31','32','11','12','33','34');
505 $SPADES = array('35','36','37','38','39','40','13','14','41','42');
506 $HEARTS = array('43','44', '1', '2','45','46','15','16','47','48');
507 $DIAMONDS = array('19','20','21','22','23','24','17','18','25','26');
510 $TRUMP = array('11','12','13','14','15','16','17','18');
511 $CLUBS = array('27','28','29','30','31','32','3', '4','33','34');
512 $SPADES = array('35','36','37','38','39','40','5', '6','41','42');
513 $HEARTS = array('43','44', '1', '2','45','46','7', '8','47','48');
514 $DIAMONDS = array('19','20','21','22','23','24','9','10','25','26');
518 $CLUBS = array('27','28','29','30','31','32','3', '4','11','12','33','34');
519 $SPADES = array('35','36','37','38','39','40','5', '6','13','14','41','42');
520 $HEARTS = array('43','44', '1', '2','45','46','7', '8','15','16','47','48');
521 $DIAMONDS = array('19','20','21','22','23','24','9','10','17','18','25','26');
524 $TRUMP = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
525 '17','18','27','28','29','30','31','32','33','34');
527 $SPADES = array('35','36','37','38','39','40','41','42');
528 $HEARTS = array('43','44','45','46','47','48');
529 $DIAMONDS = array('19','20','21','22','23','24','25','26');
530 if($RULES["dullen"]=='none')
532 $TRUMP = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
533 '17','18','27','28','29','30','31','32','33','34');
534 $HEARTS = array('43','44','1','2','45','46','47','48');
538 $TRUMP = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
539 '17','18','35','36','37','38','39','40','41','42');
540 $CLUBS = array('27','28','29','30','31','32','33','34');
542 $HEARTS = array('43','44','45','46','47','48');
543 $DIAMONDS = array('19','20','21','22','23','24','25','26');
544 if($RULES["dullen"]=='none')
546 $TRUMP = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
547 '17','18','35','36','37','38','39','40','41','42');
548 $HEARTS = array('43','44','1','2','45','46','47','48');
552 $TRUMP = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
553 '17','18','43','44','45','46','47','48');
554 $CLUBS = array('27','28','29','30','31','32','33','34');
555 $SPADES = array('35','36','37','38','39','40','41','42');
557 $DIAMONDS = array('19','20','21','22','23','24','25','26');
558 if($RULES["dullen"]=='none')
560 $TRUMP = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
561 '17','18','43','44','1','2','45','46','47','48');
567 function mysort($cards,$gametype)
569 usort ( $cards, "sort_comp" );
573 function sort_comp($a,$b)
575 global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
578 $ALL = array_merge($TRUMP,$DIAMONDS,$CLUBS,$HEARTS,$SPADES,$DIAMONDS);
580 return pos_array($a,$ALL)-pos_array($b,$ALL);