Well, I’m amazed. Out of the blue comes an implementation of Chinese Chess written in 2000 lines of F# by Đinh Thi Thuy Nga and Nguyen Van Thien from the Vietnam National University in Ho Chi Minh City.
And boy, what an implementation! This thing is functionality-wise awesome: sound, animations, AI, help, multiple piece sets (western, and several chinese variants), multiple levels of play (easy-very hard), undo moves, multiple board images. It’s just extraordinary. A screen shot (from an external website) is below. I didn’t know people in Vietnam were doing so much with F#.
The source has been posted by Robert Pickering, host of the F# Wiki. The source is terse, though that alone does not account for the brevity. Ignoring that, I’d think that this application has one of the highest functionality-to-lines-of-code ratios that I’ve ever seen, due both to the skills of the authors and the brevity of F# code.
Before you dive into the source be aware that it is formatted/indented in a somewhat strange style – I’m following up with the authors as to why they did that, in particular because people wanting to extend the source will probably have to reformat it. This is not really “normal F# style” – the brevity is typical, but the style is strange, and to comprehend the code you’ll probably have to reformat it. To do this you may want to use one of the OCaml emacs modes (or this one) , which also work well for F# (the F# Visual Studio mode does not yet come with an automatic formatter). You might also want to edit away some of the idiosyncratic uses of syntax, and the code probably should be re-organised a little. Or you might want to wait for someone else to post a formatted and commented version (maybe the authors will be able to do this)
BTW, I’m an occasional chess player and teacher, but am not actually familiar with Chinese Chess until now. I can remember a few years back a sweet 8 yr old Chinese girl in my chess class proudly giving a 5 minute talk of Chinese Chess and displaying one of her family’s sets to the class. If only I had known, I would have started practising then – fancy being thrashed by a 2000 line program written in a programming language of (partly) my own making!
[ For those who speak Vietnamese there is a follow up thread here ]