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;
81 /* first map all cards to the odd number,
82 * this insure that the first card wins the trick
83 * if they are the same card
85 if( $a/2 - (int)($a/2) != 0.5)
87 if( $b/2 - (int)($b/2) != 0.5)
90 /* some special cases */
94 if($a==1 && $b==1) /* both 10 of hearts */
95 return 0; /* second one wins. TODO should be able to set this at the start of a new game */
98 if(is_trump($a) && is_trump($b) && $a<=$b)
100 else if(is_trump($a) && is_trump($b) )
103 { /*$a is not a trump */
107 { /* both no trump */
110 $posA = pos_array($a,$CLUBS);
111 $posB = pos_array($b,$CLUBS);
119 $posA = pos_array($a,$SPADES);
120 $posB = pos_array($b,$SPADES);
128 $posA = pos_array($a,$HEARTS);
129 $posB = pos_array($b,$HEARTS);
137 $posA = pos_array($a,$DIAMONDS);
138 $posB = pos_array($b,$DIAMONDS);
145 /* not the same suit and no trump: a wins */
151 function get_winner($p,$mode)
153 /* get all 4 cards played in a trick */
159 /* find out who won */
161 /* first card is better than all the rest */
162 if( compare_cards($c1,$c2,$mode) && compare_cards($c1,$c3,$mode) && compare_cards($c1,$c4,$mode) )
165 /* second card is better than first and better than the rest */
166 if( !compare_cards($c1,$c2,$mode) && compare_cards($c2,$c3,$mode) && compare_cards($c2,$c4,$mode) )
169 /* third card is better than first card and better than last */
170 if( !compare_cards($c1,$c3,$mode) && compare_cards($c3,$c4,$mode) )
171 /* if second card is better than first, third card needs to be even better */
172 if( !compare_cards($c1,$c2,$mode) && !compare_cards($c2,$c3,$mode) )
174 /* second is worse than first, e.g. not following suite */
175 else if (compare_cards($c1,$c2,$mode) )
178 /* non of the above */
182 function count_nines($cards)
186 foreach($cards as $c)
188 if($c == "25" || $c == "26") $nines++;
189 else if($c == "33" || $c == "34") $nines++;
190 else if($c == "41" || $c == "42") $nines++;
191 else if($c == "47" || $c == "48") $nines++;
197 function check_wedding($cards)
200 if( in_array("3",$cards) && in_array("4",$cards) )
206 function count_trump($cards)
210 /* count each trump */
211 foreach($cards as $c)
216 if( in_array("19",$cards))
218 if( in_array("20",$cards) )
220 /* add one, in case the player has both foxes (schweinchen) */
221 if( in_array("19",$cards) && in_array("20",$cards) )
227 function card_to_name($card)
233 return "ten of hearts";
236 return "queen of clubs";
239 return "queen of spades";
242 return "queen of hearts";
245 return "queen of diamonds";
248 return "jack of clubs";
251 return "jack of spades";
254 return "jack of hearts";
257 return "jack of diamonds";
260 return "ace of diamonds";
263 return "ten of diamonds";
266 return "king of diamonds";
269 return "nine of diamonds";;
272 return "ace of clubs";
275 return "ten of clubs";
278 return "king of clubs";
281 return "nine of clubs";
284 return "ace of spades";
287 return "ten of spades";
290 return "king of spades";
293 return "nine of spades";
296 return "ace of hearts";
299 return "king of hearts";
302 return "nine of hearts";
304 return "something went wrong, please contact the admin. Error: code1.";
308 function card_value($card)
321 case 9: /* diamonds */
324 case 11: /* clubes */
326 case 13: /* spades */
328 case 15: /* hearts */
330 case 17: /* diamonds */
333 case 19: /* diamonds */
337 case 35: /* spades */
339 case 43: /* hearts */
342 case 21: /* diamonds */
346 case 37: /* spades */
349 case 23: /* diamonds */
353 case 39: /* spades */
355 case 45: /* hearts */
358 case 25: /* diamonds */
362 case 41: /* spades */
364 case 47: /* hearts */
368 echo "something went wrong, please contact the admin. ErrorCode: 2<br>";
374 function create_array_of_random_numbers()
382 $r = array_rand($a,48);
390 function display_cards($me,$myturn)
395 function return_timezone($offset)
400 $zone = "Europe/Berlin";
403 $zone = "America/Vancouver";
406 $zone = "Pacific/Auckland";
409 $zone = "Europe/London";
415 function have_suit($cards,$c)
417 global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
420 if(in_array($c,$TRUMP))
422 else if(in_array($c,$CLUBS))
424 else if(in_array($c,$SPADES))
426 else if(in_array($c,$HEARTS))
428 else if(in_array($c,$DIAMONDS))
431 foreach($cards as $card)
433 if(in_array($card,$suit))
440 function same_type($card,$c)
442 global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
445 /* figure out what kind of card c is */
446 if(in_array($c,$TRUMP))
448 else if(in_array($c,$CLUBS))
450 else if(in_array($c,$SPADES))
452 else if(in_array($c,$HEARTS))
454 else if(in_array($c,$DIAMONDS))
457 /* card is the same suid return 1 */
458 if(in_array($card,$suit))
464 function set_gametype($gametype)
466 global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
473 $TRUMP = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
474 '17','18','19','20','21','22','23','24','25','26');
476 $CLUBS = array('27','28','29','30','31','32','33','34');
477 $SPADES = array('35','36','37','38','39','40','41','42');
478 $HEARTS = array('43','44','45','46','47','48');
481 $TRUMP = array('3','4','5','6','7','8','9','10');
482 $CLUBS = array('27','28','29','30','31','32','11','12','33','34');
483 $SPADES = array('35','36','37','38','39','40','13','14','41','42');
484 $HEARTS = array('43','44', '1', '2','45','46','15','16','47','48');
485 $DIAMONDS = array('19','20','21','22','23','24','17','18','25','26');
488 $TRUMP = array('11','12','13','14','15','16','17','18');
489 $CLUBS = array('27','28','29','30','31','32','3', '4','33','34');
490 $SPADES = array('35','36','37','38','39','40','5', '6','41','42');
491 $HEARTS = array('43','44', '1', '2','45','46','7', '8','47','48');
492 $DIAMONDS = array('19','20','21','22','23','24','9','10','25','26');
496 $CLUBS = array('27','28','29','30','31','32','3', '4','11','12','33','34');
497 $SPADES = array('35','36','37','38','39','40','5', '6','13','14','41','42');
498 $HEARTS = array('43','44', '1', '2','45','46','7', '8','15','16','47','48');
499 $DIAMONDS = array('19','20','21','22','23','24','9','10','17','18','25','26');
502 $TRUMP = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
503 '17','18','27','28','29','30','31','32','33','34');
505 $SPADES = array('35','36','37','38','39','40','41','42');
506 $HEARTS = array('43','44','45','46','47','48');
507 $DIAMONDS = array('19','20','21','22','23','24','25','26');
510 $TRUMP = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
511 '17','18','35','36','37','38','39','40','41','42');
512 $CLUBS = array('27','28','29','30','31','32','33','34');
514 $HEARTS = array('43','44','45','46','47','48');
515 $DIAMONDS = array('19','20','21','22','23','24','25','26');
518 $TRUMP = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
519 '17','18','43','44','45','46','47','48');
520 $CLUBS = array('27','28','29','30','31','32','33','34');
521 $SPADES = array('35','36','37','38','39','40','41','42');
523 $DIAMONDS = array('19','20','21','22','23','24','25','26');