PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Doc/hall/index.php

https://bitbucket.org/toddcarnes/galaxyng
PHP | 257 lines | 210 code | 22 blank | 25 comment | 85 complexity | a4d821029504344a1923fe5301d43854 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  3. "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
  5. <!-- $Id: index.php,v 1.4 2004/09/28 14:34:26 christhecat Exp $ -->
  6. <?php $title="GalaxyNG Hall of Fame"; ?>
  7. <head>
  8. <link rel="stylesheet" href="../main.css" />
  9. <title>GalaxyNG Hall of Fame</title>
  10. </head>
  11. <body>
  12. <?php
  13. // connect to the database
  14. $link = mysql_connect("mysql.sourceforge.net", "galaxyng", "halloffame") or die("Could not connect " . mysql_error());
  15. // make galaxyng the current db
  16. mysql_select_db("galaxyng", $link) or die("Can\'t use galaxyng " . mysql_error());
  17. // page menu
  18. include '../menu.php';
  19. // table of contents
  20. echo "<ul>";
  21. echo "<li><a href=\"";
  22. if ($p) { echo "?p=$p"; }
  23. if ($p and $g) { echo "&amp;"; }
  24. if ($g) { echo "g=$g"; }
  25. echo "#i\">Introduction</a></li>";
  26. echo "<li><a href=\"";
  27. if ($p) { echo "?p=$p"; }
  28. if ($p and $g) { echo "&amp;"; }
  29. if ($g) { echo "g=$g"; }
  30. echo "#p\">Players</a></li>";
  31. echo "<li><a href=\"";
  32. if ($p) { echo "?p=$p"; }
  33. if ($p and $g) { echo "&amp;"; }
  34. if ($g) { echo "g=$g"; }
  35. echo "#g\">Games</a></li>";
  36. echo "</ul>";
  37. ?>
  38. <hr id="i" />
  39. <h2>Introduction</h2>
  40. <p>Players are awarded victory points for Galaxy and GalaxyNG games based on the number of players in each game and their effective industry at the end of the game. Only active members of the winning alliance receive victory points. If the winning alliance is unknown, all active surviving players receive victory points.</p>
  41. <p>Standard victory points are calculated as number-of-players/finish-position. For example, in a game with 20 players, first place receives 20/1=20 points, second place receives 20/2=10 points, third place receives 20/3=6.66 points, and so forth. Standard victory points awarded for a game increase if more players are in the winning alliance. For example, a 40 player game with one winner awards 40 points to the victor. The same game won by a five-player alliance awards 40 points to first place, 20 points to second place, 13.33 points to third place, 10 points to fourth place, and 8 points to fifth place for a total of 91.33 points.</p>
  42. <p>Industry victory points are calculated as (number-of-players*effective-industry)/total-effective-industry where total effective industry is the sum of the effective industry of winning players. For example, in a game with 20 players, three winning players with 50,000, 30,000 and 2,000 effective industry would receive 20*50,000/82,000=12.19 points, 20*30,000/82,000=7.32 points, and 20*2,000/82,000=0.49 points, respectively. Industry victory points awarded for a game always equal the number of players in the game. For example, a 40 player game with one winner awards 40 points to the victor. A five-player alliance winning the same game share 40 points based on each player's percentage of the total effective industry.</p>
  43. <p>The GalaxyNG Hall of Fame includes Galaxy and GalaxyNG games. <a href="http://sourceforge.net/mail/?group_id=48224">Please let us know</a> if you have any additional information about the games in the Hall of Fame or if you would like to add a game. You might also want to visit the <a href="http://www.cs.utk.edu/~bampton/blind/fame.html">Blind Galaxy Hall of Fame</a>, the <a href="http://racelist.uplanet.ru/">GalaxyPlus Race List</a>, the <a href="http://bannikov.omegaplus.ru/racelist/">Orioner RaceList</a>, the <a href="http://explorer.sourceforge.net/hall.html">Galaxy Explorer Hall of Fame</a> and the <a href="http://galaxy.fzu.cz/galaxywww/HallOfFame">Galaxy PBW Hall of Fame</a>.</p>
  44. <hr id="p" />
  45. <?php
  46. // create temporary table playerinfo
  47. mysql_query("CREATE TEMPORARY TABLE playerinfo (player INT(10), standard FLOAT(10,2), industry FLOAT(10,2), firsts INT(10), wins INT(10), games INT(10), sort INT(1))") or die("Could not create table " . mysql_error());
  48. // create the records in playerinfo, count games played and indicate if player has real name
  49. $players = mysql_query("SELECT score.player, COUNT(score.game) AS games, player.last, player.first FROM score LEFT JOIN player ON score.player=player.id GROUP BY score.player");
  50. while ($player = mysql_fetch_array($players)) {
  51. if ($player['last']) { $sort=0; } else if ($player['first']) { $sort=1; } else { $sort=2; }
  52. mysql_query("INSERT INTO playerinfo (player,games,firsts,wins,sort) VALUES ('$player[player]','$player[games]', '0', '0', '$sort')") or die("Could not add player " . mysql_error());
  53. }
  54. // select games (to calculate standard victory points, industry victory points and first place finishes)
  55. $games = mysql_query("SELECT game.id, game.players, SUM(score.eind) AS eind FROM game LEFT JOIN score ON game.id=score.game WHERE score.win='y' GROUP BY game.id");
  56. while ($game = mysql_fetch_array($games)) {
  57. // select scores for each game
  58. $scores = mysql_query("SELECT player,eind FROM score WHERE game='$game[id]' and win='y' ORDER BY eind DESC");
  59. $i = 1;
  60. while ($score = mysql_fetch_array($scores)) {
  61. // select the player from playerinfo if player is not null
  62. if ($score[player]) {
  63. $playerinfos = mysql_query("SELECT * FROM playerinfo WHERE player = $score[player]") or die("couldn't select player from playerinfo " . mysql_error());
  64. $playerinfo = mysql_fetch_array($playerinfos);
  65. // add win
  66. $wins = $playerinfo['wins'] + 1;
  67. mysql_query("UPDATE playerinfo SET wins='$wins' WHERE player='$score[player]'") or die("Could not set wins " . mysql_error());
  68. // add standard victory points
  69. $standard = $playerinfo['standard'] + ($game['players']/$i);
  70. mysql_query("UPDATE playerinfo SET standard='$standard' WHERE player='$score[player]'") or die("Could not update standard victory points " . mysql_error());
  71. // add industry victory points
  72. $industry = $playerinfo['industry'] + (($game['players']*$score['eind'])/$game['eind']);
  73. mysql_query("UPDATE playerinfo SET industry='$industry' WHERE player='$score[player]'") or die("Could not update industry victory points " . mysql_error());
  74. // add first place finish
  75. if ($i == 1) {
  76. $firsts = $playerinfo['firsts'] + 1;
  77. mysql_query("UPDATE playerinfo SET firsts='$firsts' WHERE player='$score[player]'") or die("Could not set firsts " . mysql_error());
  78. }
  79. }
  80. $i++;
  81. }
  82. }
  83. // display header and set sort order for player query
  84. if ($p=="n") {
  85. echo "<h2>Players Sorted by Name</h2>";
  86. $order = "ORDER BY playerinfo.sort ASC, player.last ASC, player.first ASC, player.nick ASC";
  87. } else if ($p=="" or $p=="s") {
  88. echo "<h2>Players Sorted by Standard Victory Points</h2>";
  89. $order = "ORDER BY playerinfo.standard DESC, player.last ASC, player.first ASC";
  90. } else if ($p=="i") {
  91. echo "<h2>Players Sorted by Industry Victory Points</h2>";
  92. $order = "ORDER BY playerinfo.industry DESC, player.last ASC, player.first ASC";
  93. } else if ($p=="f") {
  94. echo "<h2>Players Sorted by First Place Finishes</h2>";
  95. $order = "ORDER BY playerinfo.firsts DESC, player.last ASC, player.first ASC";
  96. } else if ($p=="w") {
  97. echo "<h2>Players Sorted by Games Won</h2>";
  98. $order = "ORDER BY playerinfo.wins DESC, player.last ASC, player.first ASC";
  99. } else if ($p=="g") {
  100. echo "<h2>Players Sorted by Games Played</h2>";
  101. $order = "ORDER BY playerinfo.games DESC, player.last ASC, player.first ASC";
  102. }
  103. // begin player table
  104. echo "<table summary=\"List of players in the hall of fame\">";
  105. echo "<tr><th></th><th class=\"hallhead\">"; if ($p=="n") { echo "Player<br />Name"; } else { echo "<a href=\"?p=n";
  106. if ($g) { echo "&amp;g=$g"; }
  107. echo "#p\">Player<br />Name</a>"; } echo "<br /></th>";
  108. echo "<th class=\"hallhead\">"; if ($p=="" or $p=="s") { echo "Standard<br />Victory<br />Points"; } else { echo "<a href=\"?p=s";
  109. if ($g) { echo "&amp;g=$g"; }
  110. echo "#p\">Standard<br />Victory<br />Points</a>"; } echo "</th>";
  111. echo "<th class=\"hallhead\">"; if ($p=="i") { echo "Industry<br />Victory<br />Points"; } else { echo "<a href=\"?p=i";
  112. if ($g) { echo "&amp;g=$g"; }
  113. echo "#p\">Industry<br />Victory<br />Points</a>"; } echo "</th>";
  114. echo "<th class=\"hallhead\">"; if ($p=="f") { echo "First<br />Place<br />Finishes"; } else { echo "<a href=\"?p=f";
  115. if ($g) { echo "&amp;g=$g"; }
  116. echo "#p\">First<br />Place<br />Finishes</a>"; } echo "</th>";
  117. echo "<th class=\"hallhead\">"; if ($p=="w") { echo "Games<br />Won"; } else { echo "<a href=\"?p=w";
  118. if ($g) { echo "&amp;g=$g"; }
  119. echo "#p\">Games<br />Won</a>"; } echo "</th>";
  120. echo "<th class=\"hallhead\">"; if ($p=="g") { echo "Games<br />Played"; } else { echo "<a href=\"?p=g";
  121. if ($g) { echo "&amp;g=$g"; }
  122. echo "#p\">Games<br />Played</a>"; } echo "</th></tr>";
  123. echo "<tr><td colspan=\"7\"><hr /></td></tr>";
  124. // select the players
  125. $query = "SELECT playerinfo.*, player.first, player.last, player.nick, player.id FROM playerinfo LEFT JOIN player ON playerinfo.player=player.id WHERE playerinfo.player != '0' $order;";
  126. $players = mysql_query($query) or die("Could not sort players by $order " . mysql_error());
  127. // display each player
  128. $i=1; $n=1;
  129. while ($player=mysql_fetch_array($players)) {
  130. // set nulls to zero
  131. if (!$player['firsts']) { $player['firsts']=0; }
  132. if (!$player['standard']) { $player['standard']=0; }
  133. if (!$player['industry']) { $player['industry']=0; }
  134. // decide if this is a tie with the previous player
  135. if ($p=="" or $p=="s") {
  136. if ($tie==$player['standard']) { $tied="y"; } else { $tied="n"; $n=$i; }
  137. $tie=$player['standard'];
  138. } else if ($p=="i") {
  139. if ($tie==$player['industry']) { $tied="y"; } else { $tied="n"; $n=$i; }
  140. $tie=$player['industry'];
  141. } else if ($p=="f") {
  142. if ($tie==$player['firsts']) { $tied="y"; } else { $tied="n"; $n=$i; }
  143. $tie=$player['firsts'];
  144. } else if ($p=="w") {
  145. if ($tie==$player['wins']) { $tied="y"; } else { $tied="n"; $n=$i; }
  146. $tie=$player['wins'];
  147. } else if ($p=="g") {
  148. if ($tie==$player['games']) { $tied="y"; } else { $tied="n"; $n=$i; }
  149. $tie=$player['games'];
  150. }
  151. echo "\n<tr";
  152. // if not sorted by name, highlight the first place player(s)
  153. if ($n==1 and $p!="n") { echo " class=\"hallwin\""; }
  154. echo "><td class=\"hallright\">";
  155. // don't display number if tied with previous player
  156. if ($p!="n" and $tied=="n") { echo $n; }
  157. echo "</td><td class=\"hall\"><a href=\"player.php?p=$player[id]\"";
  158. if ($n==1 and $p!="n") { echo " class=\"hallwin\""; }
  159. echo ">";
  160. if ($player['first'] and $player['last'] and $p=="n") {
  161. echo "$player[last], $player[first]";
  162. } else if ($player['first'] and $player['last']) {
  163. echo "$player[first] $player[last]";
  164. } else if ($player['first']) {
  165. echo "$player[first]";
  166. } else if ($player['last']) {
  167. echo "$player[last]";
  168. } else {
  169. echo "($player[nick])";
  170. }
  171. echo "</a></td><td class=\"hallright\">$player[standard]</td><td class=\"hallright\">$player[industry]</td><td class=\"hallright\">$player[firsts]</td><td class=\"hallright\">$player[wins]</td><td class=\"hallright\">$player[games]</td></tr>";
  172. $i++;
  173. }
  174. // end player table
  175. echo "</table>";
  176. ?>
  177. <hr id="g" />
  178. <?php
  179. // display header and set sort order for games query
  180. if ($g=="" or $g=="n") {
  181. echo "<h2>Games Sorted by Name</h2>";
  182. $order = "ORDER BY game.name, game.year";
  183. } else if ($g=="p") {
  184. echo "<h2>Games Sorted by Number of Players</h2>";
  185. $order = "ORDER BY game.players DESC, game.name, game.year";
  186. } else if ($g=="v") {
  187. echo "<h2>Games Sorted by Variant</h2>";
  188. $order = "ORDER BY game.variant, game.name DESC";
  189. } else if ($g=="g") {
  190. echo "<h2>Games Sorted by Game Master</h2>";
  191. $order = "ORDER BY player.last, player.first, game.name, game.year";
  192. } else if ($g=="y") {
  193. echo "<h2>Games Sorted by Year</h2>";
  194. $order = "ORDER BY game.year DESC, game.name";
  195. }
  196. // begin game table
  197. echo "<table summary=\"List of games in the hall of fame\">";
  198. echo "\n<tr><th class=\"hallhead\">"; if ($g=="" or $g=="n") { echo "Game<br />Name"; } else { echo "<a href=\"?";
  199. if ($p) { echo "p=$p&amp;"; }
  200. echo "g=n#g\">Game<br />Name</a>"; } echo "&nbsp;</th>";
  201. echo "<th class=\"hallhead\">"; if ($g=="p") { echo "Number<br />of<br />Players"; } else { echo "<a href=\"?";
  202. if ($p) { echo "p=$p&amp;"; }
  203. echo "g=p#g\">Number<br />of<br />Players</a>"; } echo "</th>";
  204. echo "<th class=\"hallhead\">"; if ($g=="v") { echo "Variant"; } else { echo "<a href=\"?";
  205. if ($p) { echo "p=$p&amp;"; }
  206. echo "g=v#g\">Variant</a>"; } echo "</th>";
  207. echo "<th class=\"hallhead\">"; if ($g=="g") { echo "Game&nbsp;Master"; } else { echo "<a href=\"?";
  208. if ($p) { echo "p=$p&amp;"; }
  209. echo "g=g#g\">Game&nbsp;Master</a>"; } echo "</th>";
  210. echo "<th class=\"hallhead\">"; if ($g=="y") { echo "Year"; } else { echo "<a href=\"?";
  211. if ($p) { echo "p=$p&amp;"; }
  212. echo "g=y#g\">Year</a>"; } echo "</th></tr>";
  213. echo "<tr><td colspan=\"5\"><hr /></td></tr>";
  214. // someone should figure out how to make this sort properly - currently SmallGame21 appears before SmallGame3
  215. // select games
  216. $games = mysql_query("SELECT game.*, player.first, player.last, player.id as gmid, variant.name as variantname FROM game LEFT JOIN variant ON (game.variant=variant.id) LEFT JOIN player ON (game.gm=player.id) $order");
  217. // display each game
  218. while ($game = mysql_fetch_array($games)) {
  219. echo "\n<tr><td class=\"hall\"><a href=\"game.php?g=$game[id]\">$game[name]</a></td><td class=\"hallright\">$game[players]</td><td class=\"hall\">$game[variantname]</td><td class=\"hall\"><a href=\"player.php?p=$game[gmid]\">$game[first] $game[last]</a></td><td class=\"hallright\">$game[year]</td></tr>";
  220. }
  221. // end game table
  222. echo "</table>";
  223. // page footer
  224. include '../footer.php';
  225. // disconnect from the database
  226. mysql_close($link);
  227. ?>
  228. <table></table>
  229. </body>
  230. </html>