Sunday, October 19, 2008

Step 1 - The Minesweeper Algorithm

This algorithm is written in a quite high language and is meant to be a basis for the program itself.

The principle of minesweeper is as follows:
You are in front of a table of invisible content. Each field contains either a mine or no mine. If the user clicks on a field and it contains a mine, the game is over. if he clicks on an empty field, it reveals a number that states how many mines all the adjacent fields contain. If there are no mines around, all adjacent fields are automatically revolved. Hidden fields, which are supposed to contain a mine can be marked with a flag.



member variables:
mine count (how many mines are in the field)
queue (a stack of fields, which are to revolve one after the other)
minefield array (2d)
flag array (2d)

beginning, length, height and mine count given:
-make mine count accessible from anywhere inside the minesweeper class
-create a 2 dimensional array with the given length and height
-throw an event indicating the empty minefield is complete by now




M:revolve field, x and y given:
<-condition: If it is the first revolving{
->method: fill array randomly with (mine count) amount of mines, ignoring field x,y
-throw an event indication the minefield is filled by now
}
<-condition: if the field x,y is a mine{
-throw an event indicating field x, y has the value 9
-return the value 9
} else {
->method: get adjacent mine count
<-condition: if the adjacent mine count is larger than 0{
-throw an event indicating field x, y has the value (adjacent mine count)
-return the value (adjacent mine count)
} else {
-throw an event indicating field x, y has the value 0
->method: get the array of adjacent fields for field (x, y)
->method: add necessary items to the queue for (adjacent array)
->method: revolve next queue item
-return the value 0
}
}

M:get adjacent mine count, x and y given:
-remember a number
()loop: from x - 1 to x + 1{
()loop: from y- 1 to y + 1{
<-condition: if the x-loop is NOT at -1
AND if the y-loop is not at -1
AND if the x-loop is not at the length of the x-array
AND if the y-loop is not at the length of the y-array{
<-condition: if the x-loop is NOT 0 OR the y-loop is NOT 0{
<-condition: if the field is a mine{
-add 1 to the remembered number
}
}
}
}
}
-return the remembered number
M:get adjacent flag count
the same as above, just with the flag array

M:revolve next queue item
<-condition: if the queue is not empty{
-remember the item
-remove the item from the queue
->method: revolve field (x of item, y of item)
}

M:add necessary items to the queue, adjacent array given
()loop: for each item in the adjacent array{
<-condition: if the item is not yet in the queue
AND if the item is not revolved yet
AND if the item is not marked{
-add the item to the queue
}
}





M:mark item, x and y given:
<-condition: if the item is not revolved{
-swap the boolean value of the flag array at x, y
}
-return the boolean value of the field

M:fill array randomly, mine count, x and y given
-remember the amount of added mines.
()loop: as long as the added mines are less than the mine count{
-create a random number of the x position, maximum is the length of the x array of the minefield array
-create a random number of the y position, maximum is the length of the y array of the minefield array
<- condition: if the field at the random numbers contains NO mine{
-turn the random field into a mine
-add 1 to the amount of added mines in mind
}
}
-return the value 0

M:get the array of adjacent fields, x and y given
-remember a stack of fields
()loop: from x - 1 to x + 1{
()loop: from y- 1 to y + 1{
<-condition: if the x-loop is NOT at -1
AND if the y-loop is not at -1
AND if the x-loop is not at the length of the x-array
AND if the y-loop is not at the length of the y-array{
<-condition: if the x-loop is NOT 0 OR the y-loop is NOT 0{
-add the field to the stack of remembered fields
}
}
}
}
-return the stack of remembered fields

M:revolve adjacent fields, x and y given
->method: get adjacent flag count (x, y)
->method: get adjacent mine count(x, y)
<-condition: if the adjacent flag amount = the adjacent mine count{
->method: get the array of adjacent fields for field (x, y)
->method: add necessary items to the queue for (adjacent array)
->method: revolve next queue item
return the value 0
}
return the value 1

The first real project . . .

After all the little learning tasks from the tutorials, that can't really be called a project, I have now decided to begin my first real program in C++. It's gonna be a little game and I don't want to create something from scratch. This is rather meant to be an extended practice.

