Hari's Corner

Humour, comics, tech, law, software, reviews, essays, articles and HOWTOs intermingled with random philosophy now and then

Tic Tac Toe (a.k.a Noughts and Crosses) in Haskell

Filed under: Tutorials and HOWTOs by Hari
Posted on Fri, Aug 30, 2013 at 10:21 IST (last updated: Mon, Sep 16, 2013 @ 14:33 IST)

A couple of years ago, I had written a C++ version of an AI playable Tic Tac Toe program. I have now written a similar version in Haskell, which uses the same kind of logic as the C++ one. I thought it would be kind of challenging to try a program like this in Haskell, but it turned out to be quite easy, as a matter of fact. I wrote this as a way to revisit Haskell while trying a non-trivial exercise.

I am sure there are better Tic Tac Toe programs/algorithms implemented in Haskell that illustrate more advanced techniques than the ones I have used, but still, I think mine would be a bit easier to understand for a newbie and is perfectly adequate for a simple game like this.

Simply the algorithm I used for the AI is this:

  1. Check for any winning move and make it.
  2. Check for opponent winning move and block it.
  3. Check if the center of the board is free and occupy it.
  4. Check if any one of the corners are free and occupy it.
  5. Occupy any other free cell.

That's about it. This makes the game unwinnable from a human player point of view (which is what most TicTacToe AIs implement). The best result that can be achieved is a draw. Pretty boring game, but still... In fact, the game can be won by the human player as pointed out in the comment by Jonathan below.

Read more...

Comments (2)  

A revival of interest in PC games

Filed under: Software and Technology by Hari
Posted on Sat, Aug 17, 2013 at 11:41 IST (last updated: Sat, Aug 17, 2013 @ 11:41 IST)

Of late, I've had a mild revival of interest in PC games. I've always been a fan of Real Time/Turn Based Strategy games, simulations and world-building games and to me, gameplay has always been the key, rather than graphical glitz or sound effects. Over the years, I've been a fan of games like Age of Mythology, Seven Kingdoms, Civilization, FreeCiv and so on. I've also had fun playing hardcore rail simulators like Microsoft Train Simulator, Auran Trainz and OpenBVE.

Now, a long time ago, I used to play a game called Transport Tycoon by Microprose. It was a fun, addictive transport network building game with the option of building several types of transportation networks  including land (road and rail) and air. The biggest fun was building a complex railway system and watching your miniature trains run flawlessly from point to point and make you a hefty profit. The challenge was to make sure your transport company stays afloat while servicing your bank loan, maintenance costs, infrastructure costs and so on.

And then, I recently discovered OpenTTD, an open source re-make of the old classic Transport Tycoon Delxue. Old fans of TT and TTD will find the screenshot below quite familiar.

OpenTTD

It has several enhancements over the orginal and provides for hours of fun and entertainment as you lay out tracks and roads and send you trains, buses and planes on their way.

It is addictive and fun. But be warned: it is a time sucker and it can make your family mad at you for spending hours in front of the computer! 

Comments (0)  

An alternative view on the whole keyboard layout business

Filed under: Software and Technology by Hari
Posted on Fri, Jul 26, 2013 at 21:46 IST (last updated: Wed, Jul 31, 2013 @ 14:23 IST)

As I have explained in my previous blog entry, I was recently playing around with alternative keyboard layouts for their perceived and scientific benefits over the good old fashioned qwerty layout. In fact, I have read quite a bit on the topic, including some scientific analysis on keyboard usage and finger reach/strain while touch typing on various layouts. In all the tests, the qwerty comes out as the worst layout and is universally decried as the most inefficient of them all. And I have no doubt that it is true; at one level.

Read more...

Comments (19)  

More keyboard tales: learning an alternative layout

Filed under: Software and Technology by Hari
Posted on Thu, Jul 25, 2013 at 08:59 IST (last updated: Thu, Jul 25, 2013 @ 09:00 IST)

As I type this I am using the Colemak layout and slowly discovering its advantages. It is quite similar to the qwerty layout but makes several changes to it that allow the user to type more comfortably and using the stronger fingers to type common letters in the English alphabet thus reducing strain and stress related injuries in the hands. 

For the purpose I am using the touch typing tutor gtypist on Linux.

It does take some getting used to, though, but apparently it is easier to transition to the Colemak than the dvorak layout from a qwerty background. Learning and training your fingers for the key positions on the home row is half the battle.

My biggest fear is losing my touch with qwerty after years of fast typing on that layout. All said and done, for all its stated disadvantages, qwerty remains the de-facto standard and used efficiently by a huge proportion of users worldwide.

So I am continuing to use the qwerty layout alongside. I have read conflicting and contradictory reports on whether one can easily retain muscle memery of one keyboard layout and continue to touch type on another efficiently. So I am approaching the whole thing with rather more caution than is advised.

Comments (0)  

Mechanical keyboards - rediscovering the joys of typing

Filed under: Software and Technology by Hari
Posted on Tue, Jul 16, 2013 at 17:19 IST (last updated: Tue, Jul 16, 2013 @ 17:19 IST)

Wow... after a long time, a proper article on this blog again! Actually this blog post is a result of my discovering the joys of typing on a mechanical keyboard.

Inspired by a few recent blog posts including one about the classic IBM Model M from my friend, Dion Moult, and also encouragement from my brother who is a fan of mechanical keyboards in general and the DAS keyboard in particular (being a full-time programmer who has to type 8-9 hours a day), I decided to make the switch to a mechanical keyboard. Unfortunately most mechanical keyboards are quite expensive and not available directly in India (the price tag in USD makes it more expensive in India with the current exchange rates and overseas shipping charges adds to the price). Luckily, there is one manufacturer of mechanical keyboards in India: TVS Electronics. The TVS-e Bharat Gold keyboard is relatively inexpensive and locally available. So it was my obvious choice. I went ahead and ordered it on e-bay and it arrived today.

It is a pure pleasure to type on this keyboard which uses Cherry MX Blue switches. The construction feels solid enough, and the clicky, springy feel is truly a joy after years of being used to bottoming out the keys on a membrane keyboard with little or no tactile feedback. I still press the keys a little too hard, but I am learning to reduce the pressure so as not to bottom out the keys. The added benefit of typing on a proper, full sized keyboard with separate Home, End, Page Up/Down keys and a numeric pad after so many years is a liberating experience.

A full review of this keyboard may be in order after some days of proper typing on this. In the meantime I might even goad myself to type a few more blog posts ;)

Comments (16)  

Concept portrait - Intellectual Uncle

Filed under: Artwork/Portraits/Caricatures by Hari
Posted on Thu, Jul 11, 2013 at 15:38 IST (last updated: Thu, Jul 11, 2013 @ 15:38 IST)

Intellectual Uncle

My conception of an "intellectual uncle". Drawn entirely from imagination with no references, on my HP Touchsmart tm2 with MyPaint.

Comments (2)