Archive

Posts Tagged ‘pygtk’

Comix, the image viewer

September 9, 2011 Leave a comment

Comix is a user-friendly, customizable image viewer. It is specifically designed to handle comic books, but also serves as a generic viewer. It reads images in ZIP, RAR or tar archives (also gzip or bzip2 compressed) as well as plain image files. It is written in Python and uses GTK+ through the PyGTK bindings.

Available in the Ubuntu repositories:

sudo apt-get install comix
Categories: python Tags: , , ,

Rock-Paper-Scissors: You vs. the Computer

March 8, 2011 1 comment

Computers mimic human reasoning by building on simple rules and statistical averages. Test your strategy against the computer in this rock-paper-scissors game illustrating basic artificial intelligence. Choose from two different modes: novice, where the computer learns to play from scratch, and veteran, where the computer pits over 200,000 rounds of previous experience against you.” (source)

The novice opponent is not too difficult, but it learns quickly. The veteran opponent is tough though, I had the impression that it can read my mind :) The problem is that we, humans, don’t choose our next move randomly and the computer can analyze our strategy.

Choose randomly

After playing with the veteran for a while, I came up with the idea: “Hey, if I could choose randomly, the computer couldn’t analyze my moves”. So here is a simple random number generator:

C:~> python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
>>> li=[1,2,3]
>>> random.choice(li)
2
>>> random.choice(li)
1
>>> random.choice(li)
1

In the “python shell”, you can use the up arrow to call back the previous command(s). With this “cheat” you can surprise the veteran computer :)

I read about this game in this post (in Hungarian).

Update (20110309):

I made a very simple GUI that returns a random number from the interval [1,3] :) Jack’s remark from the comments was taken into account. I’ve never used PyGtk before, I was curious what it’s like. You can get the source code here. Tip: launch the application, right click on it on the task bar, and set “Always On Top” on. This way you can use it together with the game in the browser, you won’t have to switch between the two.

Follow

Get every new post delivered to your Inbox.

Join 44 other followers