Othello (Reversi) game, flipping pieces, Prolog
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 probl开发者_C百科em 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?
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... ;)
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.
精彩评论