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 */
323 /* shuffle using a better random generator than the standard one */
324 for ($i = 0; $i <48; $i++)
326 $j = @mt_rand(0, $i);
336 function display_cards($me,$myturn)
341 function return_timezone($offset)
346 $zone = "Europe/Berlin";
349 $zone = "America/Vancouver";
352 $zone = "Pacific/Auckland";
355 $zone = "Europe/London";
361 function have_suit($cards,$c)
366 if(in_array($c,$CARDS["trump"]))
367 $suite = $CARDS["trump"];
368 else if(in_array($c,$CARDS["clubs"]))
369 $suite = $CARDS["clubs"];
370 else if(in_array($c,$CARDS["spades"]))
371 $suite = $CARDS["spades"];
372 else if(in_array($c,$CARDS["hearts"]))
373 $suite = $CARDS["hearts"];
374 else if(in_array($c,$CARDS["diamonds"]))
375 $suite = $CARDS["diamonds"];
377 foreach($cards as $card)
379 if(in_array($card,$suite))
386 function same_type($card,$c)
391 /* figure out what kind of card c is */
392 if(in_array($c,$CARDS["trump"]))
393 $suite = $CARDS["trump"];
394 else if(in_array($c,$CARDS["clubs"]))
395 $suite = $CARDS["clubs"];
396 else if(in_array($c,$CARDS["spades"]))
397 $suite = $CARDS["spades"];
398 else if(in_array($c,$CARDS["hearts"]))
399 $suite = $CARDS["hearts"];
400 else if(in_array($c,$CARDS["diamonds"]))
401 $suite = $CARDS["diamonds"];
403 /* card is the same suid return 1 */
404 if(in_array($card,$suite))
410 function set_gametype($gametype)
423 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
424 '17','18','19','20','21','22','23','24','25','26');
425 $CARDS["diamonds"] = array();
426 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
427 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
428 $CARDS["hearts"] = array('43','44','45','46','47','48');
429 $CARDS["foxes"] = array('19','20');
430 if($RULES["dullen"]=='none')
432 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
433 '17','18','19','20','21','22','23','24','25','26');
434 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
438 $CARDS["trump"] = array('3','4','5','6','7','8','9','10');
439 $CARDS["clubs"] = array('27','28','29','30','31','32','11','12','33','34');
440 $CARDS["spades"] = array('35','36','37','38','39','40','13','14','41','42');
441 $CARDS["hearts"] = array('43','44', '1', '2','45','46','15','16','47','48');
442 $CARDS["diamonds"] = array('19','20','21','22','23','24','17','18','25','26');
443 $CARDS["foxes"] = array();
446 $CARDS["trump"] = array('11','12','13','14','15','16','17','18');
447 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','33','34');
448 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','41','42');
449 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','47','48');
450 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','25','26');
451 $CARDS["foxes"] = array();
454 $CARDS["trump"] = array();
455 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','11','12','33','34');
456 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','13','14','41','42');
457 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','15','16','47','48');
458 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','17','18','25','26');
459 $CARDS["foxes"] = array();
462 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
463 '17','18','27','28','29','30','31','32','33','34');
464 $CARDS["clubs"] = array();
465 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
466 $CARDS["hearts"] = array('43','44','45','46','47','48');
467 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
468 $CARDS["foxes"] = array();
469 if($RULES["dullen"]=='none')
471 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
472 '17','18','27','28','29','30','31','32','33','34');
473 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
477 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
478 '17','18','35','36','37','38','39','40','41','42');
479 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
480 $CARDS["spades"] = array();
481 $CARDS["hearts"] = array('43','44','45','46','47','48');
482 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
483 $CARDS["foxes"] = array();
484 if($RULES["dullen"]=='none')
486 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
487 '17','18','35','36','37','38','39','40','41','42');
488 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
492 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
493 '17','18','43','44','45','46','47','48');
494 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
495 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
496 $CARDS["hearts"] = array();
497 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
498 $CARDS["foxes"] = array();
499 if($RULES["dullen"]=='none')
501 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
502 '17','18','43','44','1','2','45','46','47','48');
508 function mysort($cards,$gametype)
510 usort ( $cards, "sort_comp" );
514 function sort_comp($a,$b)
519 $ALL = array_merge($CARDS["trump"],$CARDS["diamonds"],$CARDS["clubs"],
520 $CARDS["hearts"],$CARDS["spades"],$CARDS["diamonds"]);
522 return pos_array($a,$ALL)-pos_array($b,$ALL);
525 function can_call($what,$hash)
529 $gameid = DB_get_gameid_by_hash($hash);
530 $gametype = DB_get_gametype_by_gameid($gameid);
531 $oldcall = DB_get_call_by_hash($hash);
532 $pcall = DB_get_partner_call_by_hash($hash);
534 if( ($pcall!=NULL && $what >= $pcall) ||
535 ($oldcall!=NULL && $what >=$oldcall) )
540 $NRcards = count(DB_get_hand($hash));
545 $user = DB_get_hash_from_game_and_pos($gameid,$i);
546 $NRallcards += count(DB_get_hand($user));
549 /* in case of a wedding, everything will be delayed by an offset */
551 if($gametype=="wedding")
553 $offset = DB_get_sickness_by_gameid($gameid);
554 if ($offset <0) /* not resolved */
558 switch ($RULES["call"])
561 if( 4-($what/30) >= 12 - ($NRcards + $offset))
565 if( 27+4*($what/30) <= $NRallcards + $offset*4)
570 if($oldcall!=NULL && $pcall!=NULL)
571 $mincall = ($oldcall>$pcall) ? $pcall : $oldcall;
572 else if($oldcall!=NULL)
574 else if ($pcall!=NULL)
579 if( 12 <= ($NRcards + $offset))
583 else if ( 9 <= ($NRcards + $offset))
585 if( ($mincall>=0 && $mincall==120) )
588 else if ( 6 <= ($NRcards + $offset))
590 if( ($mincall>=0 && $mincall<=90 && $what<=60 ) )
593 else if ( 3 <= ($NRcards + $offset))
595 if( ($mincall>=0 && $mincall<=60 && $what<=30 ) )
598 else if ( 0 <= ($NRcards + $offset))
600 if( ($mincall>=0 && $mincall<=30 && $what==0 ) )