The requirements for this project are:
- It has to be a nice little game, with a relatively simple algorithm.
- The game engine itself has to be an encapsulated API, that serves the outer world with all the necessary information and methods do display and control the game. In this way, the game can easily be ported from one engine to another.
- It should serve a C++ graphics engine to provide a graphical user interface!

After some consideration, I decided to develop

Minesweeper++

Minesweeper is a quite easy game and I already had lots of fun with playing it. I'm gonna keep in in the fuX-Style (fuX is my one-man-company), but the graphical style is something for later on.

Much more important is, how I'm gonna do it step by step. I planned it in the following way:

1. Write the algorithm in a very high language. This is important to me, because I want the whole program logic to be clear, when I start to code, as I'm not really comfortable with C++ at the moment. So I don't want to add logical problems to the language problems, of which I surely will have plenty.

2. Write the game class in C++.

3. Prepare the images for the GUI.

4. Choose a graphics engine.

5. Build the GUI in the graphics engine and link it to the game engine. (alpha)

6. Polish.(beta)

7. Port the game for OSX and Windows and load it up here. (final)


So, let's go for it! =)

Thursday, October 16, 2008

Learning the basics of C++

My first step was learning the theoretical basics of C++. What do I have to do to get my first application running? How does the syntax look like? What do I already know and what is new?

Since I'm using a Mac and I am used to work in Eclipse (Java Development, Flex, Aptana), I searched for a possibility to use the Eclipse IDE for C++ as well. Luckily, it is already offered at the Eclipse start page, the Eclipse for C++ Developers Plugin. I quickly installed it and found out, that I do not even have to install a compiler, because my MacBook Pro brings everything I need.

So, how to get closer to the basic rules of C++? There are a lot of tutorials on the internet, and I don't want to say, that they aren't good, but I found a book at amazon.de called "C++ für Spieleprogrammierer" from Heiko Kalista. (Means "C++ for game developers"). So, I decided to do it in the old fashioned way and to learn from this book, as it seems to be made exactly for my purposes and the user reviews were all very cheerful.

I worked through the most parts of it in about 2 weeks, whereas this is not 2 weeks 24/7, but an hour or two after work, every second day. Something like that. I can agree to the user ratings, it makes the introduction very easy, especially, when you already bring some programming experience. Okay, if you don't speak german, it will be quite useless to you, but there will surely be other solutions ;). I worked through the syntax basics in about 3 days (It's all quite familiar from Java and Actionscript 3) and am now quite familiar with classes, pointers and addresses. I'm not totally comfortable with everything, but that's simply because the experience is missing. I think now is the time to think of the realization of a really small game, with a nice, logical API that serves a graphic engine to generate the front end.

Without this basic knowledge, I think it is senseless to think about starting to develop a game and/or think about an engine to develop it with. My next thought were some game concepts and the intensive search for the right game engine. To be continued...

Monday, October 13, 2008

Hello World

The first words, programmer speaks in a new language are the same words, that will introduce my blog: Hello World!

Since I was very young (I think I had a C64 at that time), I dreamt of creating my own computer games. Over the years, I've been able to gather a quite strong background in the design and development of computer software. I studies Character Modeling and Animation, alongside with Creative Media and Technologies and finished my studies with a Bsc. title.

My main focus was the development of web software so far, so my fortes are Actionscript (Version 3 preferred), Java, Javscript and Prototype, which I'm doing a lot at work at the moment.

But since almost every job in the game development business demands for proficiency in C++, I finally decided to learn everything I have to know about C++ and stack up my portfolio with some serious games.

I'm not completely new to the development of games. Besides some very old, forgotten Basic games and some small flash games, I've created a neat little 3D pet simulation game called fuXcats during my studies. For this game, I was forced by the University to use 3D Gamestudio A6. Basically, it was quite okay, because a lot of functionality came with the game engine, but I couldn't get the necessary C++ experience. If I succeed to export it to binary some day, I will post it here as well.



So much about my background. In the next posts, I will talk about what I already learned about C++ and what I'm planning to do next.

Cheers,
Felix