Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def validMove(self, row, column, direction) :
- validity = False
- message = ""
- if(direction == Board.UP):
- if((row - 1) < 0 or str(self.grid[row - 1][column]) == str(self.grid[row][column])):
- message = "You have made an invalid move. You're not able to move into your own pieces or go outside the board."
- elif (((str(self.grid[row-1][column]) != Piece.WHITE or str(self.grid[row-1][column]) != Piece.RED) and (row-2 < 0))):
- message = "You have made an invalid move. You're not able to move into your own pieces or go outside the board."
- else:
- validity = True
- elif(direction == Board.DOWN):
- if((row+1) > 7 or (self.grid[row+1][column]) == (self.grid[row][column])):
- message = "You have made an invalid move. You're not able to move into your own pieces or go outside the board."
- elif (((str(self.grid[row+1][column]) != Piece.WHITE or str(self.grid[row+1][column]) != Piece.RED) and (row+2 > 7))):
- message = "You have made an invalid move. You're not able to move into your own pieces or go outside the board."
- else:
- validity = True
- elif(direction == Board.LEFT):
- if((column - 1 ) < 0 or str(self.grid[row][column - 1]) == str(self.grid[row][column])):
- message = "You have made an invalid move. You're not able to move into your own pieces or go outside the board."
- elif (((str(self.grid[row][column - 1]) != Piece.WHITE or str(self.grid[row][column - 1]) != Piece.RED) and (column - 2 <0))):
- message = "You have made an invalid move. You're not able to move into your own pieces or go outside the board."
- else:
- validity = True
- elif(direction == Board.RIGHT):
- if((column +1) > 7 or str(self.grid[row][column + 1]) == str(self.grid[row][column])):
- message = "You have made an invalid move. You're not able to move into your own pieces or go outside the board."
- elif (((str(self.grid[row][column + 1]) != Piece.WHITE or str(self.grid[row][column + 1]) != Piece.RED) and (column + 2 <0))):
- message = "You have made an invalid move. You're not able to move into your own pieces or go outside the board."
- else:
- validity = True
- else:
- message = "This program has encountered an unknown error."
Add Comment
Please, Sign In to add comment