Hey.. I'm currently trying to code an Othello (aka reversi) game in Java, and I have a problem with my algorithm.
Now you don't need to know Java in order to be able to help, simply programming.
What I'm trying to do is to find all the possibilities and put them in an array afterwards.
I made a paint picture that shows all the possibilities in a white spot.
My current algorithm works this way.
* = black
+ = white
` = nothing
code:
counter = 1 ;
possibilitesCounter = 0 ;
for ( counterRows = 0 ; counterRows < 8 ; counterRows ++ )
for (counterCols = 0 ; counterCols < 8 ; counterCols ++ )
{
case = array [counterRow][counterCols];
if ( case.equals ('*') )
{
case 2 = array[counterRow][counterCols-1] ;
while ( case2.equals('+'))
{
counter++ ;
case1 = case2 ;
case2 = array[counterRow][counterCols-counter]
}
if ( case2.equals('`') )
{
array[possibilitesCounter] = counterRow + "" + counterCols ;
possibilitesCounter ++ ;
}
}
}
Of course that code only applies for the checking if there's anything on the left. I have to do the same for right, up, down and 4 diagonals.
I was wondering if there was a mor efficient and shorter way to do it.
Thanks for the help everyone.
Here is a pic that shows all the possible moves ( you can see the possibilites in white )