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 /* first card is better than all the rest */
160 if( compare_cards($c1,$c2,$mode) && compare_cards($c1,$c3,$mode) && compare_cards($c1,$c4,$mode) )
163 /* second card is better than first and better than the rest */
164 if( !compare_cards($c1,$c2,$mode) && compare_cards($c2,$c3,$mode) && compare_cards($c2,$c4,$mode) )
167 /* third card is better than first card and better than last */
168 if( !compare_cards($c1,$c3,$mode) && compare_cards($c3,$c4,$mode) )
169 /* if second card is better than first, third card needs to be even better */
170 if( !compare_cards($c1,$c2,$mode) && !compare_cards($c2,$c3,$mode) )
172 /* second is worse than first, e.g. not following suite */
173 else if (compare_cards($c1,$c2,$mode) )
176 /* non of the above */
180 function count_nines($cards)
184 foreach($cards as $c)
186 if($c == "25" || $c == "26") $nines++;
187 else if($c == "33" || $c == "34") $nines++;
188 else if($c == "41" || $c == "42") $nines++;
189 else if($c == "47" || $c == "48") $nines++;
195 function check_wedding($cards)
198 if( in_array("3",$cards) && in_array("4",$cards) )
204 function count_trump($cards)
208 /* count each trump */
209 foreach($cards as $c)
214 if( in_array("19",$cards))
216 if( in_array("20",$cards) )
218 /* add one, in case the player has both foxes (schweinchen) */
219 if( in_array("19",$cards) && in_array("20",$cards) )
225 function card_to_name($card)
231 return "ten of hearts";
234 return "queen of clubs";
237 return "queen of spades";
240 return "queen of hearts";
243 return "queen of diamonds";
246 return "jack of clubs";
249 return "jack of spades";
252 return "jack of hearts";
255 return "jack of diamonds";
258 return "ace of diamonds";
261 return "ten of diamonds";
264 return "king of diamonds";
267 return "nine of diamonds";;
270 return "ace of clubs";
273 return "ten of clubs";
276 return "king of clubs";
279 return "nine of clubs";
282 return "ace of spades";
285 return "ten of spades";
288 return "king of spades";
291 return "nine of spades";
294 return "ace of hearts";
297 return "king of hearts";
300 return "nine of hearts";
302 return "something went wrong, please contact the admin. Error: code1.";
306 function card_value($card)
319 case 9: /* diamonds */
322 case 11: /* clubes */
324 case 13: /* spades */
326 case 15: /* hearts */
328 case 17: /* diamonds */
331 case 19: /* diamonds */
335 case 35: /* spades */
337 case 43: /* hearts */
340 case 21: /* diamonds */
344 case 37: /* spades */
347 case 23: /* diamonds */
351 case 39: /* spades */
353 case 45: /* hearts */
356 case 25: /* diamonds */
360 case 41: /* spades */
362 case 47: /* hearts */
366 echo "something went wrong, please contact the admin. ErrorCode: 2 - $card<br>";
372 function create_array_of_random_numbers()
380 $r = array_rand($a,48);
388 function display_cards($me,$myturn)
393 function return_timezone($offset)
398 $zone = "Europe/Berlin";
401 $zone = "America/Vancouver";
404 $zone = "Pacific/Auckland";
407 $zone = "Europe/London";
413 function have_suit($cards,$c)
415 global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
418 if(in_array($c,$TRUMP))
420 else if(in_array($c,$CLUBS))
422 else if(in_array($c,$SPADES))
424 else if(in_array($c,$HEARTS))
426 else if(in_array($c,$DIAMONDS))
429 foreach($cards as $card)
431 if(in_array($card,$suit))
438 function same_type($card,$c)
440 global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
443 /* figure out what kind of card c is */
444 if(in_array($c,$TRUMP))
446 else if(in_array($c,$CLUBS))
448 else if(in_array($c,$SPADES))
450 else if(in_array($c,$HEARTS))
452 else if(in_array($c,$DIAMONDS))
455 /* card is the same suid return 1 */
456 if(in_array($card,$suit))
462 function set_gametype($gametype)
464 global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
471 $TRUMP = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
472 '17','18','19','20','21','22','23','24','25','26');
474 $CLUBS = array('27','28','29','30','31','32','33','34');
475 $SPADES = array('35','36','37','38','39','40','41','42');
476 $HEARTS = array('43','44','45','46','47','48');
479 $TRUMP = array('3','4','5','6','7','8','9','10');
480 $CLUBS = array('27','28','29','30','31','32','11','12','33','34');
481 $SPADES = array('35','36','37','38','39','40','13','14','41','42');
482 $HEARTS = array('43','44', '1', '2','45','46','15','16','47','48');
483 $DIAMONDS = array('19','20','21','22','23','24','17','18','25','26');
486 $TRUMP = array('11','12','13','14','15','16','17','18');
487 $CLUBS = array('27','28','29','30','31','32','3', '4','33','34');
488 $SPADES = array('35','36','37','38','39','40','5', '6','41','42');
489 $HEARTS = array('43','44', '1', '2','45','46','7', '8','47','48');
490 $DIAMONDS = array('19','20','21','22','23','24','9','10','25','26');
494 $CLUBS = array('27','28','29','30','31','32','3', '4','11','12','33','34');
495 $SPADES = array('35','36','37','38','39','40','5', '6','13','14','41','42');
496 $HEARTS = array('43','44', '1', '2','45','46','7', '8','15','16','47','48');
497 $DIAMONDS = array('19','20','21','22','23','24','9','10','17','18','25','26');
500 $TRUMP = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
501 '17','18','27','28','29','30','31','32','33','34');
503 $SPADES = array('35','36','37','38','39','40','41','42');
504 $HEARTS = array('43','44','45','46','47','48');
505 $DIAMONDS = array('19','20','21','22','23','24','25','26');
508 $TRUMP = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
509 '17','18','35','36','37','38','39','40','41','42');
510 $CLUBS = array('27','28','29','30','31','32','33','34');
512 $HEARTS = array('43','44','45','46','47','48');
513 $DIAMONDS = array('19','20','21','22','23','24','25','26');
516 $TRUMP = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
517 '17','18','43','44','45','46','47','48');
518 $CLUBS = array('27','28','29','30','31','32','33','34');
519 $SPADES = array('35','36','37','38','39','40','41','42');
521 $DIAMONDS = array('19','20','21','22','23','24','25','26');
526 function mysort($cards,$gametype)
528 global $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES;
534 $ALL = array_merge($TRUMP,$DIAMONDS,$CLUBS,$HEARTS,$SPADES,$DIAMONDS);
538 $compare = create_function("$a, $b", "return pos_array($a,$ALL)-pos_array($b,$ALL);");
540 usort ( $cards, $compare );