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 myerror($message)
46 echo "<span class=\"error\">".htmlspecialchars($message)."</span>\n";
47 mymail($ADMIN_EMAIL,$EmailName." Error in Code",$message);
51 function pos_array($c,$arr)
72 if(in_array($c,$CARDS["trump"]))
78 function is_same_suite($c1,$c2)
82 if(in_array($c1,$CARDS["trump"] ) && in_array($c2,$CARDS["trump"] ) ) return 1;
83 if(in_array($c1,$CARDS["clubs"] ) && in_array($c2,$CARDS["clubs"] ) ) return 1;
84 if(in_array($c1,$CARDS["hearts"] ) && in_array($c2,$CARDS["hearts"] ) ) return 1;
85 if(in_array($c1,$CARDS["spades"] ) && in_array($c2,$CARDS["spades"] ) ) return 1;
86 if(in_array($c1,$CARDS["diamonds"]) && in_array($c2,$CARDS["diamonds"]) ) return 1;
91 function compare_cards($a,$b,$game)
93 /* if "a" is higher than "b" return 1, else 0, "a" being the card first played */
99 /* first map all cards to the odd number,
100 * this insure that the first card wins the trick
101 * if they are the same card
103 if( $a/2 - (int)($a/2) != 0.5)
105 if( $b/2 - (int)($b/2) != 0.5)
108 /* some special cases */
113 if($RULES["schweinchen"]=="both" && $GAME["schweinchen"])
115 if($a == 19 || $a == 20 )
117 if($b == 19 || $b == 20 )
120 if($RULES["schweinchen"]=="second" && $GAME["schweinchen"]==3)
122 if($a == 19 || $a == 20 )
124 if($b == 19 || $b == 20 )
131 if($RULES["dullen"]=="secondwins")
132 if($a==1 && $b==1) /* both 10 of hearts */
133 return 0; /* second one wins.*/
137 if(is_trump($a) && is_trump($b) && $a<=$b)
139 else if(is_trump($a) && is_trump($b) )
142 { /*$a is not a trump */
146 { /* both no trump */
149 $posA = pos_array($a,$CARDS["clubs"]);
150 $posB = pos_array($b,$CARDS["clubs"]);
158 $posA = pos_array($a,$CARDS["spades"]);
159 $posB = pos_array($b,$CARDS["spades"]);
167 $posA = pos_array($a,$CARDS["hearts"]);
168 $posB = pos_array($b,$CARDS["hearts"]);
176 $posA = pos_array($a,$CARDS["diamonds"]);
177 $posB = pos_array($b,$CARDS["diamonds"]);
184 /* not the same suit and no trump: a wins */
190 function get_winner($p,$mode)
192 /* get all 4 cards played in a trick, in the order they are played */
195 $c1pos = $tmp["pos"];
199 $c2pos = $tmp["pos"];
203 $c3pos = $tmp["pos"];
207 $c4pos = $tmp["pos"];
209 /* first card is better than all the rest */
210 if( compare_cards($c1,$c2,$mode) && compare_cards($c1,$c3,$mode) && compare_cards($c1,$c4,$mode) )
213 /* second card is better than first and better than the rest */
214 if( !compare_cards($c1,$c2,$mode) && compare_cards($c2,$c3,$mode) && compare_cards($c2,$c4,$mode) )
217 /* third card is better than first card and better than last */
218 if( !compare_cards($c1,$c3,$mode) && compare_cards($c3,$c4,$mode) )
219 /* if second card is better than first, third card needs to be even better */
220 if( !compare_cards($c1,$c2,$mode) && !compare_cards($c2,$c3,$mode) )
222 /* second is worse than first, e.g. not following suite */
223 else if (compare_cards($c1,$c2,$mode) )
226 /* non of the above */
230 function count_nines($cards)
234 foreach($cards as $c)
236 if($c == "25" || $c == "26") $nines++;
237 else if($c == "33" || $c == "34") $nines++;
238 else if($c == "41" || $c == "42") $nines++;
239 else if($c == "47" || $c == "48") $nines++;
245 function check_wedding($cards)
248 if( in_array("3",$cards) && in_array("4",$cards) )
254 function count_trump($cards)
260 /* count each trump */
261 foreach($cards as $c)
265 switch($RULES["schweinchen"])
270 case "secondaftercall":
271 /* add one, in case the player has both foxes (schweinchen) */
272 if( in_array("19",$cards) && in_array("20",$cards) )
276 if( in_array("19",$cards))
278 if( in_array("20",$cards) )
286 function create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD)
294 $r[ 0]=1; $r[12]=47; $r[24]=13; $r[36]=37;
295 $r[ 1]=2; $r[13]=48; $r[25]=14; $r[37]=38;
296 $r[ 2]=3; $r[14]=27; $r[26]=15; $r[38]=39;
297 $r[ 3]=4; $r[15]=16; $r[27]=28; $r[39]=40;
298 $r[ 4]=5; $r[16]=17; $r[28]=29; $r[40]=41;
299 $r[ 5]=18; $r[17]=6; $r[29]=30; $r[41]=42;
300 $r[ 6]=19; $r[18]=7; $r[30]=31; $r[42]=43;
301 $r[ 7]=20; $r[19]=8; $r[31]=32; $r[43]=44;
302 $r[ 8]=45; $r[20]=9; $r[32]=21; $r[44]=33;
303 $r[ 9]=46; $r[21]=10; $r[33]=22; $r[45]=34;
304 $r[10]=35; $r[22]=11; $r[34]=23; $r[46]=25;
305 $r[11]=36; $r[23]=12; $r[35]=24; $r[47]=26;
309 /* check if we can find a game were non of the player was involved and return
312 $userstr = "'".implode("','",array($useridA,$useridB,$useridC,$useridD))."'";
313 $randomnumbers = DB_get_unused_randomnumbers($userstr);
314 $randomnumbers = explode(":",$randomnumbers);
316 if(sizeof($randomnumbers)==48)
317 return $randomnumbers;
319 /* need to create new numbers */
332 function display_cards($me,$myturn)
337 function return_timezone($offset)
342 $zone = "Europe/Berlin";
345 $zone = "America/Vancouver";
348 $zone = "Pacific/Auckland";
351 $zone = "Europe/London";
357 function have_suit($cards,$c)
362 if(in_array($c,$CARDS["trump"]))
363 $suite = $CARDS["trump"];
364 else if(in_array($c,$CARDS["clubs"]))
365 $suite = $CARDS["clubs"];
366 else if(in_array($c,$CARDS["spades"]))
367 $suite = $CARDS["spades"];
368 else if(in_array($c,$CARDS["hearts"]))
369 $suite = $CARDS["hearts"];
370 else if(in_array($c,$CARDS["diamonds"]))
371 $suite = $CARDS["diamonds"];
373 foreach($cards as $card)
375 if(in_array($card,$suite))
382 function same_type($card,$c)
387 /* figure out what kind of card c is */
388 if(in_array($c,$CARDS["trump"]))
389 $suite = $CARDS["trump"];
390 else if(in_array($c,$CARDS["clubs"]))
391 $suite = $CARDS["clubs"];
392 else if(in_array($c,$CARDS["spades"]))
393 $suite = $CARDS["spades"];
394 else if(in_array($c,$CARDS["hearts"]))
395 $suite = $CARDS["hearts"];
396 else if(in_array($c,$CARDS["diamonds"]))
397 $suite = $CARDS["diamonds"];
399 /* card is the same suid return 1 */
400 if(in_array($card,$suite))
406 function set_gametype($gametype)
419 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
420 '17','18','19','20','21','22','23','24','25','26');
421 $CARDS["diamonds"] = array();
422 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
423 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
424 $CARDS["hearts"] = array('43','44','45','46','47','48');
425 $CARDS["foxes"] = array('19','20');
426 if($RULES["dullen"]=='none')
428 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
429 '17','18','19','20','21','22','23','24','25','26');
430 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
434 $CARDS["trump"] = array('3','4','5','6','7','8','9','10');
435 $CARDS["clubs"] = array('27','28','29','30','31','32','11','12','33','34');
436 $CARDS["spades"] = array('35','36','37','38','39','40','13','14','41','42');
437 $CARDS["hearts"] = array('43','44', '1', '2','45','46','15','16','47','48');
438 $CARDS["diamonds"] = array('19','20','21','22','23','24','17','18','25','26');
439 $CARDS["foxes"] = array();
442 $CARDS["trump"] = array('11','12','13','14','15','16','17','18');
443 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','33','34');
444 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','41','42');
445 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','47','48');
446 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','25','26');
447 $CARDS["foxes"] = array();
450 $CARDS["trump"] = array();
451 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','11','12','33','34');
452 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','13','14','41','42');
453 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','15','16','47','48');
454 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','17','18','25','26');
455 $CARDS["foxes"] = array();
458 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
459 '17','18','27','28','29','30','31','32','33','34');
460 $CARDS["clubs"] = array();
461 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
462 $CARDS["hearts"] = array('43','44','45','46','47','48');
463 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
464 $CARDS["foxes"] = array();
465 if($RULES["dullen"]=='none')
467 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
468 '17','18','27','28','29','30','31','32','33','34');
469 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
473 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
474 '17','18','35','36','37','38','39','40','41','42');
475 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
476 $CARDS["spades"] = array();
477 $CARDS["hearts"] = array('43','44','45','46','47','48');
478 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
479 $CARDS["foxes"] = array();
480 if($RULES["dullen"]=='none')
482 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
483 '17','18','35','36','37','38','39','40','41','42');
484 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
488 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
489 '17','18','43','44','45','46','47','48');
490 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
491 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
492 $CARDS["hearts"] = array();
493 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
494 $CARDS["foxes"] = array();
495 if($RULES["dullen"]=='none')
497 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
498 '17','18','43','44','1','2','45','46','47','48');
504 function mysort($cards,$gametype)
506 usort ( $cards, "sort_comp" );
510 function sort_comp($a,$b)
515 $ALL = array_merge($CARDS["trump"],$CARDS["diamonds"],$CARDS["clubs"],
516 $CARDS["hearts"],$CARDS["spades"],$CARDS["diamonds"]);
518 return pos_array($a,$ALL)-pos_array($b,$ALL);
521 function can_call($what,$hash)
525 /*TODO: check if this already has been call by teammate */
527 $gameid = DB_get_gameid_by_hash($hash);
528 $gametype = DB_get_gametype_by_gameid($gameid);
530 $NRcards = count(DB_get_hand($hash));
535 $user = DB_get_hash_from_game_and_pos($gameid,$i);
536 $NRallcards += count(DB_get_hand($user));
539 /* in case of a wedding, everything will be delayed by an offset */
541 if($gametype=="wedding")
543 $offset = DB_get_sickness_by_gameid($gameid);
544 if ($offset <0) /* not resolved */
548 switch ($RULES["call"])
551 if( 4-($what/30) >= 12 - ($NRcards + $offset))
555 if( 27+4*($what/30) <= $NRallcards + $offset*4)
559 if( ($what/10) <= $NRcards + $offset)