Sunday, December 27, 2009

Solved!

I solved it!!! Before asking for help I decided to work on it a bit myself. I slightly changed the system, so that dead pieces instead of being assigned no field, get assigned a special field  for dead pieces. I really still don't see a reason why the previous solution would not work, but since everything is fine now I'm simply going to stop worrying about it :)

Problems solved, come back twice as bad.... :/

I've been working a lot today again. I have added the limit of not being able to go backwards, I added kings (crowned pieces, those can move back and I've allowed them to). I also solved the problem of not being able to beat. I even played a match with my cousin, although the game is NOT finished, so we had to remember the rules ourselves - the program does not have all the functions needed just yet.

Unfortunately, the breaking mechanism somehow broke. I found out EXACTLY which line of code makes it break, but I have NO idea why it does so and how to fix it. The weird part is that I  have not changed this mechanism between it working and it breaking. I have added other things, but this part was not changed. I'll probably have to ask for help with this one, because I really don't know what is wrong with this.

Wednesday, December 23, 2009

The Pieces are Moving!

A few more hours of work and I arrive at the stage where I can move the pieces. Unfortunately not correctly ;) For some reason white pieces move where i direct them, but when i mark a black one, a white one moves instead. I need to experiment with the code to see what is wrong there and hopefully i will be able to move the pieces the way they are supposed to even today.


UPDATE [15:50]
I found the mistake! What's interesting is that the new bits were (in most part) correct and it wasn't these that caused the problem. Once I went through them over and over and was sure that they are correct, I started looking back and found the mistake in the set up of the board. It was just a wrong list given in one spot that didn't influence anything until this spot.


UPDATE [18:55]
I kept improving the code and right now all the pieces move well - only diagonally by 1.
However some of the things which I have implemented don't work yet - the pieces don't beat yet and I have to see what is wrong there.
Lastly there are some things which I simply didn't put into the game - for example the pieces move backwards as well as forwards at the moment.


I think I am well on at least 30% with the game. The following is a quick list of what I still have to add (not strictly ordered):

  • Beating Pieces and further movement restrictions (as above),
  • Kings,
  • algorithms for the program to make sure the game is run properly (so the program can "see" if there is a piece that can be beat etc.)
  • the order of the game - start and finish, checking if ended (won), turn system.

Monday, December 21, 2009

Keep on working

The problem I mentioned at the end of the last post I've already found a solution to - I had to JUST NAME the dependent class before describing the one depending on it.


Yesterday and today I kept working on the code. I realized that I get so much fun from the challange. Every problem I solve leads me to a next one. But only sometimes I feel frustrated - that's when I have no idea what is wrong. But when they are all a series of problems that I keep moving through (that doesn't mean that they're easy!!) then it all really does bring me joy (especially once I solve something particularly difficult ;) ).


Already yesterday I've started setting up the pieces on the board. It made me realize a problem which you might have noticed on the previous blog if you look at it carefully, but it was in fact very easy to overlook. The board I had was 7x7! I've digged through pretty much the entire code that I've wrote by now and finally realized my mistake. C++ in many cases counts from 0, not from 1. It is a rule I've remembered to watch out for, however once I got too mixed up when also using variables that I've subtracted 1 from them ending up with what I did. It can be thought of as if the board was moved up and left by one square so 1 column and 1 row got hidden behind the window border. I've fixed that by now as well as many other obstacles I met these two days and I have the board set up!







Now I will search for a solution to another problem - the pieces flick as if the program kept redrawing the board, than the pieces over it then the board again and so on.




UPDATE - found out the problem, it came from the fact that I am building the program slightly differently than I saw and practiced before. I needed a good description of a Windows message WM_PAINT and I found it easily on MSDN as well as more functions which let me solve the problem.


So now this stage is completely done and I can move on to the interaction stage - adding the implementation of functions that will let me move the pieces. Then algorithms that will serve as rules.

Sunday, December 20, 2009

Code work kicked off!




