Board representation of Connect 4

Started by
3 comments, last by Jarod42 13 years, 3 months ago
Hello every one again.
I know there are many links for programing connect four in various languages, but even after I read them, I am having some problems in the board logic(standard 7x6 board (7 columns 6 rows)). Here are my doubts.
Many begineer programmers represent the 2d board as a array of 7x6, experienced programmer represent theirs as 9x8(border of one on each side) and one program, which plays very fast which could be fould here has a 1d array of [156] .(Bit board representation is too complex for me at this moment.) these experts claim that they dont have to do the explicit checks while move generation but I am not getting this.
I mean they have to use 'for loops' within the boundary to get legal moves. Can any one clear this point?

-Thank you.
Advertisement
It is useful to also keep an array indicating how high each column is. That way, you can generate the move at that column without having to search for the lowest empty space. I am not sure if that answers your question.

Also, I don't know why you wouldn't consider a bitboard representation: Bitboards work great for this game.
To check efficiently the rule, having extra column/row allows to avoid some tests on limit of the board
Counting consecutive pawns in one direction from one position will stop at extra column/row
else you have to check position against the limit of the board

Ps: 156 = 13 * 12 = (3 + _7_ + 3) * (3 +_ 6_ + 3)
@Alvaro: Thanks again for replying. Its not that I don't want to consider Bit boards , I have read about it and talking of some more games like chess , most of them were rewritten in bitboards as it offered speed for the move generations and evalautaion.(I read it while I was trying to learn more about AI and chess computing in some links of Crafty). But right now I am just a begineer in programing, so I thought that it might be a good idea to write simple connect 4 and then later on improve on specific parts like movegeneration or evaluation adding alpha-beta to negamax (Or try some different approach like negascout). I am learning C++ for the same. So that I get a bit of edge over Java program. I am also working on data-structures, so that I dont use somethings like Strings or some other stuffs which makes the program slower. Then once I am comfortable with this language,I can move on to advance programming techniques. So in short I think that I would confuse my self if I jump onto Bitboards as of this moment,but surely I want to learn programming in bit boards.
Can you advise me to learn few more things(I am just a newbie programmer).

@Jarod: Thanks for replying me.I have one more question, if it was question of checking the board limits, then why to assign borders of size 3 when 1 will suffice? or is there any other advantage of having borders of size 3?

why to assign borders of size 3 when 1 will suffice? or is there any other advantage of having borders of size 3?

If you want to "use" 4 cases directly (by adding/bit_and/bit_or them for example)
(1: player1, -1: player2 -> a total of 4 means player1 wins, -4 player2 wins.)
like this you can avoid some tests.

The extra column/row may have 2 main objectives:
- optimisation (less tests)
- more generic code (less of special cases with limit of the board, so less "hidden" bugs).

This topic is closed to new replies.

Advertisement