Way back in 2005 Nguyen Van Thien and Dinh Thi Thuy Nga, two computer science students from Vietnam, got in contact asking me to help them share the “Chinese Chess” computer game they’d written in F#. The game plays well and has nice graphics and sounds, quite an achievement given that F# was still in its infancy back in those days. Naturally I want to help them so I gave it a place on my website.
Recently I had a couple of emails saying the link was broken (which I never got round to replying too, sorry guys!) so as part of the site revamp I took the time to upgrade the game to latest version of F# and post it github.
F# has change quite a bit since 2005 and although these changes are for the better it does mean code from back then will no longer compile. Here’s rough guide to what has changed:
- The syntax for accessing an array element (or an indexer on a class) has changed from .(x) to .[x], this is the most annoying thing to fix as you can’t do a straight search and replace as brackets are used in other places too (although you can search and replace on .( which will fix half the problem).
- Library functions have been removed and renamed, mostly this means removing the underscores from the names. Notably Array.create_matrix has gone and so I used Array2D.create which creates a “square” rather than jagged matrix but servers the same purpose.
- You are no longer allowed to use “and” to define identifiers names when the identifiers are not recursive (this code bases used this heavily but I haven’t seen it used much else where). Fortunately this can be easily fixed by search and replacing with “in let” (the code bases uses the old non-whitespace sensitive syntax where in is to control identifiers scope).
- Bitwise operators like “land” (long and) are not no longer keywords and are now symbols &&&.
Porting the game was made somewhat easier as it relied very little on library functions (meaning the second point wasn’t much of a problem), for example rather than rely on a library sorting functions they have their own quicksort implementation. I don’t generally this is a good coding style, but it does improve your chances of forward compatibility.
Anyway, it’s on github now so enjoy!