3
votes

I am implementing Othello game in Prolog. The game board is represented as list of lists.

I am facing a problem with flipping pieces after making a move.

My strategy is to look in all 8 directions from position where I placed my piece (say black),

and find the enclosing black piece and flip every white piece between my pieces.

So, I have 8 separate predicates to do that.

The problem is I call them sequentially after I make a move, and if any one of these predicates fails, the whole thing fails.

Is there any way to get around this? Or maybe my approach is wrong?

2
Can't you make your 8 direction predicates never fail?Carl Norum

2 Answers

0
votes

Maybe you should try to OR the predicates?

I know I wrote this for a CS class when studying at uni, I hope your not using stackoverflow to cheat on your assignments... ;)

0
votes

As suggested by Cari Norum I just make my predicates never fail. So if one fails, I just make it return the current board state. That seems to work.