Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from enum import Enum
- # import list libaray for the type declarations in the functions
- from typing import List
- class Edge(Enum):
- FLAT = 1
- BUMP = 2
- INSET = 3
- class Piece:
- def __init__(self, edges: List[Edge]):
- # eEvery list thing should contain 4 edges
- self.edges = edges
- # we assume
- def rotate_clockwise(self):
- pass
- def match(self, other_piece: 'Piece') -> bool:
- pass
- def arrange_puzzle(pieces: List[Piece], rows: int, cols: int) -> List[List[Piece]]:
- placed = []
- create the grid
- puzzle = [[None] * cols for _ in range(rows)]
- while pieces:
- piece = pieces.pop(0)
- placed_it = False
- for _ in range(4): # try all rotations
- for r in range(rows):
- for c in range(cols):
- # find all the emppty spts
- if puzzle[r][c] is None:
- # check if the pieceses match with the pieces around it
- if (r > 0 and puzzle[r-1][c] and not puzzle[r-1][c].match(piece)):
- continue
- if (c > 0 and puzzle[r][c-1] and not puzzle[r][c-1].match(piece)):
- continue
- puzzle[r][c] = piece
- placed.append(piece)
- placed_it = True
- break
- if placed_it:
- break
- if placed_it:
- break
- else:
- piece.rotate_clockwise() # rotate and try again
- return puzzle
Advertisement
Add Comment
Please, Sign In to add comment