[Tutor] Help with brute force approach to solving grid combinations

tempest.amogh tempest.amogh at gmail.com
Tue Jun 21 01:47:26 EDT 2022


As a personal project, I was inspired by Erik Demaine. He has created a font based on tetris shapes [http://erikdemaine.org/fonts/], however I would like to emulate this but based on another reference. I want to write an algorithm that brute force solves all the positions for these pieces in the english alphabet. I am having trouble making a grid that can be solved with these pieces, despite a book saying so.

I have attached the image that shows the shapes [http://erikdemaine.org/fonts/tetris/kadon_fonts.jpg].

My code:

---

import numpy as np

default_grid = np.array([[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0]
])

a_grid = np.array([[0, 0, 0, 0, 0, 0],
[0, 0, -1, -1, 0, 0],
[0, 0, -1, -1, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, -1, -1, 0, 0],
[0, 0, -1, -1, 0, 0]
])

# 1. SHAPES

# 1.1 DOMINOES

shape_straight2 = np.array([[7, 0, 0, 0, 0, 0],
[7, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0]
])

shape_flat = np.array([[0, 0, 0, 0, 8, 8],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0]
])

# 1.2 TRIMINOES

shape_corner = np.array([[6, 0],
[6, 6]
])

shape_straight3 = np.array([[7],
[7],
[7]
])

# 1.3 TETRIMINOES

shape_straight = np.array([[1, 1, 1, 1]
])

shape_straight1 = np.array([[1],
[1],
[1],
[1]
])

shape_square = np.array([[2, 2],
[2, 2]
])

shape_l = np.array([[3, 0],
[3, 0],
[3, 3]
])

shape_l2 = np.array([[0, 3],
[0, 3],
[3, 3]
])

shape_l3 = np.array([[3, 3, 3],
[0, 0, 3]
])

shape_l4 = np.array([[3, 3, 3],
[3, 0, 0]
])

shape_skew = np.array([[4, 4, 0],
[0, 4, 4]
])

shape_skew2 = np.array([[4, 0],
[4, 4],
[0, 4]
])

shape_skew3 = np.array([[0, 4, 4],
[4, 4, 0]
])

shape_skew4 = np.array([[0, 4],
[4, 4],
[4, 0]
])

shape_t = np.array([[5, 0],
[5, 5],
[5, 0]
])

shape_t2 = np.array([[5, 5, 5],
[0, 5, 0]
])

shape_t3 = np.array([[0, 5],
[5, 5],
[0, 5]
])

shape_t4 = np.array([[0, 5, 0],
[5, 5, 5]
])

new_shape = np.array(default_grid + shape_t4)

---

I ran a test with just inserting one shape into a grid. But the following error messages comes up.

In the final code, I want there to be a way to check the coordinates and insert the shapes there will many for loops and if elif statements.

Error Message:
120, in <module>
new_shape = np.array(default_grid + shape_t4)
ValueError: operands could not be broadcast together with shapes (6,6) (2,3)

—
Regards,

Amogh Atwe



More information about the Tutor mailing list