4Blocks Source Code

7 05 2010

Today I decided to try my hand at releasing a cabal package with the 4Blocks code. I finally managed: http://hackage.haskell.org/package/4Blocks-0.2. (I made a newbie mistake in 0.1 so please ignore that release).

Unfortunately the library can be compiled only with, as far as i know:

  • GHC 6.8.3
  • Gtk2hs 0.9.13

The reasons why are in the README file in the cabal package, copy/pasted here:

Some notes:
– The game currently works only with GHC 6.8.3 due to its use of Gtk2hs 0.9.13.
– I haven’t tested with anything later but it is likely to fail due the fact that later versions of Gtk2hs have a different system of handling events.
– To make this project compatible with later versions of GHC and Gtk2hs two changes are required:
– Remove the function “permutations” which was copied from a later GHC base library
– Alter key-event handling to the version used by later Gtk2hs: some functions (in CommandKeys.hs) were simply introduced in order to disallow some of the keys used in the game (namely rotation) to trigger continuously when a key is held pressed. I believe this kind of behaviour can be managed automatically with Gtk2hs’ new event handling mechanism, however I haven’t had time to recode accordingly myself.
– I hope to write a patch for this in the near future.

So yeah, fairly old now, but I thought, I’d share the code all the same as some people have requested it earlier. Hopefully I will release the code with my AI later on after my project is over and done with in summer and also a patch to make it work with newer versions of GHC and Gtk2hs.

I have to say I really enjoyed coding the game in Haskell and if you have any comments for me, regarding better ways to code stuff, silly things I did, or anything else please let me know by leaving a comment!

Space Generals

6 05 2010

Hi all!

It’s been more than 4 months since my last post! I’ve been really busy lately creating a website for a game called Space Generals which we are going to use for our research in game AI. The game itself is actually a turn-based one much in the style of Risk with a little twist which will allow us to study hierarchical AI and domain-specific embedded scripting languages. The website’s front-end is developed in Java using the GWT framework while its back-end, which carries out turn-processing and game-logic, is developed in Haskell. Here are some screenshots of the game:

More information about the game and how to play can be found in the User Manual.

Feel free to register and play the game. You need at least one more friend to play a game and up to 5 players can play together.  Also, if possible report any errors and provide suggestions using the game’s:

Email Address


Facebook Group

Also, it would be of great interest to us for you to share your game-playing strategies using the above methods as we shall be using them to create different AIs using the DSEL we are working on at the moment.

Thanks! We hope you enjoy the game!

P.S. Currently only Mozilla Firefox and Google Chrome are supported.

Paper: A Domain-Specific Embedded Language Approach for the Scripting of Game Artificial Intelligence

13 12 2009

Yet again I have ignored this blog for quite some time – I’ve been really busy with an implementation of a game involving a Haskell back-end/Google Web Toolkit front-end (more on this in a future post)  and other deadlines. Anyways I thought I’d share more info on how 4Blocks’ AI was implemented using a DSL embedded in Haskell:

A Domain-Specific Embedded Language Approach for the Scripting of Game Artificial Intelligence, with Gordon Pace, in the Proceedings of the University of Malta Workshop in ICT (WICT’09), 2009.

More info on WICT can be found here. Co-incidentally thanks to Dr Pace’s Erdös Number of 4 I get to have one of at most 5. 🙂 Hope this short paper provides with some interesting lightweight reading. Also, any feedback is greatly appreciated!

Haskell IDEs on Windows

8 09 2009

I’m a Windows user. I do dabble with a little Ubuntu now and then but most of the time since I am running around a lot: uni, work, flat, parent’s home, gf… I tend to stick to one platform. So I said to myself, I can’t work with Haskell the way I am, writing code in Notepad++ and compiling manually in command prompt. (Well I can but I wanted to make things easier). My next logical question was: Is there possibly no IDE for my most fav language? Of course there is… so I look things up and find out that the two most popular beta IDEs are Leksah and EclipseFP2. Both Leksah and Eclipse work on windows as well! Perfect. Anyone would do!

Since, I have worked with gtk and I liked it I went to Leksah first (ahem… there is also the new installer which kinda made the choice in the end for me). I installed it but I couldn’t figure out why it wouldn’t parse my installation’s modules. (I am using the Haskell Platform with ghc 6.10.3 for the pure reason that I want to work with gtk2hs and it currently supports that version.) At first it was due to my system’s lack of the tar application which I tried to fix using GNU Tar. Unfortunately the latter seems to be missing some fork mode so it didn’t work out. Is there any way to remedy this somehow or are there any step by step installations somewhere on how to install Leksah (I have followed the given instructions to no avail)?
Disclaimer: I can’t neglect the fact that I might have not managed to make it work due to lack of knowledge from my part.

