Link to home
Start Free TrialLog in
Avatar of KyleG
KyleG

asked on

Othello move validation

Hey everyone,
I'm trying to make an othello (reversi) game in c++. For the moment I'm making it for two human players, but eventually it will have a computer player. It runs in DOS, and right now I have it being played on a 6 by 6 board, which is represented in a 2d array. I've been tryin to figure out how to validate and complete a player's move. That is, I need to be able to make sure that their move is valid, place their piece, then flip over the other appropriate pieces (you need to know thw rules of othello to understand this part). I came very close to succeding, but there are a few flaws which I cannot fix, so I've decided to start over. Any and all help is appreciated, including links to websites.

Thanks alot,
Kyle
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ah sorry, in the if statement in main, they should all be
!function() &&

(IE you return 0, you want it to evaluate true.  If it is > 1, it will evaluate true while it's a valid move so you want to make sure it evaluates false.)
Avatar of KyleG
KyleG

ASKER

Thanks alot, that really makes alot more sense to me now. Just one more thing, I'm pretty sure that it will work, but I'd like your opinion on it first: I could set up 8 (one for each direction) if statements to handle flipping the other pieces (older ones) on the main function, right? What I mean is, if, for example, searchrup() returns a value greater than 0, I would then call a similar function which flips the pieces along the path that it just searched. This all makes sense in my head, I hope it does in yours :)

Thanks alot,
Kyle
Avatar of KyleG

ASKER

One more thing. I know how to fix it, but I thought I'd point it out for clarity's sake, just incase you hadn't realised it. I hope I don't seem like a jackass pointing out your mistakes! Your code didn't check to see if, while following a certain path, it encountered an empty square. Obviously, if the program just went until it hit a another of the current player's pieces, I could possibly fill in previously blank squares.

Kyle
LOL, that's why we have the website, to point out each other's mistakes.  You are correct.  At first I was pseudo-coding it, then I just jumped into the code and started writing and did it on the fly.  So in terms of not checking for blanks, yes, you are correct.  (Easily taken care of by adding another conditional to the while loop:
(x > 0; y > 0; !space_is_empty());

and yeah, you could have 8 if statements for flipping purposes; in fact you can have all if statements in side a big if statement if you really wanted to get into it.  (I don't recommend it, it's not pretty, not really good programming, and confusing if you ever went back to it or wanted to show anyone)  

But incase you wanted to make it over difficult

you could call

if (flip(searchrup() && flip(searchldown() . . .)

inside flip your first statement would be

int flip(int numsquares,int direction)
 if (numsquares == 0)
  return 0;
 else
  switch(direction)
   case 0:{do your flipping; break}
   
 return 1;

The direction would be a number by you to know which way to flip, just correspond it to whatever you send, or you can enum it.

Hope that makes sense.  If this works to your satisfaction please accept answer and grade to close the question, or keep firing away at the questions and I'll knock em down as best I can. :-D  Enjoy.


Avatar of KyleG

ASKER

Alright, thanks alot, you've answered all of my questions, and without makin them overly complicated answers! There aren't many people that I know that make things simple the way you did, so thanks alot! Here are your points, enjoy them :)

Kyle