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 */
160 /* first card is better than all the rest */
161 if( compare_cards($c1,$c2,$mode) && compare_cards($c1,$c3,$mode) && compare_cards($c1,$c4,$mode) )
164 /* second card is better than first and better than the rest */
165 if( !compare_cards($c1,$c2,$mode) && compare_cards($c2,$c3,$mode) && compare_cards($c2,$c4,$mode) )
168 /* third card is better than first card and better than last */
169 if( !compare_cards($c1,$c3,$mode) && compare_cards($c3,$c4,$mode) )
170 /* if second card is better than first, third card needs to be even better */
171 if( !compare_cards($c1,$c2,$mode) && !compare_cards($c2,$c3,$mode) )
173 /* second is worse than first, e.g. not following suite */
174 else if (compare_cards($c1,$c2,$mode) )
177 /* non of the above */
181 function count_nines($cards)
185 foreach($cards as $c)
187 if($c == "25" || $c == "26") $nines++;
188 else if($c == "33" || $c == "34") $nines++;
189 else if($c == "41" || $c == "42") $nines++;
190 else if($c == "47" || $c == "48") $nines++;
196 function check_wedding($cards)
199 if( in_array("3",$cards) && in_array("4",$cards) )
205 function count_trump($cards)
209 /* count each trump */
210 foreach($cards as $c)
215 if( in_array("19",$cards))
217 if( in_array("20",$cards) )
219 /* add one, in case the player has both foxes (schweinchen) */
220 if( in_array("19",$cards) && in_array("20",$cards) )
226 function card_to_name($card)
232 return "ten of hearts";
235 return "queen of clubs";
238 return "queen of spades";
241 return "queen of hearts";
244 return "queen of diamonds";
247 return "jack of clubs";
250 return "jack of spades";
253 return "jack of hearts";
256 return "jack of diamonds";
259 return "ace of diamonds";
262 return "ten of diamonds";
265 return "king of diamonds";
268 return "nine of diamonds";;
271 return "ace of clubs";
274 return "ten of clubs";
277 return "king of clubs";
280 return "nine of clubs";
283 return "ace of spades";
286 return "ten of spades";
289 return "king of spades";
292 return "nine of spades";
295 return "ace of hearts";
298 return "king of hearts";
301 return "nine of hearts";
303 return "something went wrong, please contact the admin. Error: code1.";
307 function card_value($card)
320 case 9: /* diamonds */
323 case 11: /* clubes */
325 case 13: /* spades */
327 case 15: /* hearts */
329 case 17: /* diamonds */
332 case 19: /* diamonds */
336 case 35: /* spades */
338 case 43: /* hearts */
341 case 21: /* diamonds */
345 case 37: /* spades */
348 case 23: /* diamonds */
352 case 39: /* spades */
354 case 45: /* hearts */
357 case 25: /* diamonds */
361 case 41: /* spades */
363 case 47: /* hearts */
367 echo "something went wrong, please contact the admin. ErrorCode: 2 - $card<br>";
373 function create_array_of_random_numbers()
381 $r = array_rand($a,48);
389 function display_cards($me,$myturn)
394 function return_timezone($offset)
399 $zone = "Europe/Berlin";
402 $zone = "America/Vancouver";
405 $zone = "Pacific/Auckland";
408 $zone = "Europe/London";
414 function have_suit($cards,$c)
416 global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
419 if(in_array($c,$TRUMP))
421 else if(in_array($c,$CLUBS))
423 else if(in_array($c,$SPADES))
425 else if(in_array($c,$HEARTS))
427 else if(in_array($c,$DIAMONDS))
430 foreach($cards as $card)
432 if(in_array($card,$suit))
439 function same_type($card,$c)
441 global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
444 /* figure out what kind of card c is */
445 if(in_array($c,$TRUMP))
447 else if(in_array($c,$CLUBS))
449 else if(in_array($c,$SPADES))
451 else if(in_array($c,$HEARTS))
453 else if(in_array($c,$DIAMONDS))
456 /* card is the same suid return 1 */
457 if(in_array($card,$suit))
463 function set_gametype($gametype)
465 global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
472 $TRUMP = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
473 '17','18','19','20','21','22','23','24','25','26');
475 $CLUBS = array('27','28','29','30','31','32','33','34');
476 $SPADES = array('35','36','37','38','39','40','41','42');
477 $HEARTS = array('43','44','45','46','47','48');
480 $TRUMP = array('3','4','5','6','7','8','9','10');
481 $CLUBS = array('27','28','29','30','31','32','11','12','33','34');
482 $SPADES = array('35','36','37','38','39','40','13','14','41','42');
483 $HEARTS = array('43','44', '1', '2','45','46','15','16','47','48');
484 $DIAMONDS = array('19','20','21','22','23','24','17','18','25','26');
487 $TRUMP = array('11','12','13','14','15','16','17','18');
488 $CLUBS = array('27','28','29','30','31','32','3', '4','33','34');
489 $SPADES = array('35','36','37','38','39','40','5', '6','41','42');
490 $HEARTS = array('43','44', '1', '2','45','46','7', '8','47','48');
491 $DIAMONDS = array('19','20','21','22','23','24','9','10','25','26');
495 $CLUBS = array('27','28','29','30','31','32','3', '4','11','12','33','34');
496 $SPADES = array('35','36','37','38','39','40','5', '6','13','14','41','42');
497 $HEARTS = array('43','44', '1', '2','45','46','7', '8','15','16','47','48');
498 $DIAMONDS = array('19','20','21','22','23','24','9','10','17','18','25','26');
501 $TRUMP = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
502 '17','18','27','28','29','30','31','32','33','34');
504 $SPADES = array('35','36','37','38','39','40','41','42');
505 $HEARTS = array('43','44','45','46','47','48');
506 $DIAMONDS = array('19','20','21','22','23','24','25','26');
509 $TRUMP = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
510 '17','18','35','36','37','38','39','40','41','42');
511 $CLUBS = array('27','28','29','30','31','32','33','34');
513 $HEARTS = array('43','44','45','46','47','48');
514 $DIAMONDS = array('19','20','21','22','23','24','25','26');
517 $TRUMP = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
518 '17','18','43','44','45','46','47','48');
519 $CLUBS = array('27','28','29','30','31','32','33','34');
520 $SPADES = array('35','36','37','38','39','40','41','42');
522 $DIAMONDS = array('19','20','21','22','23','24','25','26');