We recently wrapped up the first Ibuildings challenge of 2011; a contest to create a virtual gamer able to play Four in a Line (you might also know it as Four in a Row, Connect Four or Find Four). Ibuildings provided the gaming field and the abstract player class that everyone needed to extend, and the competitors provided the rest. This post announces the winners and makes some observations based on the submissions we received.
Tournament key rules
- If a player attempts to make any illegal move, they will automatically lose the match. Illegal moves are trying to insert a disc into a column that’s full, or trying to insert a disc into a column that doesn’t exist.
- To keep things fair for everybody, we created 3 categories based on your PHP experience (0-2 years experience, 2-4 years experience, 4+ years experience).
- Points were awarded in the following way:
- 3 points for a win
- 1 point for a tie
- no points for a lose
Let the Battle Commence
Four in a Line as game has been mathematically solved and the advantage lies with the player taking the first turn. To level the playing field, we allowed each player to fight against all the others; in this way, any player had the chance to begin with the first move advantage playing against all the other opponents at least once, sharing the elements of luck and making it easier to spot skill. Each game was played on the official 7 x 6 grid on a basis of three rounds per game. At the end of each qualification session only the players with the highest score moved further in the tournament.
Competition Entries
As usual we had 3 categories; Junior developers, Medium developers and Senior developers. In contrast to our previous challenges however, every single submission was successful, with every entry able to play the game within the rules successfully.
Winners
The competition is designed to be fun for the participants, but it is also good fun for us too and we have to say that the whole challenge has been very exciting and interesting. We will comment on the trends we saw but first: the winners!
Junior category
In the Junior category we had only two submissions, their games played very fast (all less than 1 second) due to the simplicity of the algorithm implemented; despite this we have to say that the quality of the code was pretty good in this category.
Category Winner Junior: Xavier Van Herpe
Medium category
We saw 4 submissions for this intermediate section and in general, the execution time increased. There were plenty of fast games but the average time was about 3 minutes and 30 seconds. Code quality is increased and we started to see some advanced gaming logic and strategy. Players anticipated the play and picked moves with consideration for what their following move would be.
A special mention goes to Tobias Rojahn because with a relatively short implementation in terms of lines of code, his gamer played very well.
Category Winner Medium: Piotr Mlocek
Senior category
This category for more experienced developers delivered a huge range of submissions, from a very interesting tiny implementation from Klaus Jorgensen, less than hundred lines, to the most complex and much larger proposal by Tomas Creemers. The longest game took exactly 04h 56m 09s on a 2.53Ghz Intel Core 2 Duo. Again we’d like to give a special mention in this category, this time to Tjado Maecke: his virtual player was the only one able to challenge our winner, scoring one win and a couple of draws.
Category Winner Senior: Tomas Creemers
Prizes
Amongst all the winners, we raffled three prizes: 2 tickets to the Dutch PHP Conference and an iPad. The prizes go as follows:
DPC tickets: Xavier Van Herpe and Piotr Mlocek
iPad: Tomas Creemers
Congratulations to all the winners!
Observations
In this challenge, we didn’t impose any strict restrictions regarding performance, code standards or time limits, the only rule was to play and win. It was interesting to us to see how various programming practices varied across the submissions, and we think that it’s important to remark on some basic but very important general notions as we saw it.
Coding standards
Whether you are new to PHP programming or a seasoned veteran you can benefit from following a set of coding standards. Such standards haven’t always been a key area, but nowadays PHP reaches so many major projects and enterprise organisations that we’d expect to see these consistent standards everywhere the language is used. Between the 14 developers in this challenge, we saw four general different coding styles plus several personal touches. Personal touch is acceptable in some settings, but a developer must remember that the code is going to be read by someone else and the reader should be comfortable with it.
We have a previous article about PHP Code Sniffer so check that out if you’re looking for a tool to help you with standards. We also advise that one of the existing standards such as Zend or PEAR are better than inventing your own standard for code.
Performance
As developers, we often need to find a compromise between complexity and precision versus speed and approximation. We have seen a very good virtual player win and play ten times faster than others, and we also saw games that ran for many hours. As an example, when we ran some contests in simulation mode to see how the AI were working, we saw this scenario:
. X X X . . O
The (X) player was the one supposed to make the next move and the AI took more than 10 minutes to decide what that move should be. We understand the algorithm has been implemented to be good and successful but in a real scenarios the KISS approach would have helped a lot!
Conclusions
For us as organisers, this has been another fun challenge and we look forward to the next (watch this space!) We offer our warm congratulations to all our participants for such a high standard of submission, and especially to our winners who fought off some stiff competition to emerge victorious. Thanks to all of you and we hope you had as much fun as we did!