Showing posts with label Hex. Show all posts
Showing posts with label Hex. Show all posts

Monday, December 31, 2007

One of Those Boring Retrospective Articles

I hate TV at this time of year, when all the stories on the news shows are "let's take a look at what happened throughout the year". I was there, I did see it, and I KNOW you're only showing it because it's cheap television. Stop wasting my time. I will now demonstrate the height of hypocrisy by doing the same thing myself.

Game of the Year

With 59 plays, more than the next four contenders combined, my Game of the Year has to be Scrabble. I enjoy it a lot, and I can play on-line which means my opponents and I don't need to synchronise in time and location. Given that one of my most regular opponents lives in Beijing, that's just as well. I enjoy Scrabble a lot, and now that I know the 2 letter words hope to play a little bit more seriously in 2008.

Highlight of the Year

The gaming highlight of the year has to have been Scrabblette finding the "Connection Games" book for me. It led to an obsession that has had a massive impact on the games I buy and play. It sure would be handy if I had an opponent with a similar obsession, but the mathematical aspects of these games have kept me amused for hours. Not to mention implementing Hex for Facebook.

Best New Game of the Year

I've probably played only about a dozen games published in 2007, so I'm choosing from a small pool here, but the best of them so far is definitely Unspeakable Words. It's nothing deep, but it's easy to teach and fun to play and does reward skill.

Happily Unplayed Games of the Year

At the end of last year I realised there were a few games I was completely over - Ra, Geschenkt and Poison, for starters. I wanted to avoid playing them for a while. Given that I didn't play them at all in 2007, I guess I succeeded. Their banishment is over now, and while I still won't be rushing to play them I may not avoid them as assiduously.

Sadly Unplayed Games of the Year

I know it's a long time since Ozvortex came over for a game of C&C Ancients, but I didn't realise it had been a whole year. I guess a lot of 2007 was occupied by moving house. I also didn't play GIPF, DVONN or PUNCT, which doesn't seem right.

Ambitions

Apart from my ambitions with regards to managing my collection as described in an earlier post, these are the things I want to achieve in 2008:
  • Find more opponents for 2 player abstracts so I can start playing the again.
  • Play more of my capital games, e.g. St Petersburg, Tigris & Euphrates, Domaine.
That is all. See you next year.

Sunday, December 23, 2007

A Labour of Love

No, this is not another post about Kevin Rudd. This is a post about Facebook.

A few months ago Aldie asked for testers for his Facebook board game app. Of course I joined Facebook to see what the story was. I found a few people that I know there, so I hung around for a couple of days adding friends. Somehow I started playing Scrabulous, and that was when I realised what a great site this really was. I was playing Scrabble against people I didn't see very often (because they lived in London, for example) and with people who never had the time for a proper game (even though they lived in the same house, for example). I' ve played 47 games of Scrabulous so far.

So I realised Facebook was a great site for playing games against friends you just can't get to in real life. And other games, as well as Scrabble. I decided to write my own. To avoid copyright issues, I decided to write Hex.

Of course, I had no idea how to. I didn't know whether Aldie had written his app in MSVC or Java or Flash or what, and I had no idea how it got deployed on Facebook. But that was the fun part. I was pretty sure that I could program it, whatever it was. Besides, I wanted to know about this Web 2.0 thing Yehuda was into.

I did some research and found out that Facebook apps are very clever indeed. You write your application as a web service and Facebook delegates requests to your app on Facebook through to your web server. So you can write your app in whatever you like and you host it on your own machine, so Facebook doesn't care about your database maintenance or CPU or anything. It just cares that your app responds to requests. I had used Apache in the past, so I installed it on my home machine. I also wanted to write my application in Python because Java bores me sometimes, so I installed mod_python (lets you write Apache services in Python) as well. I already had Linux and MySQL running, so I'd finally got myself a complete LAMP stack.

I couldn't even get the test example going! I did everything it told me to do and it just didn't work! It was very frustrating! It turned out I was running Apache 1.3 and reading the Apache 2 documentation. You can see at this stage that I didn't know much about what I was doing.

