Minesweeper holidays

Dec 29, 2016

I’ve created a small minesweeper game in Angular 2 to refresh my Typescript in the holidays. I decided to give the Angular-CLI a spin, and check the current state of Angular Material 2.

I also wanted to try some game AI technigues, so the game and the AI is inspired by a chapter in Introduction to Game AI. The original project in the book is implemented in Visual Basic, and with quite a different aesthetic.

The rules based AI in action. Notice the sidebar text is a little cramped.

The AI

The AI is a rules based AI. Every iteration, every possible rules efficiency is evaluated, and the one yielding the highest score wins. For example, the “mark fields as bombs”-rule has a score equal to the number of fields we are 100% sure are bombs at the current state of the board.

The AI picks the rule with the highest score at every iteration. This usually results in it either marking a set of fields as bombs, or exposing a set of fields that it knows are safe.

I choose not to make the AI “guess” when there are no more fields so safely mark or expose (it happens in minesweeper), as I do not want to take away the thrill of failing away from the user.

Take it for a spin

You can try the minesweeper game here on this site. It’s published using github pages, which is easy to do using the angular cli (just run ng github-pages:deploy, and you are golden).