After some hours I said… well lets try EclipseFP2. Now I know it was/still is in development but I said, lets give it a shot. Unfortunately I met with problems again:
1. I couldn’t get GHC to work with it even thought I set the Haskell implementation and the scion correctly.
2. I couldn’t make it show what errors my code contained as my console was blank all the time. When I opened the Errors view i found out that my error was due to a problem with:
Could not write file: D:\Eclipse Workspace\.metadata\.plugins\org.eclipse.debug.core\.launches\L\My Project\src. The folders were there up to .launches, the rest was non-existant.

So, I am sorry to say that neither of them worked for me. For now I am going back to Notepad++ and old command prompt. I want to make it clear that I am not saying that the developers who have worked on these IDEs should be ashamed of themselves but the direct opposite. By my attempts I am showing how I applaud their time spent on giving us an IDE. I just wish I was good enough to make the IDEs work myself but sadly I was not able to. I just hope that someday Haskell will have its own IDE or that someday soon I might get time to work on one of the projects myself. I sincerely believe that given the publicity given to Haskell by the various publications and books such as Real World Haskell, the only real thing missing from making this language more mainstream is an IDE. And unfortunately not just on Linux-based systems but also on Windows. We all have to admit that most mainstream people come from Windows: especially first year uni students attending their functional programming course (that’s how I met Haskell) and Java/.Net professional programmers who want to dabble in functional programming.

Anyways, three things:
1. If anyone managed to make Leksah or EclipseFP2 work well on their machines please let me know where I went wrong in the comments. I can’t stop stressing the fact that it could be something I missed.
2. What do you guys think is the future of Haskell’s IDE development?
3. What is the most common platform and compilation method most Haskellers use?
Let me know! 🙂

Edit: Gotta love this community!

1. Just minutes after my post I got a reply from Hamish Mackenzie link with tips on how to fix my problem. I am currently working on it with his help! Thanks!

2. I also asked Thomas ten Cate about EclipseFP2 on his website here and he has replied here.

Thanks both of you guys. 🙂

Edit 2: Leksah works, now EclipseFP2

1. Leksah works for me on Vista. Here is a screenshot as proof!


Coincidentally there is also some of 4Blocks’ code which I hope to release shortly, as soon as I have some time to figure out how to work with Cabal.

2. Going attempt to make EclipseFP2 work next. Since I need to pull the source from the live sources via github and I have never used the latter, it might take me some time. Or I can wait a bit as JP Moresmau seems to be working upon updating EclipseFP2.

To both teams: Keep up the great work. 🙂

4Blocks with AI

19 08 2009

I’ve been wanting to write another blog post on the series on DSELs I’ve been planning, but I’ve been really swamped with work lately. So once more I’ll post a video or two on something I’ve been working on. It’s the 4blocks game again, this time playing on its own with an AI I’ve written for it. Here are the videos:

On the whole these were two good runs. I’ve had much better and much worse runs of course.

The AI is by no means perfect but it uses the DSEL techniques in Haskell. I have two languages acting here:
1. A Tetris DSEL
2. Haskell acting as a meta-language over the Tetris DSEL.

What is happening is that for every new brick the game state is queried by Haskell for certain information such as occupied blocks or number of lines. Using this information, by means of Haskell’s case statement I simply trigger one of a possible number of strategies. These strategies acquire certain information from the game state and generate a DSEL script. This script is then carried out by a DSEL script interpreter.

There are numerous problems with the AI and its mostly because I haven’t had time to write more strategies or a more intelligent way to select what according to the selected strategy is the best final brick destination.

That’s about it for now. Let me know what you think.

4Blocks in Haskell!

6 08 2009

This week, instead of a post on DSELs, I’m going to show what I’ve been working on. It’s my first, real foray into Haskell: a game implementation. Some day soon I hope to make my implementation available on the Haskell libraries repository (Hackage).

Thanks goes to the folk at the Haskell irc channel #haskell who helped me when I got stuck. Special mention goes to Saizan for his everlasting patience.

Some more details:
The game is being played by me in single player mode. The other parts shown are WIP. The graphics library used if anyone is interested is Gtk2hs.

Edit 2:
In light of a comment by one of the visitors of the blog (which was also a nagging worry of mine), and some searching on my side I decided to alter the game’s name and certain minor features to prevent copyright problems. I have uploaded a new video which reflects these changes.

Edit 3:

4Blocks code released! Check here and here for more info! 🙂