My Other Sites

Friends

Python Code Recovery A Success May 1st, 2009

I’ve recently begun a mini project to get my old high school AI code working once again. We created AI’s to play the game of Othello against each other, and these programs were written in Python. For some stupid reason, I only saved the .pyc files of pretty much all of the AI’s I had except for one, which happened to be not that great (loses to randomness). But I digress.

The point is I got the Othello referee (the program which lets AIs battle each other) to work once again by letting it read from .py files and by cleaning up its display code. I also fixed up the only AI file I had so that I could test the referee once more. It really does bring back memories.

I’ve created a template AI file which contains the code needed for any AI to function, and has comments for which defs were left blank. One of my goals here is that anyone wanting to learn Python and work on something a little more interesting can use the template to create as complicated or as simple an AI as he or she wishes. This of course leads me to my other goal: to integrate this Python script into my website and have people be able to upload their AI’s and battle their creations against those on the system. It’s bold, but I like it a lot. I really do want this as I feel it would be something cool that people could do to make learning Python fun. It’ll also allow me to play with programming web with Python, working with a GUI framework for Python (I’m gonna look into wxPython), and will let me test the Python capabilities of my host (Dreamhost is awesome).

I’ll keep logging my Python successes and failures as I progress through this little project of mine. Wish me luck.

Python Backwards Compatibility Sucks April 29th, 2009

A few days ago I found all of my old Python code from high school. I have various files from small assignments, but the one program I am truly interested in resurrecting is the Othello AI program. I have the Othello referree which allows different AI’s to play against one another, and I also have a bunch of compiled Python files for the different AI’s I happen to have. There’s a bit of a problem however: when I try to use the referee to upload these AI’s, I get a bad magic number error.

What!? Bad magic number? And I thought Ruby was full of magic, turns out Python has a whole error around bad magic numbers. I went to look up this error, and I found out that Python doesn’t do well with importing compiled python code (pyc) if it was compiled using an older version of Python. This means all I have to do is recompile the source code with the version of Python I have now. Unfortunately, I don’t have the source code…

Well then I thought, how about I just grab the version of Python that I used to compile them. That’s turning out to be difficult. I grabbed the oldest version of Python that I probably could have used from the Python site, but now none of the AI’s show up in the othello referee list. I have no idea why this is the case, and I’m running out of options.

I have one source for one AI. I’ll have to use this code as a template for other AI’s to be made so that I can have a working version of this program once again. Either that, or I need to find a decompiler or someone who knows how to get old pyc’s to work with newer versions of Python. If anyone knows, drop me a line.