# [Tutor] Reversi Game Logic

Dave Angel davea at davea.name
Fri Mar 20 14:38:42 CET 2015

```On 03/19/2015 08:50 PM, niyanaxx95 at gmail.com wrote:
> I am having trouble with a function in my reversi logic code. The function is the isLegalMove I am asked to "Return a Boolean indicating if the current player can place their chip in the square at position (row, col). Both row and col must be valid indices​." So I came up with my code below, however a move I make in the game says Error: not a legal move. Please help!
>
>

I see lots of things wrong with the code, just by visual inspection.
That should tell us that unit tests are necessary.  If nothing else,
unit tests help you refine just what each method is supposed to do, and
under what conditions.

I don't recall the rules for Othello, as it's been about 25 years since
I've played it, and even then I didn't play much.

But there are lots of things about the code that the comments don't
describe.  For example, it would seem from some of your code that the
first player is always BLACK, and the second player is always WHITE. But
in other places, you keep them distinct.

I see Mark gave you a number of markers into your code for problems that
already exist.  So I'm going to concentrate only on the method you mention.

>
>    # Returns the

Finish the comment

>    def isLegalMove( self, row, col):
>      if row < 8 and col < 8:
>        if self._gameBoard[row,col] != EMPTY:
>          return True
>      else:
>        return False

There are 3 exit points from the above function, and only two of them
have return statements.  Your unit test could detect that by assuring
that the return value is always either True or False.  The above
function sometimes returns None.

Have you been taught yet what happens when a function falls off the end
without a return statement?

--
DaveA
```