Showing posts with label pentomino. Show all posts
Showing posts with label pentomino. Show all posts

Wednesday, 10 February 2016

Pentomino versi Python

Ini adalah beberapa rakaman video (youtube) yang saya buat bagi program 'PENTOMINOS' yang saya tulis semula dalam Python. Saja untuk suka-suka. Video yang pertama ini ialah untuk puzzle bersaiz 3x20 sel.

3x20 sel

Program asal adalah seperti yang dibincangkan dalam pos bertajuk "Pentominos: A Puzzle-Solving Program | The BASIC Programs". Program asal ditulis dalam bahasa BASIC untuk mikrokomputer Commodore. Versi Python ini adalah lebih-kurang berdasarkan program BASIC yang asal.

Algoritma utamanya ialah seperti berikut:

slotno = 0
while slotno < 12:
full = get_next_empty_spot()
if full:
end
while not all_pieces_tried( slotno ):
p = get_untried_piece( slotno )
if p==-1: break
fit = try_piece( p, slotno )
if fit:
place_piece( p, nextrot, slotno )
pieceno[slotno] = p
rotation[slotno] = nextrot
slotno = slotno + 1
break
else:
tried[slotno][p] = True
if not fit:
reset_unused_pieces( slotno )
slotno = slotno - 1
if slotno<0: slotno="0</font">
undraw_piece( slotno )

Berikut ini adalah rakaman-rakaman video untuk puzzle bersaiz 4x15, 5x12 dan 6x10.


4x15 sel


5x12 sel


6x10 sel