Exemplo n.º 1
0
 def getPossibleMoves(self, board, color, i, j):
     ret_list = []
     physical_moves = []
     for k in [1, 2, 3, 4, 5, 6, 7]:
         move = encoded(i, j, i - k, j - k)
         physical_moves.append(move)
         move = encoded(i, j, i + k, j + k)
         physical_moves.append(move)
         move = encoded(i, j, i - k, j + k)
         physical_moves.append(move)
         move = encoded(i, j, i + k, j - k)
         physical_moves.append(move)
     for k in range(8):
         if k != i:
             move = encoded(i, j, k, j)
             physical_moves.append(move)
         if k != j:
             move = encoded(i, j, i, k)
             physical_moves.append(move)
     if color == 'B':
         turn = 'BLACK'
     else:
         turn = 'WHITE'
     for m in physical_moves:
         from Move import Move
         move = Move(m)
         if move.isValidRule(board, turn):
             ret_list.append(move.coded)
     return ret_list
Exemplo n.º 2
0
 def getPossibleMoves(self, board, color, i, j):
     ret_list = []
     physical_moves = []
     move = encoded(i, j, i - 1, j - 2)
     physical_moves.append(move)
     move = encoded(i, j, i - 2, j - 1)
     physical_moves.append(move)
     move = encoded(i, j, i + 1, j + 2)
     physical_moves.append(move)
     move = encoded(i, j, i + 2, j + 1)
     physical_moves.append(move)
     move = encoded(i, j, i - 1, j + 2)
     physical_moves.append(move)
     move = encoded(i, j, i - 2, j + 1)
     physical_moves.append(move)
     move = encoded(i, j, i + 1, j - 2)
     physical_moves.append(move)
     move = encoded(i, j, i + 2, j - 1)
     physical_moves.append(move)
     if color == 'B':
         turn = 'BLACK'
     else:
         turn = 'WHITE'
     for m in physical_moves:
         from Move import Move
         move = Move(m)
         if move.isValidRule(board, turn):
             ret_list.append(move.coded)
     return ret_list
Exemplo n.º 3
0
def getMove(board, turn, example=''):
    printBoard(board)
    move = input(turn + example + ': ')
    while True:
        if len(move) != 4:
            move = input(
                'Please enter a four digit input (eg: from D2 to D4 -> \'D2D4\'): '
            )
        else:
            move = Move(move)
            if move.isValidInput():
                if move.isValidRule(board, turn):
                    return move.coded
                else:
                    move = input('Not valid according to rules, enter again: ')
            else:
                move = input(
                    'Please enter a valid move (eg: from D2 to D4 -> \'D2D4\'): '
                )