tags:

views:

154

answers:

2

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?

A: 

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... ;)

Erik
A: 

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.

Asterisk
That seems reasonable, since it's not really a 'failure', there's just no operations to be taken.
Carl Norum