Hello fellow coders,
I am currently taking a C++ class and have a final project due very soon. We are recreating the game Othello/Reversi using the console.

So far I haven't run into really any problems and it hasn't been too bad. I have almost all of it complete except for checking the diagonals for valid pieces to flip/capture.

I have it down to check rows and columns (North, South, East, West) perfectly, but I just can't seem to figure out how to get the diagonals to work. I tried using two for-loops (one nested) to check up one "square" and right one square for example to the North East. However, it checks one square to the north and then all of the squares to the east/right before going one more to the north again. (Since the east for-loop is nested it executes completely)

So basically, I need a little guidance on what to do to check diagonals. Pseudocode is perfectly fine with me as long as I understand what you're saying. :P

I have an 8x8 board that is stored in the array board[row][col].

Anyone have any ideas?

Thanks!

Recommended Answers

All 2 Replies

First I recommend making your board two rows bigger and two columns wider so you will not change your code when you are at the border. You must 'mark' the boxes that are out of the bord with some special value.
Then, if you are at the position r,c, for example, the diagonals will be at positions r+1,c+1, r+1,c-1, r-1,c+1 and r-1,c-1.
I don't know if this answer your question or I am not undertanding you.

That actually would help me, however, I just managed to work it out myself a few minutes ago.

Thanks for the attempted help though! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.