Then there was the Facebook API. It talked all about authentication (yawn) and making requests to the Facebook server. I really struggled with how that was relevant to me. I googled and found something called minifb.py which was Python code for doing Facebook stuff. All of the Facebook doco refers to PHP which I don't speak. minifb did more authentication stuff, and I still didn't get it. Eventually by following examples I figured out what I was supposed to do, and I loaded a Facebook page which made a request to my web server. A small victory, at last.

I've glossed over a few things here. Firstly, my ISP gives me a dynamic IP address, so whenever that changed I'd have to go to Facebook and reconfigure my app to point to the new address. A mate at work told me about dyndns.org which provides DNS services for exactly my situation, and I figured out that my router supports it. So now whenever the router is restarted it connects to dyndns.org and tells it that friendless.servegame.org is at this new IP address now. It's very cool. I also had to deal with the network security - our router was configured to not allow any requests from the outside to come into our home network. I had to tell it to route requests for the HTTP service through to my desktop. Not that hard to do, but tricky to realise that you have to do it.

OK, so we were at the "one request got through once" stage. Nothing got any easier. Facebook uses HTML, but it extends it with FBML (Facebook Markup Language) which implements all of the cool widgets that you use to invite friends to do stupid stuff. So I needed to learn a little about that. I also needed to figure out how I was going to implement the user interface. JavaScript looked pretty handy, so I learned that as well.

JavaScript really is pretty cool. You can do all sorts of programming on the client side, and with AJAX you can even make calls back to the server from within the web page. Without worrying about the Facebook thing, I coded up some JavaScript to render the board in the web page, figure out which cell the user clicked on, then make an AJAX RPC back to the server to make the move. It took a while, but it was sweet. After I got it going I hooked it into the Facebook code, and Facebook said "JavaScript not allowed". They're afraid you'll hack around with there HTML and corrupt the site experience.

Well that was a wasted week! It was fun, but ultimately got me no closer to having a working game. I experimented with many solutions. I knew that Scrabulous used Flash, but Flash is not free and I wasn't particularly motivated to learn it, so I couldn't copy from them. My goal was to do as much work as possible in the client, but as JavaScript wasn't allowed I couldn't see how to do much at all. I probably could have written a Java applet (I mean, I know I could do it, I just don't know whether Facebook would allow it), but even I understand that users don't want to install Java.

This was all complicated by the fact that I couldn't get Facebook to display my images. In fact, I still can't. Any image included in my app has to come direct from my web server - if it goes through Facebook its gets interpreted as text. Yes I'm setting the content type. I still don't understand that one. I have another app in progress using the Django framework and it does the same thing. So I had to solve the client technology problem and the image serving problem at the same time.

The solution I eventually came up with was to generate the board image on the server side, serve it direct from my own machine, into a HTML form, so when the user clicked on a cell it would send me back the (x,y) coordinates of the click. I could then convert that back to a cell on the server side. Nothing at all happens on the client, but at least it seems to work.


I got the game basically working. The code about detecting wins and so on was EASY compared to all of the technology nonsense. The game requires two real players so there's no AI involved. However them I needed to add some of the bells and whistles, for example, notification to your opponent that you've started a game.

That was when the authentication tarrasque bit me. You see, Facebook has this completely sensible system where your page is treated as a form with lots of hidden fields. Some of those fields, e.g. user id, Facebook session id, and so on, come from Facebook and tell you Facebook stuff. Those fields are digitally signed and you use your application secret to check they're kosher. EXCEPT, if you have a form on your page like I do, it sends some of that stuff twice, and digitally signs it twice. So you have to figure out what is authenticated by what signature. I ended up changing minifb to deal with it, because of course I was the first person to use minifb to receive a form submission and nobody else cared that it didn't work.

So after I figured out authentication I was able to get the session key which allowed me to send notifications to the server. At the moment I send a notification only when a game is started, as if your application sends too many notifications in one day your application gets classified as spam. Given the spamminess of many Facebook applications, the fact that they monitor that is a good thing.

Anyway, it's all sort-of working. I need some users to try it out.

http://apps.facebook.com/hexgame/

Please.

Thursday, May 03, 2007

Thoughts on Hex and Y

Scrabblette and I played a few games of Hex and Y last night. This was Scrabblette's first time playing and she didn't really get the strategy. (BTW, she subsequently beat me at Bridg-It, but this post is not about that.) After the game (and for a while when I would have preferred to be asleep) I was thinking about strategy for connection games on the hex grid. This post IS about that.

The basic tactic I understand involves the colours on the board above. If I've claimed two "adjacent" red hexes (or yellow, or white) and my opponent has not played on any of the spaces between them, I have an unbreakable connection between them. Hence for several games last night I was playing almost solely on the (let's say) red hexes until Scrabblette realised she'd lost.

