Indiana Poker Programming Contest Computers Playing Poker

21Jun/100

Errors when running bots

I've found out that there have been a few oversights in the "writing a bot" instructions.

Java's classpath

First and foremost, the instructions neglected the importance of setting Java's classpath. As you might already know, Java searches all of the paths in the $CLASSPATH variable for the classes you reference via "import" statements. Importing com.indianapokerbot.bot.PokerClient in NetBeans without also referencing IndianaPokerBot.jar at runtime would cause Java to fail with a message like

bash-3.2$ java -cp MyBot.jar MyBot 127.0.0.1 9001
Exception in thread "main" java.lang.NoClassDefFoundError: com/indianapokerbot/bot/PokerClient
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        ...

Unfortunately, for every level of abstraction beyond that, you'd get less and less helpful messages. Running startme.sh might only give Exception in thread "main" java.lang.NoClassDefFoundError: MyBot. If you ran a match using matchConstructor.py, you might only see this in GlassFrog's log:

user@indiana$ ./run.sh
...
Executing bot command: "/path/to/startme.bat 127.0.0.1 9001" from /path/to/
AAAIPPlayer PLAYERONE hit timeout
Removing Room: MYROOM from active list

which is utterly unhelpful.

We have three solutions:

  1. The simplest thing to do is to add IndianaPokerBot.jar to the classpath at runtime by changing startme.sh to say java -cp "/path/to/IndianaPokerBot.jar;MyBot.jar" MyBot $1 $2.
  2. A potentially more convenient method but more invasive method is to permanently set your system $CLASSPATH variable to include IndianaPokerBot.jar, saving you the effort of adding it to every startme.sh script you write. Adding the line CLASSPATH=$CLASSPATH:/path/to/IndianaPokerBot.jar to ~/.bash_profile would do the trick.
  3. The easiest solution would be to skip the classpath madness altogether and copy the contents of IndianaPokerBot/src/ to your own project's src directory. If you do, you also won't need to set external libraries for your project.

Executable permissions

The instructions also neglected to mention that scripts need to, by nature, be marked as executable or else Unix will refuse to run it. If you see errors like java.io.IOException: Cannot run program ...: error=13, Permission denied, run chmod +x startme.sh on the script and it should work.

The instructions have been updated. If you still have issues, please contact us.

Filed under: Help Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

If you have a question, consider using the contact form instead.


No trackbacks yet.