Skip to content
 

Scheme hits the App Store

Reverso logo

I believe I have got the first Scheme application past Apple review into the iTunes App Store. It is yet another Reversi clone, called Reverso. It is a combination of 90% Scheme and 10% Objective-C, written with Gambit-C Scheme. James Long has already shown how to compile Gambit-C for the iPhone, and I started from there. My Scheme code is compiled to C by Gambit and later by GCC to produce native ARM code, bundled in a static library, which is ok with the iPhone SDK license agreement. The Objective-C then calls the library as a pure C library. The Scheme code deals with position evaluation, alpha-beta pruning, transposition tables, move legality, different strategies and so on. The Objective-C code deals with sound, animations, GUI, user preferences, basically everything that calls the iPhone OS API. Reversi was chosen because I like strategy games and it is much more algorithmic than artistic, and I am no artist.

The performance of the code is excellent. I used some Gambit-specific declarations, only fixnum arithmetic, pre-allocated a large heap, and called the garbage-collector every time the user needed to think. The search is not memory intensive, but the transposition tables are. I did not write a specific hash function but relied on Gambit-C’s table type. The boards used during search were retrieved from a pool (the newest Gambit-C has made subu8vector-move! a public API), so they did not put pressure on the garbage-collector. In the end it was a very successful experiment. Developing with Scheme is orders of magnitude more productive than with most other languages. Gambit-C is also one of the best Scheme compilers out there, and made my job a lot easier.

Update: There was a bug in the application that caused it to play poorly. The weak AI was not Gambit’s or Scheme’s fault, but mine. I already sent an updated version to Apple that will play much better. Besides fixing the bug, I am now using Zobrist’s hashing instead of Gambit’s own hash function, that performs poorly for game positions. It is still written in Scheme, though. Now I am waiting for the approval of the update, and to hear further feedback from my users. :)

7 Comments

  1. Robert says:

    That is pretty cool.

  2. Congratulations (again! :-) )!

    Pretty nice achievement. Thanks for the info about the implementation.

    Keep the good work.

    Best wishes.
    Mario

  3. Awesome work, Ventonegro! Well done :-)

  4. Leonardo says:

    Congratulations! I just read James Long’s posts and managed to get a small Scheme app running on the device. I was wondering though, is it possible to remotely debug the application when it’s running on the device? I’ve used the remote debugger to debug the program while running it on the iPhone Simulator; but so far I haven’t had any luck getting it to work with the device.

    Any ideas?

  5. Mark says:

    While I think it’s an excellent achievement, and very exciting news that Gambit allows this sort of development, I must say that the strength of Reverso’s AI is very weak even at the highest levels, and that gameplay is painfully slow. I own a few Reversi/Othello games and purchased yours after hearing about it in a Scheme blog.

    There is a good article about the state of Reversi games on the iPhone:
    http://www.macobserver.com/tmo/article/iphone_reversi_games_a_bunch_of_losers/
    Basically, KissTheMachine’s Reversi is the best. And the only one worth spending money on if you’re a half-decent player.

    I think the second victory will come when the Scheme version is comparable in terms of AI strength and playing speed with KissTheMachine Reversi. I hope you continue to improve Reverso towards this end.

    Best of luck.

  6. alex says:

    Hello Mark,

    Thanks for you comments. Actually there was a bug in my code that prevented the proper use of transposition tables. Gambit is up to task, really. I hope you like the next version better. If not, please let me know why.

  7. Mark says:

    Hi Alex. The AI is definitely much improved. Good job!

Leave a Reply