3 function mymail($To,$Subject,$message,$header="")
9 $message = str_replace("\n","<br />\n",$message);
10 $message = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
11 "<a href=\"\\0\">\\0</a>", $message);
12 //$message = ereg_replace("(http.*)[ <>]","<a href=\"\\1\">\\1 </a>",$message);
14 echo "<br />To: $To<br />";
16 echo $header."<br />";
17 echo "Subject: $Subject <br />$message<br />\n";
21 mail($To,$Subject,$message,$header);
23 mail($To,$Subject,$message);
29 /* returns 1 if all names passed as args are defined by a GET or POST statement,
34 $args = func_get_args();
36 foreach($args as $arg)
38 $ok = $ok * isset($_REQUEST[$arg]);
39 /*echo "$arg: ok = $ok <br />";
45 function pos_array($c,$arr)
66 if(in_array($c,$CARDS["trump"]))
72 function is_same_suite($c1,$c2)
76 if(in_array($c1,$CARDS["trump"] ) && in_array($c2,$CARDS["trump"] ) ) return 1;
77 if(in_array($c1,$CARDS["clubs"] ) && in_array($c2,$CARDS["clubs"] ) ) return 1;
78 if(in_array($c1,$CARDS["hearts"] ) && in_array($c2,$CARDS["hearts"] ) ) return 1;
79 if(in_array($c1,$CARDS["spades"] ) && in_array($c2,$CARDS["spades"] ) ) return 1;
80 if(in_array($c1,$CARDS["diamonds"]) && in_array($c2,$CARDS["diamonds"]) ) return 1;
85 function compare_cards($a,$b,$game)
87 /* if "a" is higher than "b" return 1, else 0, "a" being the card first played */
93 /* first map all cards to the odd number,
94 * this insure that the first card wins the trick
95 * if they are the same card
97 if( $a/2 - (int)($a/2) != 0.5)
99 if( $b/2 - (int)($b/2) != 0.5)
102 /* some special cases */
107 if($RULES["schweinchen"]=="both" && $GAME["schweinchen"])
109 if($a == 19 || $a == 20 )
111 if($b == 19 || $b == 20 )
114 if($RULES["schweinchen"]=="second" && $GAME["schweinchen"]==3)
116 if($a == 19 || $a == 20 )
118 if($b == 19 || $b == 20 )
125 if($RULES["dullen"]=="secondwins")
126 if($a==1 && $b==1) /* both 10 of hearts */
127 return 0; /* second one wins.*/
131 if(is_trump($a) && is_trump($b) && $a<=$b)
133 else if(is_trump($a) && is_trump($b) )
136 { /*$a is not a trump */
140 { /* both no trump */
143 $posA = pos_array($a,$CARDS["clubs"]);
144 $posB = pos_array($b,$CARDS["clubs"]);
152 $posA = pos_array($a,$CARDS["spades"]);
153 $posB = pos_array($b,$CARDS["spades"]);
161 $posA = pos_array($a,$CARDS["hearts"]);
162 $posB = pos_array($b,$CARDS["hearts"]);
170 $posA = pos_array($a,$CARDS["diamonds"]);
171 $posB = pos_array($b,$CARDS["diamonds"]);
178 /* not the same suit and no trump: a wins */
184 function get_winner($p,$mode)
186 /* get all 4 cards played in a trick, in the order they are played */
189 $c1pos = $tmp["pos"];
193 $c2pos = $tmp["pos"];
197 $c3pos = $tmp["pos"];
201 $c4pos = $tmp["pos"];
203 /* first card is better than all the rest */
204 if( compare_cards($c1,$c2,$mode) && compare_cards($c1,$c3,$mode) && compare_cards($c1,$c4,$mode) )
207 /* second card is better than first and better than the rest */
208 if( !compare_cards($c1,$c2,$mode) && compare_cards($c2,$c3,$mode) && compare_cards($c2,$c4,$mode) )
211 /* third card is better than first card and better than last */
212 if( !compare_cards($c1,$c3,$mode) && compare_cards($c3,$c4,$mode) )
213 /* if second card is better than first, third card needs to be even better */
214 if( !compare_cards($c1,$c2,$mode) && !compare_cards($c2,$c3,$mode) )
216 /* second is worse than first, e.g. not following suite */
217 else if (compare_cards($c1,$c2,$mode) )
220 /* non of the above */
224 function count_nines($cards)
228 foreach($cards as $c)
230 if($c == "25" || $c == "26") $nines++;
231 else if($c == "33" || $c == "34") $nines++;
232 else if($c == "41" || $c == "42") $nines++;
233 else if($c == "47" || $c == "48") $nines++;
239 function check_wedding($cards)
242 if( in_array("3",$cards) && in_array("4",$cards) )
248 function count_trump($cards)
254 /* count each trump */
255 foreach($cards as $c)
259 switch($RULES["schweinchen"])
264 case "secondaftercall":
265 /* add one, in case the player has both foxes (schweinchen) */
266 if( in_array("19",$cards) && in_array("20",$cards) )
270 if( in_array("19",$cards))
272 if( in_array("20",$cards) )
280 function card_to_name($card)
286 return "ten of hearts";
289 return "queen of clubs";
292 return "queen of spades";
295 return "queen of hearts";
298 return "queen of diamonds";
301 return "jack of clubs";
304 return "jack of spades";
307 return "jack of hearts";
310 return "jack of diamonds";
313 return "ace of diamonds";
316 return "ten of diamonds";
319 return "king of diamonds";
322 return "nine of diamonds";;
325 return "ace of clubs";
328 return "ten of clubs";
331 return "king of clubs";
334 return "nine of clubs";
337 return "ace of spades";
340 return "ten of spades";
343 return "king of spades";
346 return "nine of spades";
349 return "ace of hearts";
352 return "king of hearts";
355 return "nine of hearts";
357 return "something went wrong, please contact the admin. Error: code1. $card <br />";
361 function card_value($card)
371 case 9: /* diamonds */
374 case 11: /* clubes */
376 case 13: /* spades */
378 case 15: /* hearts */
380 case 17: /* diamonds */
383 case 19: /* diamonds */
387 case 35: /* spades */
389 case 43: /* hearts */
394 case 21: /* diamonds */
398 case 37: /* spades */
401 case 23: /* diamonds */
405 case 39: /* spades */
407 case 45: /* hearts */
410 case 25: /* diamonds */
414 case 41: /* spades */
416 case 47: /* hearts */
420 echo "something went wrong, please contact the admin. ErrorCode: 2 - $card<br>";
426 function create_array_of_random_numbers()
434 $r[ 0]=1; $r[12]=47; $r[24]=13; $r[36]=37;
435 $r[ 1]=2; $r[13]=48; $r[25]=14; $r[37]=38;
436 $r[ 2]=3; $r[14]=27; $r[26]=15; $r[38]=39;
437 $r[ 3]=4; $r[15]=16; $r[27]=28; $r[39]=40;
438 $r[ 4]=5; $r[16]=17; $r[28]=29; $r[40]=41;
439 $r[ 5]=18; $r[17]=6; $r[29]=30; $r[41]=42;
440 $r[ 6]=19; $r[18]=7; $r[30]=31; $r[42]=43;
441 $r[ 7]=20; $r[19]=8; $r[31]=32; $r[43]=44;
442 $r[ 8]=45; $r[20]=9; $r[32]=21; $r[44]=33;
443 $r[ 9]=46; $r[21]=10; $r[33]=22; $r[45]=34;
444 $r[10]=35; $r[22]=11; $r[34]=23; $r[46]=25;
445 $r[11]=36; $r[23]=12; $r[35]=24; $r[47]=26;
461 function display_cards($me,$myturn)
466 function return_timezone($offset)
471 $zone = "Europe/Berlin";
474 $zone = "America/Vancouver";
477 $zone = "Pacific/Auckland";
480 $zone = "Europe/London";
486 function have_suit($cards,$c)
491 if(in_array($c,$CARDS["trump"]))
492 $suite = $CARDS["trump"];
493 else if(in_array($c,$CARDS["clubs"]))
494 $suite = $CARDS["clubs"];
495 else if(in_array($c,$CARDS["spades"]))
496 $suite = $CARDS["spades"];
497 else if(in_array($c,$CARDS["hearts"]))
498 $suite = $CARDS["hearts"];
499 else if(in_array($c,$CARDS["diamonds"]))
500 $suite = $CARDS["diamonds"];
502 foreach($cards as $card)
504 if(in_array($card,$suite))
511 function same_type($card,$c)
516 /* figure out what kind of card c is */
517 if(in_array($c,$CARDS["trump"]))
518 $suite = $CARDS["trump"];
519 else if(in_array($c,$CARDS["clubs"]))
520 $suite = $CARDS["clubs"];
521 else if(in_array($c,$CARDS["spades"]))
522 $suite = $CARDS["spades"];
523 else if(in_array($c,$CARDS["hearts"]))
524 $suite = $CARDS["hearts"];
525 else if(in_array($c,$CARDS["diamonds"]))
526 $suite = $CARDS["diamonds"];
528 /* card is the same suid return 1 */
529 if(in_array($card,$suite))
535 function set_gametype($gametype)
548 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
549 '17','18','19','20','21','22','23','24','25','26');
550 $CARDS["diamonds"] = array();
551 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
552 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
553 $CARDS["hearts"] = array('43','44','45','46','47','48');
554 $CARDS["foxes"] = array('19','20');
555 if($RULES["dullen"]=='none')
557 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
558 '17','18','19','20','21','22','23','24','25','26');
559 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
563 $CARDS["trump"] = array('3','4','5','6','7','8','9','10');
564 $CARDS["clubs"] = array('27','28','29','30','31','32','11','12','33','34');
565 $CARDS["spades"] = array('35','36','37','38','39','40','13','14','41','42');
566 $CARDS["hearts"] = array('43','44', '1', '2','45','46','15','16','47','48');
567 $CARDS["diamonds"] = array('19','20','21','22','23','24','17','18','25','26');
568 $CARDS["foxes"] = array();
571 $CARDS["trump"] = array('11','12','13','14','15','16','17','18');
572 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','33','34');
573 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','41','42');
574 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','47','48');
575 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','25','26');
576 $CARDS["foxes"] = array();
579 $CARDS["trump"] = array();
580 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','11','12','33','34');
581 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','13','14','41','42');
582 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','15','16','47','48');
583 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','17','18','25','26');
584 $CARDS["foxes"] = array();
587 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
588 '17','18','27','28','29','30','31','32','33','34');
589 $CARDS["clubs"] = array();
590 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
591 $CARDS["hearts"] = array('43','44','45','46','47','48');
592 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
593 $CARDS["foxes"] = array();
594 if($RULES["dullen"]=='none')
596 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
597 '17','18','27','28','29','30','31','32','33','34');
598 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
602 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
603 '17','18','35','36','37','38','39','40','41','42');
604 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
605 $CARDS["spades"] = array();
606 $CARDS["hearts"] = array('43','44','45','46','47','48');
607 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
608 $CARDS["foxes"] = array();
609 if($RULES["dullen"]=='none')
611 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
612 '17','18','35','36','37','38','39','40','41','42');
613 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
617 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
618 '17','18','43','44','45','46','47','48');
619 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
620 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
621 $CARDS["hearts"] = array();
622 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
623 $CARDS["foxes"] = array();
624 if($RULES["dullen"]=='none')
626 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
627 '17','18','43','44','1','2','45','46','47','48');
633 function mysort($cards,$gametype)
635 usort ( $cards, "sort_comp" );
639 function sort_comp($a,$b)
644 $ALL = array_merge($CARDS["trump"],$CARDS["diamonds"],$CARDS["clubs"],
645 $CARDS["hearts"],$CARDS["spades"],$CARDS["diamonds"]);
647 return pos_array($a,$ALL)-pos_array($b,$ALL);
650 function can_call($what,$hash)
654 /*TODO: check if this already has been call by teammate */
656 $gameid = DB_get_gameid_by_hash($hash);
657 $gametype = DB_get_gametype_by_gameid($gameid);
659 $NRcards = count(DB_get_hand($me));
664 $user = DB_get_hash_from_game_and_pos($gameid,$i);
665 $NRallcards += count(DB_get_hand($user));
668 /* in case of a wedding, everything will be delayed by an offset */
670 if($gametype=="wedding")
672 $offset = DB_get_sickness_by_gameid($gameid);
673 if ($offset <0) /* not resolved */
677 switch ($RULES["call"])
680 if( 4-($what/30) >= 12 - $NRcards + $offset)
684 if( 27+4*($what/30) <= $NRallcards + $offset*4)
688 if( ($what/10) <= $NRcards + $offset)