Now where we're up to in our understanding of strategy is that the game is won or lost according to who claims the best chain of red hexes. But it occurs to me that the red hexes themselves form a hex grid, and you can make connections on that grid by claiming the blue hexes in this diagram:

And of course the blue hexes form a hex grid... and so on until we can identify exactly the most important hex that the opponent must claim in response to a move - the most important move at the highest level of abstraction. I know, I'm losing people here. Consider this colouring:

Say I'm trying to make a chain from top-left to bottom-right and I make my first move at A. (We're not using a pie rule here, we're not smart enough.) I'd love to make my next move at B, C or D so you should play there instead to prevent me. In fact if you let me play at A, B and D I believe the game is lost for you. So you play at C, I play at D and you play at B. It looks like if I play at B1 you'll have a really hard time getting through. Hmm... what happens next? I haven't figured that out yet.

Saturday, April 14, 2007

Unlur

Yep, I have no life. Here's an Unlur board:

The kid and I went to visit Sister and BIL this evening and played some of the games I've been making the boards for. Sister put up a very good fight at Bridg-It but caved in when the pressure was on. BIL played like a 9 year old girl in a rugby league match.

Then we moved to Hex where I thrashed both of them. Then in a game which still confuses me, BIL managed to beat me. I think it was a case of "LOOK! A Monkey!" I definitely thought I was safely connected to the edge when I wasn't. Hmm... so to prove it was a fluke I thrashed him again.

I found that I was much less confident playing Bridg-It, because although someone must win it wasn't clear how that was going to happen. It's the sort of game where you must not make a useless move, because if you do your alert opponent will gain a winning advantage. In Hex I look forward to learning what you're supposed to do when your opponent knows what they're doing. BIL will become good at it if I make him practise.

We also played Achi, which turned out to be disappointing. Many of the moves were forced, and often you could tell that you were forced to lose the game. It's right down there with Tic Tac Toe except that I don't know the winning strategy.

By the way, Bridg-It and Hex both strongly favour the person playing first. I think in all of our games the person playing second won.

Octagons

Octagons (no BGG entry that I know of) is a similar game to Hex where the players Black and White are trying to connect their sides of the board. On your move you may claim a half-octagon or two small squares. The first player to connect their two sides wins.


Note that with many of these connection games there's a strong first player advantage (if the first player is smart enough). The usual solution is for someone to make the first move then the other player chooses whose move that was. This encourages the smart enough move maker to make a move which is not too strong as the first move.

Friday, April 13, 2007

Alcohol + Python Interpreter = ????

It's Friday night here and Scrabblette is STILL away... what's a man to do but have a drink? And if that man is an abstract game fan? And has an unfettered Python interpreter at his fingertips? Well...


You see when I discover a new abstract game I think "that would be so easy to make if only I had the board...". And so often the board is something so simple you could code up an image for it even if you were drunk...


So, what games have I done? Well, more than I can be bothered uploading here. It's a program... it can do heaps of stuff without much modification.


So I'm only uploading a selection of things that seem useful. The achi board is for a game I added to BGG recently called Achi - search the web for the rules. The 10x10 board is for Amazons (or International Draughts). The GIPF board is for Gute Nachbarn (or GIPF). The hexagon board is for Hex. The 7x7 board is for the original version of Breakthrough.


If there are other boards I could make a game board for, please let me know. I'll need a project for when I attack the rest of the bottle of red wine :-).