|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionHexomania is a strategy game that I've made and wanted to share with you. It contains a good AI for the computer play. I think this is a good example of what you can do with C#. It took 2 days for programming. How to playEvery player has a lot of pieces and some targets (circles) with the same color. The game is played in turns. Targets move randomly one step, every turn. You win if all his targets are imprisoned (can't move). You play by moving any of your pieces to an empty hex that is adjacent to another one of your pieces. Click a piece to move. Click an empty hex to put the piece. You can change the board size (and number of pieces and targets of course). You can change number of players. I Hope you enjoy the Game. The game classes consists of
The Computer AIThe AI is simple enough. It consists of the function The For the computer to play its turn, it searches for the piece that can be removed producing the minimum cost. Then searches for the best position to put that piece in, based on (again) the minimum cost produced. The search is done on all the available pieces to remove, then on all the free spaces that are adjacent to another pieces, to select a place to put on. How to save a hex grid in an arrayIt is done by a normal 2 dimensional array. But the y positions are spaced by a half grid below, every Xindex mod 2 = 1, to create the hex shape. The next shape shows how we calculate the x,y index of the array:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||