[Tutor] Reversi Game Logic

Dave Angel davea at davea.name
Sat Mar 21 00:45:48 CET 2015


On 03/20/2015 01:28 PM, niyanaxx95 at gmail.com wrote:
>

You have more than one copy of some lines of previous messages, and more 
than one version of code in the message.  So I have to guess which one 
you intend to be current.


>
> Thank you Mark for replying. I fixed the note you provided on the isLegalMove. However the lineOfAttack function is a function my Professor did so students are not allowed to touch it.
>
>
>
>
> For the isOver function, are you able to guide me on that?
>
> I am very new to Comp Science and am still learning.
>
> I have attached the programs needed for testing to show that I am testing my code as well as the instructions provided for my project.
>
> Please help me out!
>
>
>
>
>    # Returns a boolean indicating whether the game is over.
>    def isOver(self) :
>      isOver = 0
>      for i in range(8) :
>        for j in range(8) :
>          if self._gameBoard[i, j] != 0 :
>            isOver + 1

The above line does NOT change isOver variable.  Try again.  By the way, 
it's not usually a good idea to use the function name as a local within 
the function, even though it'll work.


>      if isOver == 64 :
>          self._gameOver = True
>          return True
>      else:
>          return False
>
>
>    # Returns the
>    def isLegalMove( self, row, col):
>      if row < 8 > col:
>        if self._gameBoard[row,col] != EMPTY:
>          return True
>      else:
>        return False

This function is still buggy.  It does not return either True or False 
if the selected row is non-empty.

>
>
>     # Returns the player number whose chip occupies the given square.
>    def occupiedBy(self, row, col):

How is the following function body any different from:
      return self._gameBoard[row, col]


>      if self._gameBoard[row, col] == BLACK :
>        return 1
>      if self._gameBoard[row, col] == WHITE :
>        return 2
>      else:
>        return 0
>
>
>
>
>    # Performs an actual move in the game. That is the current player places
>    # one of his chips in the square at position (row, col).
>    def makeMove( row, col ):
>      if isALineOfAttack(row, col, 1, 1) is True :

How are the four following lines any different from:
       self._gameBoard[row, col] = self._currentPlayer


>        if self._currentPlayer == 1 :
>          self._gameBoard[row, col] = BLACK
>        else :
>          self._gameBoard[row, col] = WHITE
>
>
>


-- 
DaveA


More information about the Tutor mailing list