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);
13 echo "<br />To: $To<br />";
15 echo $header."<br />";
16 echo "Subject: $Subject <br />$message<br />\n";
20 mail($To,$Subject,$message,$header);
22 mail($To,$Subject,$message);
28 /* returns 1 if all names passed as args are defined by a GET or POST statement,
33 $args = func_get_args();
35 foreach($args as $arg)
37 $ok = $ok * isset($_REQUEST[$arg]);
38 /*echo "$arg: ok = $ok <br />";
44 function pos_array($c,$arr)
65 if(in_array($c,$CARDS["trump"]))
71 function is_same_suite($c1,$c2)
75 if(in_array($c1,$CARDS["trump"] ) && in_array($c2,$CARDS["trump"] ) ) return 1;
76 if(in_array($c1,$CARDS["clubs"] ) && in_array($c2,$CARDS["clubs"] ) ) return 1;
77 if(in_array($c1,$CARDS["hearts"] ) && in_array($c2,$CARDS["hearts"] ) ) return 1;
78 if(in_array($c1,$CARDS["spades"] ) && in_array($c2,$CARDS["spades"] ) ) return 1;
79 if(in_array($c1,$CARDS["diamonds"]) && in_array($c2,$CARDS["diamonds"]) ) return 1;
84 function compare_cards($a,$b,$game)
86 /* if "a" is higher than "b" return 1, else 0, "a" being the card first played */
92 /* first map all cards to the odd number,
93 * this insure that the first card wins the trick
94 * if they are the same card
96 if( $a/2 - (int)($a/2) != 0.5)
98 if( $b/2 - (int)($b/2) != 0.5)
101 /* some special cases */
106 if($RULES["schweinchen"]=="both" && $GAME["schweinchen"])
108 if($a == 19 || $a == 20 )
110 if($b == 19 || $b == 20 )
113 if($RULES["schweinchen"]=="second" && $GAME["schweinchen"]==3)
115 if($a == 19 || $a == 20 )
117 if($b == 19 || $b == 20 )
124 if($RULES["dullen"]=="secondwins")
125 if($a==1 && $b==1) /* both 10 of hearts */
126 return 0; /* second one wins.*/
130 if(is_trump($a) && is_trump($b) && $a<=$b)
132 else if(is_trump($a) && is_trump($b) )
135 { /*$a is not a trump */
139 { /* both no trump */
142 $posA = pos_array($a,$CARDS["clubs"]);
143 $posB = pos_array($b,$CARDS["clubs"]);
151 $posA = pos_array($a,$CARDS["spades"]);
152 $posB = pos_array($b,$CARDS["spades"]);
160 $posA = pos_array($a,$CARDS["hearts"]);
161 $posB = pos_array($b,$CARDS["hearts"]);
169 $posA = pos_array($a,$CARDS["diamonds"]);
170 $posB = pos_array($b,$CARDS["diamonds"]);
177 /* not the same suit and no trump: a wins */
183 function get_winner($p,$mode)
185 /* get all 4 cards played in a trick, in the order they are played */
188 $c1pos = $tmp["pos"];
192 $c2pos = $tmp["pos"];
196 $c3pos = $tmp["pos"];
200 $c4pos = $tmp["pos"];
202 /* first card is better than all the rest */
203 if( compare_cards($c1,$c2,$mode) && compare_cards($c1,$c3,$mode) && compare_cards($c1,$c4,$mode) )
206 /* second card is better than first and better than the rest */
207 if( !compare_cards($c1,$c2,$mode) && compare_cards($c2,$c3,$mode) && compare_cards($c2,$c4,$mode) )
210 /* third card is better than first card and better than last */
211 if( !compare_cards($c1,$c3,$mode) && compare_cards($c3,$c4,$mode) )
212 /* if second card is better than first, third card needs to be even better */
213 if( !compare_cards($c1,$c2,$mode) && !compare_cards($c2,$c3,$mode) )
215 /* second is worse than first, e.g. not following suite */
216 else if (compare_cards($c1,$c2,$mode) )
219 /* non of the above */
223 function count_nines($cards)
227 foreach($cards as $c)
229 if($c == "25" || $c == "26") $nines++;
230 else if($c == "33" || $c == "34") $nines++;
231 else if($c == "41" || $c == "42") $nines++;
232 else if($c == "47" || $c == "48") $nines++;
238 function check_wedding($cards)
241 if( in_array("3",$cards) && in_array("4",$cards) )
247 function count_trump($cards)
253 /* count each trump */
254 foreach($cards as $c)
258 switch($RULES["schweinchen"])
263 case "secondaftercall":
264 /* add one, in case the player has both foxes (schweinchen) */
265 if( in_array("19",$cards) && in_array("20",$cards) )
269 if( in_array("19",$cards))
271 if( in_array("20",$cards) )
279 function card_to_name($card)
285 return "ten of hearts";
288 return "queen of clubs";
291 return "queen of spades";
294 return "queen of hearts";
297 return "queen of diamonds";
300 return "jack of clubs";
303 return "jack of spades";
306 return "jack of hearts";
309 return "jack of diamonds";
312 return "ace of diamonds";
315 return "ten of diamonds";
318 return "king of diamonds";
321 return "nine of diamonds";;
324 return "ace of clubs";
327 return "ten of clubs";
330 return "king of clubs";
333 return "nine of clubs";
336 return "ace of spades";
339 return "ten of spades";
342 return "king of spades";
345 return "nine of spades";
348 return "ace of hearts";
351 return "king of hearts";
354 return "nine of hearts";
356 return "something went wrong, please contact the admin. Error: code1. $card <br />";
360 function card_value($card)
370 case 9: /* diamonds */
373 case 11: /* clubes */
375 case 13: /* spades */
377 case 15: /* hearts */
379 case 17: /* diamonds */
382 case 19: /* diamonds */
386 case 35: /* spades */
388 case 43: /* hearts */
393 case 21: /* diamonds */
397 case 37: /* spades */
400 case 23: /* diamonds */
404 case 39: /* spades */
406 case 45: /* hearts */
409 case 25: /* diamonds */
413 case 41: /* spades */
415 case 47: /* hearts */
419 echo "something went wrong, please contact the admin. ErrorCode: 2 - $card<br>";
425 function create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD)
433 $r[ 0]=1; $r[12]=47; $r[24]=13; $r[36]=37;
434 $r[ 1]=2; $r[13]=48; $r[25]=14; $r[37]=38;
435 $r[ 2]=3; $r[14]=27; $r[26]=15; $r[38]=39;
436 $r[ 3]=4; $r[15]=16; $r[27]=28; $r[39]=40;
437 $r[ 4]=5; $r[16]=17; $r[28]=29; $r[40]=41;
438 $r[ 5]=18; $r[17]=6; $r[29]=30; $r[41]=42;
439 $r[ 6]=19; $r[18]=7; $r[30]=31; $r[42]=43;
440 $r[ 7]=20; $r[19]=8; $r[31]=32; $r[43]=44;
441 $r[ 8]=45; $r[20]=9; $r[32]=21; $r[44]=33;
442 $r[ 9]=46; $r[21]=10; $r[33]=22; $r[45]=34;
443 $r[10]=35; $r[22]=11; $r[34]=23; $r[46]=25;
444 $r[11]=36; $r[23]=12; $r[35]=24; $r[47]=26;
448 /* check if we can find a game were non of the player was involved and return
451 $userstr = implode(",",array($useridA,$useridB,$useridC,$useridD));
452 $randomnumbers = DB_get_unused_randomnumbers($userstr);
453 $randomnumbers = explode(":",$randomnumbers);
455 if(sizeof($randomnumbers)==48)
456 return $randomnumbers;
458 /* need to create new numbers */
471 function display_cards($me,$myturn)
476 function return_timezone($offset)
481 $zone = "Europe/Berlin";
484 $zone = "America/Vancouver";
487 $zone = "Pacific/Auckland";
490 $zone = "Europe/London";
496 function have_suit($cards,$c)
501 if(in_array($c,$CARDS["trump"]))
502 $suite = $CARDS["trump"];
503 else if(in_array($c,$CARDS["clubs"]))
504 $suite = $CARDS["clubs"];
505 else if(in_array($c,$CARDS["spades"]))
506 $suite = $CARDS["spades"];
507 else if(in_array($c,$CARDS["hearts"]))
508 $suite = $CARDS["hearts"];
509 else if(in_array($c,$CARDS["diamonds"]))
510 $suite = $CARDS["diamonds"];
512 foreach($cards as $card)
514 if(in_array($card,$suite))
521 function same_type($card,$c)
526 /* figure out what kind of card c is */
527 if(in_array($c,$CARDS["trump"]))
528 $suite = $CARDS["trump"];
529 else if(in_array($c,$CARDS["clubs"]))
530 $suite = $CARDS["clubs"];
531 else if(in_array($c,$CARDS["spades"]))
532 $suite = $CARDS["spades"];
533 else if(in_array($c,$CARDS["hearts"]))
534 $suite = $CARDS["hearts"];
535 else if(in_array($c,$CARDS["diamonds"]))
536 $suite = $CARDS["diamonds"];
538 /* card is the same suid return 1 */
539 if(in_array($card,$suite))
545 function set_gametype($gametype)
558 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
559 '17','18','19','20','21','22','23','24','25','26');
560 $CARDS["diamonds"] = array();
561 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
562 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
563 $CARDS["hearts"] = array('43','44','45','46','47','48');
564 $CARDS["foxes"] = array('19','20');
565 if($RULES["dullen"]=='none')
567 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
568 '17','18','19','20','21','22','23','24','25','26');
569 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
573 $CARDS["trump"] = array('3','4','5','6','7','8','9','10');
574 $CARDS["clubs"] = array('27','28','29','30','31','32','11','12','33','34');
575 $CARDS["spades"] = array('35','36','37','38','39','40','13','14','41','42');
576 $CARDS["hearts"] = array('43','44', '1', '2','45','46','15','16','47','48');
577 $CARDS["diamonds"] = array('19','20','21','22','23','24','17','18','25','26');
578 $CARDS["foxes"] = array();
581 $CARDS["trump"] = array('11','12','13','14','15','16','17','18');
582 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','33','34');
583 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','41','42');
584 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','47','48');
585 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','25','26');
586 $CARDS["foxes"] = array();
589 $CARDS["trump"] = array();
590 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','11','12','33','34');
591 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','13','14','41','42');
592 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','15','16','47','48');
593 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','17','18','25','26');
594 $CARDS["foxes"] = array();
597 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
598 '17','18','27','28','29','30','31','32','33','34');
599 $CARDS["clubs"] = array();
600 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
601 $CARDS["hearts"] = array('43','44','45','46','47','48');
602 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
603 $CARDS["foxes"] = array();
604 if($RULES["dullen"]=='none')
606 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
607 '17','18','27','28','29','30','31','32','33','34');
608 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
612 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
613 '17','18','35','36','37','38','39','40','41','42');
614 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
615 $CARDS["spades"] = array();
616 $CARDS["hearts"] = array('43','44','45','46','47','48');
617 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
618 $CARDS["foxes"] = array();
619 if($RULES["dullen"]=='none')
621 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
622 '17','18','35','36','37','38','39','40','41','42');
623 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
627 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
628 '17','18','43','44','45','46','47','48');
629 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
630 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
631 $CARDS["hearts"] = array();
632 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
633 $CARDS["foxes"] = array();
634 if($RULES["dullen"]=='none')
636 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
637 '17','18','43','44','1','2','45','46','47','48');
643 function mysort($cards,$gametype)
645 usort ( $cards, "sort_comp" );
649 function sort_comp($a,$b)
654 $ALL = array_merge($CARDS["trump"],$CARDS["diamonds"],$CARDS["clubs"],
655 $CARDS["hearts"],$CARDS["spades"],$CARDS["diamonds"]);
657 return pos_array($a,$ALL)-pos_array($b,$ALL);
660 function can_call($what,$hash)
664 /*TODO: check if this already has been call by teammate */
666 $gameid = DB_get_gameid_by_hash($hash);
667 $gametype = DB_get_gametype_by_gameid($gameid);
669 $NRcards = count(DB_get_hand($hash));
674 $user = DB_get_hash_from_game_and_pos($gameid,$i);
675 $NRallcards += count(DB_get_hand($user));
678 /* in case of a wedding, everything will be delayed by an offset */
680 if($gametype=="wedding")
682 $offset = DB_get_sickness_by_gameid($gameid);
683 if ($offset <0) /* not resolved */
687 switch ($RULES["call"])
690 if( 4-($what/30) >= 12 - ($NRcards + $offset))
694 if( 27+4*($what/30) <= $NRallcards + $offset*4)
698 if( ($what/10) <= $NRcards + $offset)