C++ reversi

Hello everyone,

This is my first post in this website and I hope its as good as I heard :).

Anyhow, I am sort of new to C++ but I have been learning it quite well and picking it up fast.

They have asked us in uni to write a C++ reversi game, I got everything they asked us for on spot, the only thing I cant figure out is how to reverse the opponents pieces once a valid move is made.
for Example: if a player makes this move XOOX I want it to change to XXXX.

I know I have to code something that checks in the surrounding squares for a matching piece and then change all the pieces in between, but I cant figure out how to code it.

I dont want to share the code I have in the web just to not get caught in any plagiarism issues.

I hope you understand what I mean and help me.

Thanks in advance
From what you have written, I don't think you could have plagiarism issues.
However, you don't have to post the entire program, but only a piece of code that doesn't work, otherwise I think nobody would help you.
Well everything I wrote so far i correct.. What i need help with is what I cant figure out how to write.
So, plagiarism issues for what, if you can't figure out how to write?
At least, write in pseudo-code, maybe someone will translate it to C++.
are u in malaysia ?
that is odd but yes I am in malaysia.
I think this is not so complicated.
The game is played on a 8×8 square playground.
For this you can use a simple array. For example an int array will be good, because you can simply indicate the puppets of the players with 0 and 1.
The checking can be done with more for loops. Maybe with three, one for the pattern lenght (how many same puppets in a line) and other two to loop through the array.

Other solution is to write a list previously how a pattern can be formed.
For example:

1
2
3
4
5
6
7
8
########
########
########
###0111#
###10###
########
########
######## 

[4][5],[4][6],[4][7] is a possible pattern.
You can store theese indices and only check theese every time.
Simplier than with loops although it claims more work.

You don't have to copy the source from somewhere, I think you can write it yourself. With it you will study a lot. :)
Last edited on
Start by thinking about checking in one direction. For example, if r and c are the row and column that was just flipped then you could look diagonally with something like this:
1
2
3
4
5
int i,j;
for (i=r+1, j=c+1;
     i < boardWidth && j<boardWidth && board[i][j] != board[r][c]; ++i, ++j) {
    board[i[][j] = board[r][c]; // flip it
}


Now you could write similar code to check in each of the 7 other directions but that sounds like a lot of repeated code and "repeated code" is usually an opportunity for a function. In this case, the thing that changes each time (the parameters) are the position of the move and the direction that you want to check. The direction really boils down to "what should you add to the row and column numbers" to get to the next square to check. In my example you add 1 to i and j.
Last edited on
Topic archived. No new replies allowed.