Guest User

Untitled

a guest
Apr 24th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.43 KB | None | 0 0
  1.    def validMove(self, row, column, direction) :
  2.        validity = False
  3.        message = ""
  4.        if(direction == Board.UP):
  5.            if((row - 1) < 0 or str(self.grid[row - 1][column]) == str(self.grid[row][column])):
  6.                message = "You have made an invalid move. You're not able to move into your own pieces or go outside the board."
  7.            elif (((str(self.grid[row-1][column]) != Piece.WHITE or str(self.grid[row-1][column]) != Piece.RED) and (row-2 < 0))):
  8.                message = "You have made an invalid move. You're not able to move into your own pieces or go outside the board."
  9.            else:
  10.                validity = True
  11.        elif(direction == Board.DOWN):
  12.            if((row+1) > 7 or (self.grid[row+1][column]) == (self.grid[row][column])):
  13.                message = "You have made an invalid move. You're not able to move into your own pieces or go outside the board."
  14.            elif (((str(self.grid[row+1][column]) != Piece.WHITE or str(self.grid[row+1][column]) != Piece.RED) and (row+2 > 7))):
  15.                message = "You have made an invalid move. You're not able to move into your own pieces or go outside the board."
  16.            else:
  17.                validity = True
  18.        elif(direction == Board.LEFT):
  19.            if((column - 1 ) < 0 or str(self.grid[row][column - 1]) == str(self.grid[row][column])):
  20.                message = "You have made an invalid move. You're not able to move into your own pieces or go outside the board."
  21.            elif (((str(self.grid[row][column - 1]) != Piece.WHITE or str(self.grid[row][column - 1]) != Piece.RED) and (column - 2 <0))):
  22.                message = "You have made an invalid move. You're not able to move into your own pieces or go outside the board."
  23.            else:
  24.                validity = True
  25.        elif(direction == Board.RIGHT):
  26.            if((column +1) > 7 or str(self.grid[row][column + 1]) == str(self.grid[row][column])):
  27.                message = "You have made an invalid move. You're not able to move into your own pieces or go outside the board."
  28.            elif (((str(self.grid[row][column + 1]) != Piece.WHITE or str(self.grid[row][column + 1]) != Piece.RED) and (column + 2 <0))):
  29.                message = "You have made an invalid move. You're not able to move into your own pieces or go outside the board."
  30.            else:
  31.                validity = True
  32.        else:
  33.            message = "This program has encountered an unknown error."
Add Comment
Please, Sign In to add comment