Last active
March 9, 2019 09:32
-
-
Save kernelshreyak/9fb68bb0a76f5f862b121b3460fbbe0b to your computer and use it in GitHub Desktop.
Custom PHP function to build a balanced deck using power distribution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function deckbuilder($gametype){ //custom deck builder function of 20 cards | |
global $dbconnect; | |
$cards=array(); | |
//Build a balanced deck using power distribution | |
if($gametype==3) $pdist=[20,0,0]; //for pokemon cards no distribution | |
else $pdist=[14,5,1]; | |
$i=0; | |
$rs=mysqli_query($dbconnect,"SELECT * FROM tcg_cards WHERE gametype=$gametype AND HP<=7000 ORDER BY RAND() LIMIT 0,$pdist[0]"); | |
while($cdat=mysqli_fetch_array($rs)){ | |
$cards[$i]['name']=$cdat['Name']; | |
$cards[$i]['image']=$cdat['picurl']; | |
$cards[$i]['color']=$cdat['Color']; | |
$cards[$i]['mana']=intval($cdat['Mana']); | |
$cards[$i]['hp']=intval($cdat['HP']); | |
$i+=1; | |
} | |
$rs=mysqli_query($dbconnect,"SELECT * FROM tcg_cards WHERE gametype=$gametype AND HP>7000 AND HP<10000 ORDER BY RAND() LIMIT 0,$pdist[1]"); | |
while($cdat=mysqli_fetch_array($rs)){ | |
$cards[$i]['name']=$cdat['Name']; | |
$cards[$i]['image']=$cdat['picurl']; | |
$cards[$i]['color']=$cdat['Color']; | |
$cards[$i]['mana']=intval($cdat['Mana']); | |
$cards[$i]['hp']=intval($cdat['HP']); | |
$i+=1; | |
} | |
$rs=mysqli_query($dbconnect,"SELECT * FROM tcg_cards WHERE gametype=$gametype AND HP>10000 ORDER BY RAND() LIMIT 0,$pdist[2]"); | |
while($cdat=mysqli_fetch_array($rs)){ | |
$cards[$i]['name']=$cdat['Name']; | |
$cards[$i]['image']=$cdat['picurl']; | |
$cards[$i]['color']=$cdat['Color']; | |
$cards[$i]['mana']=intval($cdat['Mana']); | |
$cards[$i]['hp']=intval($cdat['HP']); | |
$i+=1; | |
} | |
//Random Deck | |
// $i=0; | |
// $rs=mysqli_query($dbconnect,"SELECT * FROM tcg_cards gametype=$gametype ORDER BY RAND() LIMIT 0,20"); | |
// while($data=mysqli_fetch_array($rs)){ | |
// $cards[$i]['name']=$data['Name']; | |
// $cards[$i]['image']=$data['picurl']; | |
// $cards[$i]['color']=$data['Color']; | |
// $cards[$i]['mana']=intval($data['Mana']); | |
// $cards[$i]['hp']=intval($data['HP']); | |
// $i+=1; | |
// } | |
return $cards; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment