Download source code: palisaro_wall_demo.zip
Tutorial written by: vladimir_levin@yahoo.ca and edA-qa@disemia.com.
All source code written by edA-qa@disemia.com

Palisaro Tutorial: Surrounding Areas With Walls

Installation
This tutorial is based on the game Palisaro, written by edA-qa mort-ora-y. You can see more games at http://disemia.com/games/. First download the tutorial. The source code for the tutorial itself is in the WallDetect.hx file in the 'package/tutorial' subdirectory. The code is written in haXe, a language that can compile to the flash swf format. To run the code, simply type in the path to the WallDetect.swf file into your browser, e.g. file://c:/palisaro_wall_demo/package/WallDetect.swf. You can find this file in the 'package' directory of the tutorial. If you wish to make changes and play around with the source, you'll first have to install haXe. Once that's installed, to compile the source, open a command line prompt and type: haxe tutorial/WallDetect.hxml from the 'package' directory. This will regenerate the WallDetect.swf file.
The Basics
In this tutorial we will explore the algorithm and code that identifies when a player completes walls around previously open areas. What are walls and areas? In the game itself, the goal is to surround areas containing towers with walls within the time allowed. The larger one makes the surrounded areas the better, since that allows for placement of more canons. However, any unfinished walls are removed when the time is up so in the game there is a tradeoff between making the largest walls possible and finishing smaller walls more quickly. The interactive demo below has been simplied from the actual game. There are no towers. Instead when you surround an area of land with wall elements, the squares inside the surrounded area become partially filled with a different color. Green squares represent land and blue squares represent water. When you click on a land square, it will turn into a wall element. You can remove the wall element by clicking on the same square again. You can also turn a square into water by clicking on it while holding down the Ctrl key. The code in this tutorial highlights properly surrounded areas with different colors. There is a slight difference between the 4 seed and 8 seed modes. In 4 seed mode, walls don't need to have corners filled in to be considered complete. In 8 seed mode, corners have to be completed as well.

Interactive Demo (feel free to play around)