def create_moves(rows, columns, row, column): """ Test creating all knight moves >>> create_moves(rows = 8, columns = 8, row = 8, column = 8) ((1, 2), (1, -2), (-1, 2), (-1, -2), (2, 1), (2, -1), (-2, 1), (-2, -1)) """ board = Board(rows, columns) position = Position(row, column, board) knight = Knight(position) return knight.create_moves()
def retrace_pop(rows, columns, row1, column1, row2, column2): """ >>> retrace_pop(rows=8, columns=8, row1=4, column1=5, row2=5, column2=7) (4, 5) """ board = Board(rows, columns) position1 = Position(row1, column1, board) position2 = Position(row2, column2, board) knight = Knight(position1) knight.record_visited_position(position2) return knight.retrace().coordinate
def valid_possible_position2(rows, columns, row1, column1, row2, column2): """ >>> valid_possible_position2(rows=8, columns=8, row1=4, column1=5, row2=5, column2=7) False """ board = Board(rows, columns) position1 = Position(row1, column1, board) position2 = Position(row2, column2, board) knight = Knight(position1) knight.record_visited_position(position2) return knight._valid_position(position2)
def knight_moves(rows, columns, row1, column1, row2, column2): """ Tests to see if a second knight is created, it has the proper knight moves >>> knight_moves(rows=8, columns=8, row1=4, column1=5, row2=5, column2=7) True """ board = Board(rows, columns) position1 = Position(row1, column1, board) position2 = Position(row2, column2, board) knight1 = Knight(position1) knight2 = Knight(position2) return knight1.moves == knight2.moves
def get_possible_moves(rows, columns, row, column): """ >>> get_possible_moves(rows = 8, columns = 8, row = 8, column = 8) [(7, 6), (6, 7)] >>> get_possible_moves(rows = 8, columns = 8, row = 4, column = 5) [(5, 7), (5, 3), (3, 7), (3, 3), (6, 6), (6, 4), (2, 6), (2, 4)] """ board = Board(rows, columns) position = Position(row, column, board) knight = Knight(position) positions = [] for p in knight.get_possible_moves(): positions.append(p.coordinate) return positions
def valid_possible_position3(rows, columns, row1, column1, row2, column2): """ >>> valid_possible_position3(rows=8, columns=8, row1=4, column1=5, row2=5, column2=7) True >>> valid_possible_position3(rows=8, columns=8, row1=4, column1=5, row2=5, column2=11) False >>> valid_possible_position3(rows=8, columns=8, row1=9, column1=9, row2=5, column2=7) True """ board = Board(rows, columns) position1 = Position(row1, column1, board) position2 = Position(row2, column2, board) knight = Knight(position1) return knight._valid_position(position2)
def record_visited_position(rows, columns, row1, column1, row2, column2): """ >>> record_visited_position(rows=8, columns=8, row1=4, column1=5, row2=5, column2=7) [(4, 5), (5, 7)] """ board = Board(rows, columns) position1 = Position(row1, column1, board) position2 = Position(row2, column2, board) knight = Knight(position1) knight.record_visited_position(position2) positions = [] for pos in knight.visited_positions: positions.append(pos.coordinate) return positions