### Author Topic: PENtrIS  (Read 360 times)

#### _vince

##### PENtrIS
« on: October 11, 2018, 05:42:37 PM »
An extension of tetris to pentominos as described here https://en.wikipedia.org/wiki/Pentomino

I've never actually played this variant before other then this very program so not sure how playable and balanced it is, I am able to get several lines with a bit of luck.  Suggestions such as which pieces to add/remove, board size, etc are welcome.  Edit: fixed lines not being cleared issue

Code: QB64 [Select]
1. DEFLNG a-z
2.
3. DIM SHARED piece(17, 2, 4)
4. DIM SHARED piece_color(17)
5. DIM SHARED size, sw, sh
6.
7. size = 35
8. sw = 11
9. sh = 25
10.
11. REDIM SHARED board(sw - 1, sh - 1)
12.
13. piece(0,0,0)=0: piece(0,1,0)=1: piece(0,2,0)=0
14. piece(0,0,1)=0: piece(0,1,1)=1: piece(0,2,1)=0
15. piece(0,0,2)=0: piece(0,1,2)=1: piece(0,2,2)=0
16. piece(0,0,3)=0: piece(0,1,3)=1: piece(0,2,3)=0
17. piece(0,0,4)=0: piece(0,1,4)=1: piece(0,2,4)=0
18.
19. piece(1,0,0)=0: piece(1,1,0)=0: piece(1,2,0)=0
20. piece(1,0,1)=0: piece(1,1,1)=0: piece(1,2,1)=0
21. piece(1,0,2)=0: piece(1,1,2)=1: piece(1,2,2)=1
22. piece(1,0,3)=1: piece(1,1,3)=1: piece(1,2,3)=0
23. piece(1,0,4)=0: piece(1,1,4)=1: piece(1,2,4)=0
24.
25. piece(2,0,0)=0: piece(2,1,0)=0: piece(2,2,0)=0
26. piece(2,0,1)=0: piece(2,1,1)=0: piece(2,2,1)=0
27. piece(2,0,2)=1: piece(2,1,2)=1: piece(2,2,2)=0
28. piece(2,0,3)=0: piece(2,1,3)=1: piece(2,2,3)=1
29. piece(2,0,4)=0: piece(2,1,4)=1: piece(2,2,4)=0
30.
31. piece(3,0,0)=0: piece(3,1,0)=0: piece(3,2,0)=0
32. piece(3,0,1)=0: piece(3,1,1)=1: piece(3,2,1)=0
33. piece(3,0,2)=0: piece(3,1,2)=1: piece(3,2,2)=0
34. piece(3,0,3)=0: piece(3,1,3)=1: piece(3,2,3)=0
35. piece(3,0,4)=1: piece(3,1,4)=1: piece(3,2,4)=0
36.
37. piece(4,0,0)=0: piece(4,1,0)=0: piece(4,2,0)=0
38. piece(4,0,1)=0: piece(4,1,1)=1: piece(4,2,1)=0
39. piece(4,0,2)=0: piece(4,1,2)=1: piece(4,2,2)=0
40. piece(4,0,3)=0: piece(4,1,3)=1: piece(4,2,3)=0
41. piece(4,0,4)=0: piece(4,1,4)=1: piece(4,2,4)=1
42.
43. piece(5,0,0)=0: piece(5,1,0)=0: piece(5,2,0)=0
44. piece(5,0,1)=0: piece(5,1,1)=0: piece(5,2,1)=0
45. piece(5,0,2)=1: piece(5,1,2)=1: piece(5,2,2)=0
46. piece(5,0,3)=1: piece(5,1,3)=1: piece(5,2,3)=0
47. piece(5,0,4)=0: piece(5,1,4)=1: piece(5,2,4)=0
48.
49. piece(6,0,0)=0: piece(6,1,0)=0: piece(6,2,0)=0
50. piece(6,0,1)=0: piece(6,1,1)=0: piece(6,2,1)=0
51. piece(6,0,2)=0: piece(6,1,2)=1: piece(6,2,2)=1
52. piece(6,0,3)=0: piece(6,1,3)=1: piece(6,2,3)=1
53. piece(6,0,4)=0: piece(6,1,4)=1: piece(6,2,4)=0
54.
55. piece(7,0,0)=0: piece(7,1,0)=0: piece(7,2,0)=0
56. piece(7,0,1)=0: piece(7,1,1)=1: piece(7,2,1)=0
57. piece(7,0,2)=0: piece(7,1,2)=1: piece(7,2,2)=0
58. piece(7,0,3)=1: piece(7,1,3)=1: piece(7,2,3)=0
59. piece(7,0,4)=1: piece(7,1,4)=0: piece(7,2,4)=0
60.
61. piece(8,0,0)=0: piece(8,1,0)=0: piece(8,2,0)=0
62. piece(8,0,1)=0: piece(8,1,1)=1: piece(8,2,1)=0
63. piece(8,0,2)=0: piece(8,1,2)=1: piece(8,2,2)=0
64. piece(8,0,3)=0: piece(8,1,3)=1: piece(8,2,3)=1
65. piece(8,0,4)=0: piece(8,1,4)=0: piece(8,2,4)=1
66.
67. piece(9,0,0)=0: piece(9,1,0)=0: piece(9,2,0)=0
68. piece(9,0,1)=0: piece(9,1,1)=0: piece(9,2,1)=0
69. piece(9,0,2)=1: piece(9,1,2)=1: piece(9,2,2)=1
70. piece(9,0,3)=0: piece(9,1,3)=1: piece(9,2,3)=0
71. piece(9,0,4)=0: piece(9,1,4)=1: piece(9,2,4)=0
72.
73. piece(10,0,0)=0: piece(10,1,0)=0: piece(10,2,0)=0
74. piece(10,0,1)=0: piece(10,1,1)=0: piece(10,2,1)=0
75. piece(10,0,2)=0: piece(10,1,2)=0: piece(10,2,2)=0
76. piece(10,0,3)=1: piece(10,1,3)=0: piece(10,2,3)=1
77. piece(10,0,4)=1: piece(10,1,4)=1: piece(10,2,4)=1
78.
79. piece(11,0,0)=0: piece(11,1,0)=0: piece(11,2,0)=0
80. piece(11,0,1)=0: piece(11,1,1)=0: piece(11,2,1)=0
81. piece(11,0,2)=0: piece(11,1,2)=0: piece(11,2,2)=1
82. piece(11,0,3)=0: piece(11,1,3)=0: piece(11,2,3)=1
83. piece(11,0,4)=1: piece(11,1,4)=1: piece(11,2,4)=1
84.
85. piece(12,0,0)=0: piece(12,1,0)=0: piece(12,2,0)=0
86. piece(12,0,1)=0: piece(12,1,1)=0: piece(12,2,1)=0
87. piece(12,0,2)=0: piece(12,1,2)=0: piece(12,2,2)=1
88. piece(12,0,3)=0: piece(12,1,3)=1: piece(12,2,3)=1
89. piece(12,0,4)=1: piece(12,1,4)=1: piece(12,2,4)=0
90.
91. piece(13,0,0)=0: piece(13,1,0)=0: piece(13,2,0)=0
92. piece(13,0,1)=0: piece(13,1,1)=0: piece(13,2,1)=0
93. piece(13,0,2)=0: piece(13,1,2)=1: piece(13,2,2)=0
94. piece(13,0,3)=1: piece(13,1,3)=1: piece(13,2,3)=1
95. piece(13,0,4)=0: piece(13,1,4)=1: piece(13,2,4)=0
96.
97. piece(14,0,0)=0: piece(14,1,0)=0: piece(14,2,0)=0
98. piece(14,0,1)=0: piece(14,1,1)=1: piece(14,2,1)=0
99. piece(14,0,2)=1: piece(14,1,2)=1: piece(14,2,2)=0
100. piece(14,0,3)=0: piece(14,1,3)=1: piece(14,2,3)=0
101. piece(14,0,4)=0: piece(14,1,4)=1: piece(14,2,4)=0
102.
103. piece(15,0,0)=0: piece(15,1,0)=0: piece(15,2,0)=0
104. piece(15,0,1)=0: piece(15,1,1)=1: piece(15,2,1)=0
105. piece(15,0,2)=0: piece(15,1,2)=1: piece(15,2,2)=1
106. piece(15,0,3)=0: piece(15,1,3)=1: piece(15,2,3)=0
107. piece(15,0,4)=0: piece(15,1,4)=1: piece(15,2,4)=0
108.
109. piece(16,0,0)=0: piece(16,1,0)=0: piece(16,2,0)=0
110. piece(16,0,1)=0: piece(16,1,1)=0: piece(16,2,1)=0
111. piece(16,0,2)=0: piece(16,1,2)=1: piece(16,2,2)=1
112. piece(16,0,3)=0: piece(16,1,3)=1: piece(16,2,3)=0
113. piece(16,0,4)=1: piece(16,1,4)=1: piece(16,2,4)=0
114.
115. piece(17,0,0)=0: piece(17,1,0)=0: piece(17,2,0)=0
116. piece(17,0,1)=0: piece(17,1,1)=0: piece(17,2,1)=0
117. piece(17,0,2)=1: piece(17,1,2)=1: piece(17,2,2)=0
118. piece(17,0,3)=0: piece(17,1,3)=1: piece(17,2,3)=0
119. piece(17,0,4)=0: piece(17,1,4)=1: piece(17,2,4)=1
120.
121. SCREEN _NEWIMAGE(sw*size, sh*size, 32)
122.
123. piece_color(0) = _RGB(255,0,0)
124. piece_color(1) = _RGB(255,145,0)
125. piece_color(2) = _RGB(255,200,211)
126. piece_color(3) = _RGB(0,255,220)
127. piece_color(4) = _RGB(0,230,255)
128. piece_color(5) = _RGB(0,170,10)
129. piece_color(6) = _RGB(0,250,20)
130. piece_color(7) = _RGB(128,230,0)
131. piece_color(8) = _RGB(80,150,0)
132. piece_color(9) = _RGB(0,200,0)
133. piece_color(10) = _RGB(50,160,170)
134. piece_color(11) = _RGB(50,110,175)
135. piece_color(12) = _RGB(50,50,175)
136. piece_color(13) = _RGB(110,50,175)
137. piece_color(14) = _RGB(210,0,255)
138. piece_color(15) = _RGB(110,0,130)
139. piece_color(16) = _RGB(255,0,140)
140. piece_color(17) = _RGB(170,0,100)
141.
142.
143. redraw = -1
144.
145. speed = 2
146. lines = 0
147. pause = 0
148. putpiece = 0
149. startx = (sw - 4)/2
150.
151. pn = INT(RND*18)
152. px = startx
153. py = -2
154. rot = 0
155.
156. title\$ = "lines="+LTRIM\$(STR\$(lines))+",speed="++LTRIM\$(STR\$(speed))
157. _TITLE title\$
158.
159. t = TIMER
160.
161.         IF (TIMER - t) > (1/speed) AND NOT pause THEN
162.                 IF valid(pn, px, py + 1, rot) THEN py = py + 1 ELSE putpiece = -1
163.
164.                 t = TIMER
165.                 redraw = -1
166.
167.         IF putpiece THEN
168.                 IF valid(pn, px, py, rot) THEN
169.                         n = place(pn, px, py, rot)
170.                                 lines = lines + n
171.                                 title\$ = "lines="+LTRIM\$(STR\$(lines))+",speed="++LTRIM\$(STR\$(speed))
172.                                 _TITLE title\$
173.
174.                 pn = INT(RND*18)
175.                 px = startx
176.                 py = -2
177.                 rot = 0
178.
179.                 putpiece = 0
180.                 redraw = -1
181.
182.                 IF NOT valid(pn, px, py, rot) THEN
183.                         FOR y=0 TO sh-1
184.                                 FOR x=0 TO sw-1
185.                                         board(x, y) = 0
186.                         lines = 0
187.                         title\$ = "lines="+LTRIM\$(STR\$(lines))+",speed="++LTRIM\$(STR\$(speed))
188.                         _TITLE title\$
189.
190.         IF redraw THEN
191.                 LINE (0,0)-(sw*size, sh*size),_RGB(0,0,0),bf
192.                 FOR y=0 TO sh - 1
193.                         FOR x=0 TO sw - 1
194.                                 IF board(x, y) <> 0 THEN
195.                                         LINE (x*size, y*size)-STEP(size-2, size-2), piece_color(board(x, y)-1), bf
196.                                         LINE (x*size, y*size)-STEP(size-2, size-2), _RGB(50,50,50), b
197.
198.                 FOR y=0 TO 4
199.                         FOR x=0 TO 2
200.                                 rotate xx, yy, x, y, pn, rot
201.                                 IF piece(pn, x, y) THEN LINE ((px + xx)*size, (py + yy)*size)-STEP(size-2, size-2), piece_color(pn), bf
202.
203.                 redraw = 0
204.
205.         k = _KEYHIT
206.                 shift = _KEYDOWN(100304) OR _KEYDOWN(100303)
207.                 CASE 18432 'up
208.                         IF valid(pn, px, py, (rot + 1) MOD 4) THEN rot = (rot + 1) MOD 4
209.                         pause = 0
210.                 CASE 19200 'left
211.                         IF shift THEN
212.                                 FOR xx=0 TO sw-1
213.                                         IF NOT valid(pn, px - xx, py, rot) THEN EXIT FOR
214.                                 px = px - xx + 1
215.                                 IF valid(pn, px - 1, py, rot) THEN px = px - 1
216.                         pause = 0
217.                 CASE 19712 'right
218.                         IF shift THEN
219.                                 FOR xx=px TO sw-1
220.                                         IF NOT valid(pn, xx, py, rot) THEN EXIT FOR
221.                                 px = xx - 1
222.                                 IF valid(pn, px + 1, py, rot) THEN px = px + 1
223.                         pause = 0
224.                 CASE 20480, 32 'down
225.                         IF shift OR k = 32 THEN
226.                                 FOR yy=py TO sh-1
227.                                         IF NOT valid(pn, px, yy, rot) THEN EXIT FOR
228.                                 py = yy - 1
229.                                 putpiece = -1
230.                                 IF valid(pn, px, py + 1, rot) THEN py = py + 1
231.                         pause = 0
232.                 CASE 112 'p
233.                         pause = NOT pause
234.                 CASE 13 'enter
235.                         FOR y=0 TO sh-1
236.                                 FOR x=0 TO sw-1
237.                                         board(x, y) = 0
238.                         pn = INT(RND*17)
239.                         px = startx
240.                         py = -2
241.                         rot = 0
242.                         putpiece = 0
243.                         lines = 0
244.                         title\$ = "lines="+LTRIM\$(STR\$(lines))+",speed="++LTRIM\$(STR\$(speed))
245.                         _TITLE title\$
246.                 CASE 43, 61 'plus
247.                         IF speed < 100 THEN
248.                                 speed = speed + 1
249.                                 title\$ = "lines="+LTRIM\$(STR\$(lines))+",speed="++LTRIM\$(STR\$(speed))
250.                                 _TITLE title\$
251.                 CASE 95, 45
252.                         IF speed > 1 THEN
253.                                 speed = speed - 1
254.                                 title\$ = "lines="+LTRIM\$(STR\$(lines))+",speed="++LTRIM\$(STR\$(speed))
255.                                 _TITLE title\$
256.                 CASE 27
257.
258.                 redraw = -1
259.
260.
261. SUB rotate(xx, yy, x, y, pn, rot)
262.         CASE 0
263.                 rot_new = rot MOD 2
264.                 rot_new = rot
265.
266.         SELECT CASE rot_new
267.         CASE 0
268.                 xx = x
269.                 yy = y
270.         CASE 1
271.                 IF pn = 0 THEN
272.                         xx = y - 1
273.                         yy = 3 - x
274.                 ELSEIF pn = 14 OR pn = 15 THEN
275.                         xx = y - 1
276.                         yy = 3 - x
277.                         xx = y - 2
278.                         yy = 4 - x
279.         CASE 2
280.                 IF pn = 14 OR pn = 15 THEN
281.                         xx = 2 - x
282.                         yy = 4 - y
283.                         xx = 2 - x
284.                         yy = 6 - y
285.         CASE 3
286.                 IF pn = 14 OR pn = 15 THEN
287.                         xx = 3 - y
288.                         yy = x + 1
289.                         xx = 4 - y
290.                         yy = x + 2
291.
292. FUNCTION valid(pn, px, py, rot)
293.         FOR y=0 TO 4
294.                 FOR x=0 TO 2
295.                         rotate xx, yy, x, y, pn, rot
296.                         IF py + yy >= 0 THEN
297.                                 IF piece(pn, x, y) THEN
298.                                         IF (px + xx >= sw) OR (px + xx < 0) THEN
299.                                                 valid = 0
300.                                         IF (py + yy >= sh) THEN
301.                                                 valid = 0
302.                                         'if (py >= 0) then
303.                                         IF board(px + xx, py + yy) THEN
304.                                                 valid = 0
305.                                         'end if
306.
307.         valid = -1
308.
309. FUNCTION place(pn, px, py, rot)
310.         lines = 0
311.
312.         FOR y=0 TO 4
313.                 FOR x=0 TO 2
314.                         rotate xx, yy, x, y, pn, rot
315.                         IF py + yy >= 0 THEN IF piece(pn, x, y) THEN board(px + xx, py + yy) = pn + 1
316.
317.         'clear lines
318.         FOR y=py-5 TO py+5
319.                 IF y>=0 AND y<sh THEN
320.                         clr = -1
321.                         FOR x=0 TO sw - 1
322.                                 IF board(x, y) = 0 THEN
323.                                         clr = 0
324.
325.                         IF clr THEN
326.                                 lines = lines + 1
327.                                 FOR yy=y TO 1 STEP -1
328.                                         FOR x=0 TO sw-1
329.                                                 board(x, yy) = board(x, yy-1)
330.
331.         place = lines
332.
« Last Edit: October 13, 2018, 04:59:56 AM by v »

#### johnno56

• Live long and prosper.
##### Re: PENtrIS
« Reply #1 on: October 12, 2018, 02:05:50 AM »
Cool version. So much harder than the original but still cool... I like it.
Logic is the beginning of wisdom.

#### STxAxTIC

• Library Staff
• Your mom would love me.
##### Re: PENtrIS
« Reply #2 on: October 12, 2018, 11:54:08 AM »
Enjoyed the heck out of this generalization of Tetris. Not sure how refined the code is yet but I swear I formed a line that didn't clear - but lines above that one did clear properly. In the old game I got more lines than a cokehead - this one's way harder. Love it!

#### TempodiBasic

##### Re: PENtrIS
« Reply #3 on: October 13, 2018, 08:59:57 AM »
Great V
I like  this version too, also if it uses blocks that have a more unusual shape.