Today I’ve spent 3 hours coding. I’ve come across a BUNCH of different problems, but most of them I was able to solve after sometime. A lot of these problems were simply syntax or ‘layout’ – I would not be sure how to put some stuff together for it to make sense etc. Part of it are also small pieces of information that are not important until one tries to use them. E.g. I had to change a constructor of Field because it had to be empty for me to be able to put it into the array of Board. It is just a requirement of the language because one excludes the other. This problem and many other I had to look up and the C++ dla każdego book was indispensible here, especially that I was working in the car, without internet.


I was heavily using the tutorial to code the window creating code. A lot of it was pretty much copied, with just slight changes, because this part of the code does not differ from program to program much and it is also quite lengthy, so it takes a lot of time to be able to remember and write it all without reference.


Once I’ve finished the making of the window, I created a function which would display the board in it. It was going step by step – I had to implement the Field function; then create an abstract board as an array of Fields; then write the code which would go through the array and display the fields one by one (I could have made this easier and shorter, but this lengthy approach takes off some load from future – I would have to do it sometime anyways). Only once I had that ready and tested I made the colors alternate making it a real checkers board.


This concept is really important for me right now. I can’t make everything right away at the same time. So being able to separate the process into some steps which are than developed is the way to go. It is quite a challenge, because the different parts of the code are inter-related and intertwined which makes it hard to take only a part  without having to drag the rest with it.


For example, I’ve had to create the Field class to be able to create the board. But my main focus of the moment was to create the board not the fields in their full detail, so I only wrote the most important parts of the Field class that allowed it to function. As I was expanding the program I was adding more and more functionality to Field AS I NEEDED IT.


The process I showed last post is only somewhat correct. The basic idea is correct, but all the steps are really blended together and really only the first one was the only one I did by itself. Later all the steps are too much connected for me to keep the rigidity of a step-by-step plan – it is much more dynamic than that.


Right now I am stuck on one quite big problem - I want to create the two classes of Field and Piece which both point to one another. The problem is that the second function in the code can recognize the function that comes before it. However  the one that is first can not point to the one that comes afterwards because at that point the compiler doesn't know that it exists.

Thursday, December 17, 2009

In my initial start of the program I started with writing the classes of the object. I thought it would be a natural step to create the building blocks of the program first and then connect them and use them to make the actual game. However I have now realized that this way I can't test things as I write them, because I can only run a program, not a part of it. I decided I need a different approach. I have changed it especially because of not much experience with programming, in terms of not actual amount of code I wrote in the past and the time that has passed since my last bigger programing project. Another thing is that I never used some of the components and functions before.

The actual change was that I will start with the frame of the program - the Windows' protocalls which actaully create the program in Windows' "memory". This way I will be able to run the program at early stages of development to test the components as I add them. Another advantage is that the Windows' functions are mostly the same for all programs, so they are not really the hard part of the coding.

So the coding in terms of time will look somewhat like this (latter parts might change):
  1. Windows "frame"
  2. Basic graphics (The board)
  3. Classes (pieces, fields)
  4. Movement graphics
  5. Structure of the game
  6. Final improvements, fixes, etc.
 This process could be compared to making a jig-saw puzzle. It is the easiest to start with the boarder for two reasons. One, you can work from outside to inside, having everyting much more organized and in relation to each other. Two, the larger components are easier to check against the boarder if its ready.

Thursday, December 10, 2009

December update

Unfortunately due to a sickness right after the 3 week long school clousre I've fallen behind with some school work and had to catch up on that, so my PP has been pushed out of the way by some more urgent matters.

Now I  have 1.5 month to finsh the game. I believe I can finish the game in this time, although with quite a big effort. I will use the winter break to its full extent for this. However, even if it so happens that I do not manage to create the full game, it should not hurt my PP, because my goal is to learn from the creation, not to create. I will finish the game anyways, weather it will be within PP or already afterwards.

I figured that when I have a problem with my code, it would be a great help to have someone I can actaully physically come up and talk to - online tutorials and such are good, but when there's a specific problem this kind of help would be much much better. I have contacted an IT teacher, Mr. Vitaly, who has some experience with C++ and making games. He is happy to help me if find any obstacles that I don't know how to tackle.