Что-то в том же духе.
Я сделал это на месте, так как считаю, что это лучше подходит здесь, из-за возможной обработки ошибок, которую вы можете рассмотреть.
import numpy as np
A2 = np.tile(2, (8, 8))
A3 = np.tile(3, (4, 8))
A4 = np.tile(4, (4, 4))
A5 = np.tile(5, (2, 4))
A6 = np.tile(6, (2, 2))
A7 = np.tile(7, (1, 2))
#list to track blocks positions
hist_moves=[]
#Assuming "blocks" can only take positive numbers - let's make empty=-1
main_list = -np.ones(shape=(18, 8))
#block - block to be added
#position - top, left coordinates, to position block on the board
#board - board to put the block on
def put_block(block, position, board, hist):
block_shape=np.array(block.shape)
board_shape=np.array(board.shape)
position=np.array(position)
if(np.any(block_shape+position>board_shape)):
#block is too big - doesn't fit the board
return False
elif(np.any(board[position[0]:position[0]+block.shape[0], position[1]:position[1]+block.shape[1]]!=-1)):
#block overlaps with other blocks
return False
else:
board[position[0]:position[0]+block.shape[0], position[1]:position[1]+block.shape[1]]=block
hist.append((block[0,0], position.tolist()))
return True
move_=put_block(A4, (0,0), main_list, hist_moves)
print(move_)
move_=put_block(A5, (0,4), main_list, hist_moves)
print(move_)
move_=put_block(A5, (2,4), main_list, hist_moves)
print(move_)
move_=put_block(A3, (5,4), main_list, hist_moves)
print(move_)
print(main_list)
print(hist_moves)
Выводы:
True
True
True
False
[[ 4. 4. 4. 4. 5. 5. 5. 5.]
[ 4. 4. 4. 4. 5. 5. 5. 5.]
[ 4. 4. 4. 4. 5. 5. 5. 5.]
[ 4. 4. 4. 4. 5. 5. 5. 5.]
[-1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1.]
[-1. -1. -1. -1. -1. -1. -1. -1.]]
[(4, [0, 0]), (5, [0, 4]), (5, [2, 4])]