2008-02-19

Cheating

I have come to believe that inventing ways to cheat at games is often more fun than playing the games. Sometimes when I have time to waste, I like to play a quick game of Yahoo! Pool. Some people can make impossible shots more often than a human could and what is there to level the playing field? These types of games were made for cheaters. I see nothing wrong with a person using a straight-edge such as a piece of paper to line up a shot in Y! Pool because everybody has access to that “technology.” Using an auto-aimer against another player? Not cool. Here’s a question: with online games, how do you know if the person you’re playing against is cheating or not? Does it matter to you if you lose to an online cheater?

Groovy!

I hate losing at Scrabble because I don’t have as good of a vocabulary as the computer with a built-in dictionary that I’m playing against. In order to even the playing field, I wrote my own anagram-solver so that I can defeat that darn computer and become a Scrabble champion. For me, writing the program to solve anagrams was much more fun than just playing Scrabble and it has many uses! With a little bit of scripting knowledge and the Web Developer extension for Firefox, it’s easy to modify the anagram-solver to become a “Super Dictionary” in the Make-A-Word game at NerdTests.com. In another script modification, I was able to get a high score in Text Twist because I can send letters to the game as if I had typed them on a keyboard (that possibility makes Text Twist a well designed game in my opinion.) All of these things were fun for my brain when the games had become boring. I’ll post some code for all you would-be cheaters out there. You should be able to find your own plain text dictionary (words.txt). Have fun when you code!

anagram.pl
#/usr/bin/perl -w

my @p = split(/\/|\\/, $0);
my $fName = pop(@p);
my $root = join("\\", @p);

my $dict =  "$root/words.txt";
my @words;

open(DICT, $dict) || die "Couldn't open '$dict': $!\n";
while (<DICT>){
 chomp;
 s/\W//g;
 push(@words, uc($_));
}
close(DICT);

@words = sort { length($a) <=> length($b) } @words;

my $doAgain = 1;
do{
 my %found;
 if(!@ARGV){
  print "Enter an anagram (press Enter to quit): ";
  chomp($input=uc(<STDIN>));
  exit if($input eq "");
 }else{
  $input = uc(shift(@ARGV));
  $doAgain = 0;
 }
 
 $input =~ s/\W+//g;
 print "Anagrams for: $input\n" if $doAgain;
 
 $minLen = 3;
 $maxLen = length($input);
 
 foreach $word (@words){
  my $wordLen = length($word);
  next if($wordLen < $minLen);
  last if($wordLen > $maxLen);
  next if($found{$word});
  my $isIn = true;
  my @wordArr = split(//, $word);
  foreach my $ch (@wordArr){
   $isIn = (index($input, $ch) > -1);
   last if(!$isIn);
  }
  if($isIn){
   my @chars = split(//, $input);
   my $tmp = $word;
   foreach my $ch (@chars){
    #strip used characters from match so they are used only once
    $tmp =~ s/$ch//;
   }
   #print "$word\n" if(length($tmp) == 0);
   ++$found{$word} if(length($tmp) == 0);
  }
 }
 
 foreach $word (sort{length($a) <=> length($b) || $a cmp $b} keys %found){
  print "$word\n";
 }
}while($doAgain);

Text Twist.vbs
Option Explicit

Const HKEY_LOCAL_MACHINE = &H80000002
Dim wshShell, basePath, oReg, strIEPath, oBrowser, txt, output, anagrams, anagram

Set wshShell = WScript.CreateObject("WScript.Shell")
basePath = Mid(WScript.ScriptFullName, 1, InStrRev(WScript.ScriptFullName, "\"))

Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
oReg.GetStringValue HKEY_LOCAL_MACHINE, "SOFTWARE\Clients\StartMenuInternet\FIREFOX.EXE\shell\open\command", "", strIEPath

Function ShellExec(tcShellCmd, tlRetOutput)
 Dim lcStr : lcStr = ""
 If tlRetOutput Then
  Dim oExec : Set oExec = wshShell.Exec(tcShellCmd)
  With oExec.StdOut
   Do Until .AtEndOfStream
    lcStr = lcStr & .ReadLine() & VbCrLf
   Loop
  End With
  Set oExec = Nothing
 Else
  wshShell.Run(tcShellCmd)
 End If
 ShellExec = lcStr
End Function

Set oBrowser = wshShell.Exec(strIEPath & " http://games.yahoo.com/console/tx")
Do
 txt = InputBox("Enter an anagram for Text Twist:", "Text Twist Solver")
 If Len(txt) > 0 And Len(txt) < 8 Then
  'Get anagrams from anagram.pl
  output = ShellExec("perl.exe """ & basePath & "anagram.pl"" " & txt, True)
  WScript.Sleep 500
  anagrams = Split(output, VbCrLf)
  wshShell.AppActivate oBrowser.ProcessID
  For Each anagram In anagrams
   WScript.Sleep 100
   wshShell.SendKeys anagram & "~"
  Next
 End If
Loop While Len(txt) > 0

The good ol' days...

I recall smelling the sweat in Aladdin’s Castle at the Oakridge mall as if I were there today. I must have been about eight years old. I played “Mappy”, “Kung-Fu Master”, “Punch-Out!!” and the other rad video games of the time. Joysticks galore! However, no other game had us lining up to dump our allowances into it the way “Gauntlet” did. Acid pools, goblins, even the touch of Death made the game so annoying yet so tempting. The narrator would say, “warrior shot the food” and “elf needs food, badly” followed soon by, “Valkyrie… is about to die” and finally the “aaaaahhhhh…. (blup)” sound as your player’s body became a pile of bones and ghosts emerged from it. No matter how many tokens I’d put into the game -- no matter how good I was… the outcome was inevitable.

I recall thinking that, after I had spent all of my tokens, “if only that stupid food timer wasn’t always counting down… I’d be able to beat this game!” I was always so driven to win at every game I played. Eventually, the “always dying” part of the game made it stop being fun for me and so I moved on to a different waste of my allowance. Years later someone told me that it wasn’t even possible to defeat the game because it had no end. Today, I find myself looking at my son and his never-ending thirst for the “new game” and I see my old self. I tell him, “save your money to buy a car someday” or “buy something that will go up in value so that you’ll have more money tomorrow” but he does not listen to me. Fortunately for him, most of his money is safe in the bank and he would need my help to retrieve it for him. It waits for him to understand its value.

I still love to play games... so long as I am winning. I have not found a game that I like which I am not very good at. I’m either good at it enough for my own expectations or I don’t want to play it. I love to cheat at games. I was a kid with an NES Advantage and a Game Genie and I remember being very frustrated that even with those tools; I would still lose to my brother’s superior “speed fingers.” If I’m cheating at a game, it’s almost always a one-player game because I wouldn’t like to lose to another cheater. I recently played “Gauntlet” on MAME with unlimited quarters to see how far I could get. The game seemed to be really boring because I never died and I never won. Perhaps something was missing because the multi-player element from the sweaty arcade days was absent.