#!/usr/bin/perl


print "Content-type:text/html\n\n";

&chugCGI(*input);


@charts= 
(
"1997",
"2002",
"2001",
"2003",
"2005"
);

$namechart{"1997"} = "EGM<br>1997";
$namechart{"2001"} = "GI<br>2001";
$namechart{"2002"} = "EGM<br>2002";
$namechart{"2003"} = "IGN<br>2003";
$namechart{"2005"} = "IGN<br>2005";


if($input{"fromform"} ne ""){
    foreach $chart(@charts){
	$use{$chart} = $input{"$chart"};
    }

} else{
    foreach $chart(@charts){
	$use{$chart} = "on";
    }
}



foreach $chart (@charts){
    if($use{$chart} ne ""){
       push @usedcharts,$chart;

    $file = "$chart.txt";
    open(READ,"< $file") || print "Can't read $file $!<br>";;
    for($i = 1; $i <= 100; $i++){
	$line = <READ>;
	chomp $line;
	($newrank,$name,$system,$year) = split(/\t/,$line);

	$global{$name} += (101 - $i);
	


	if(defined($rankbyname_year{$name}{$chart})){
	    #print "$name dup'd in year $chart\n";
	}
	
$rankbyname_year{$name}{$chart} = $i;
	$rankbyyear_name{$chart}{$name} = $i;
	
	#if(! defined($yearforname{$name})){
	if($year ne ""){
	    $yearforname{$name} = $year;
	}
	#	$yearfromcharforname{$name} = $chart;
	#} else {
	#	if($yearforname{$name} ne $year){
	#		print "'$yearforname{$name}' (from $yearfromcharforname{$name})  or '$year' (from $chart) for $name \n";
	#	}
	#}
	
    }
    }	
	close READ;

    
}




$count=0;




print<<__EOQ__;

<head>
<title>kisrael.com|videogames|powerlist</title>
</head>
<body bgcolor="white">
<FONT FACE="ARIAL" SIZE="5" color="black">
<a href="/"><b>kisrael</b>.com</a>
| <a href="..">videogames</a> | powerlist
</font>
<br><br>

These are the ratings from EMG's 100th issue "Top 100 Games Ever" from 1997, their 2002 list, Game Informer's "Top 100 Games of All Time" (August 2001) then IGN.com's
online lists from <a href="http://top100.ign.com/2003/index.html">2003</a> and
<a href="http://top100.ign.com/2005/index.html">2005</a>.  This page calculates each game's "power ranking" by
adding their cumulative <i>"(101 - rank)"</i> for its entry in each of the  lists. (This is probably unfair for games that are too recent to make the older lists; thems the breaks.)
<br><br>
This isn't meant to be a "better" list, just an interesting little tool.  Each of these lists made much better reading, with a description of why it made the cut, so it's worth looking for the back issues or at least seeing IGN's online charts.

<br><br>
Yes, I know this is tragically geeky of me.  I started seeing had the made out
in which systems and which years <a href="egm100.html">made the biggest impact</a> from the 1997 list.  When the
2002 update came out, I then wanted to see <a href="egm100.2002.html">how the list changed</a>.  Then I added in IGN's info into a big static page. When I threw GI into the mix (an "odd man out" in many rankings...plus they don't include year info) I went a little nuts and put the script itself online, allowing people to only look at certain charts.
I had to fudge a few things, ignore a few differences in versions and years and what not. (And a lot of typos) but I think the numbers are pretty good. If EGM makes a new list (in 2007 or so) I might tweak the interface to allow comparing in different orders. (It's not chronological so that the EGMs would be lumped together...what's a year difference among friends.)
<br><br>
<form>
<input type="hidden" name="fromform" value="on">

<b>Use Charts:</b><br>
<table border=1><tr><td>

<table border=0>
<tr>	
__EOQ__

foreach $chart (@charts){
    $checked = "";
    if($use{$chart}) { $checked = " CHECKED ";}
    print<<__EOQ__;

<td valign="top">
		<input type="checkbox" $checked name="$chart">
</td><td>
		<i>$namechart{$chart}</i></th>
</td>

__EOQ__
}

print<<__EOQ__;
<th valign="top">&nbsp;&nbsp;<input type="submit" value="update"></th>
</tr>
</table></form>
</td></tr></table>



<table border=0>

<tr>
<td>&nbsp;</td>
<th>Name</th>
<th>Year</th>
<Th>Pts</th>
<th></th>
__EOQ__
foreach $chart (@charts){
    $checked = "";
    if($use{$chart}) {
    print<<__EOQ__;
	    <th colspan=2>
		<i>$namechart{$chart}</i></th>
__EOQ__
}
}
print<<__EOQ__;

__EOQ__

print "</tr>";



foreach $name (sort {$global{$b} <=> $global{$a}} keys %global){

if($color eq "#CCCCCC") { $color = "#EEEEEE"; }
else { $color = "#CCCCCC"; }

$count++;

print<<__EOQ__;

<tr bgcolor="$color">
<td align=right bgcolor="white">$count.</td>
<td>$name</td>
<td align="center" bgcolor="white"><font size=-1>$yearforname{$name}</font></td>
<td align=center><b>&nbsp;$global{$name}&nbsp;</b></td>
<td bgcolor="white">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
__EOQ__


for($ptr = 0; $ptr <= $#usedcharts; $ptr++){
	$chart = $usedcharts[$ptr];
	    if(defined($rankbyname_year{$name}{$chart})){
		$thisrank = $rankbyname_year{$name}{$chart};
		$delta = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		if($ptr > 0){
			if(defined($rankbyname_year{$name}{$usedcharts[$ptr - 1]})) {
				$oldrank = $rankbyname_year{$name}{$usedcharts[$ptr - 1]};
				$diff = $oldrank - $thisrank;
				if($diff == 0) { $delta = "<font color=blue size=-1 face=\"arial,helvetica,sans-serif\">=</font>"; }
				if($diff > 0) { $delta = "<font color=green size=-1 face=\"arial,helvetica,sans-serif\">\/\\ $diff</font>"; }
				if($diff < 0) { $diff = abs($diff); $delta = "<font color=red size=-1 face=\"arial,helvetica,sans-serif\">\\\/ $diff</font>"; }
			}
		}
	
		print "<td align=center>$thisrank&nbsp</td><td align=center bgcolor=\"white\">$delta</td>\n";
	} else {
		print "<td align=center>--</td><td align=center bgcolor=white>&nbsp;&nbsp;</td>\n";
	}

    }
print "</tr>";

}




print "</table>\n";



sub chugCGI { local (*in) = @_ if @_; local ($i, $key, $val);
	      if($ENV{'REQUEST_METHOD'}eq"POST") { read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
					       }else {$in = $ENV{'QUERY_STRING'};} @in = split(/&/,$in);
	      foreach $i (0 .. $#in) { $in[$i] =~ s/\+/ /g;
($key, $val) = split(/=/,$in[$i],2);$key =~ s/%(..)/pack("c",hex($1))/ge;
$val =~ s/%(..)/pack("c",hex($1))/ge; $in{$key}.= $val;}return length($in);} 
