QB64 Phoenix Edition
"5-line" engine - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Programs (https://qb64phoenix.com/forum/forumdisplay.php?fid=7)
+---- Thread: "5-line" engine (/showthread.php?tid=2429)

Pages: 1 2 3 4


RE: "5-line" engine - SMcNeill - 02-11-2024

Code: (Select All)
en = 9: gold = 12: c0 = 219: c1 = 46: c2 = 36: c3 = 35: c4 = 2: r(0) = 80: r(1) = 45: FOR t = 0 TO 1: r(2 + t) = INT(r(t) / 2): p(t) = r(2 + t): d(t) = p(t): NEXT t: RANDOMIZE TIMER: SCREEN _NEWIMAGE(r(0), r(1), 0): _FULLSCREEN: _CONTROLCHR OFF: COLOR 6: _PRINTSTRING (1, 1), STRING$(r(0) * r(1), CHR$(c0)): FOR c = 1 TO 4000: _PRINTSTRING (d(0), d(1)), CHR$(c1): t = INT(4 * RND): f = 0: FOR a = 0 TO 1: b = a * 2: l = t = b + 1: d(a) = (t = b OR l) * (l * 2 + 1) + d(a): f = f OR d(a) = 1 OR d(a) = r(a) - 1: NEXT a: FOR t = 0 TO 1: d(t) = r(t + 2) * -f + d(t) * (-f XOR 1): NEXT t, c: COLOR 14: FOR c = 1 TO gold: DO: FOR t = 0 TO 1: g(t) = INT((r(t) - 10) * RND) + 5: NEXT t: LOOP WHILE SCREEN(g(1), g(0), 0) <> c1 OR g(0) = r(2): _PRINTSTRING (g(0), g(1)), CHR$(c2): NEXT c: FOR c = 0 TO en - 1: DO: FOR t = 0 TO 1: en(c, t) = INT((r(t) - 10) * RND) + 5: NEXT t: LOOP UNTIL SCREEN(en(c, 1), en(c, 0), 0) = c1 AND SCREEN(en(c, 1), en(c, 0) + 1, 0) = c0: NEXT c: DO: COLOR 6: _PRINTSTRING (p(0), p(1)), MID$(CHR$(c1), 1, c): die = die OR SCREEN(p(1), p(0), 0) = c3: REDIM di(r(0) - 1, r(1) - 1) AS _BYTE: FOR x = 1 TO r(0) - 2: FOR y = 1 TO r(1) - 2: di(x, y) = SCREEN(y, x, 0) = c0: NEXT y, x: WHILE _MOUSEINPUT: WEND: e = 0: k = 1: di(_MOUSEX, _MOUSEY) = k: j = 15: DO UNTIL e OR k > j: mdis = 100: FOR x1 = -1 TO 1: FOR y1 = -1 TO 1: x2 = p(0) + x1: y2 = p(1) + y1: dis = ABS(x2 - _MOUSEX) + ABS(y2 - _MOUSEY): n = ((di(p(0) + x1, p(1)) = -1) AND (di(p(0), p(1) + y1) = -1) AND x1 AND y1) = 0: q = ABS(di(x2, y2) = k AND dis < mdis AND n): e = e OR q: d1 = d1 * (q XOR 1) + x1 * q: d2 = d2 * (q XOR 1) + y1 * q: mdis = mdis * (q XOR 1) + dis * q: NEXT y1, x1: FOR x = 1 TO r(0) - 2: FOR y = 1 TO r(1) - 2: f = 0
FOR x1 = -1 TO 1: FOR y1 = -1 TO 1: n = ((di(x + x1, y) = -1) AND (di(x, y + y1) = -1) AND x1 AND y1) = 0: f = f OR ((di(x + x1, y + y1) = k) AND (x1 OR y1) AND n): NEXT y1, x1: f = ABS(f AND di(x, y) = 0): di(x, y) = (k + 1) * f + di(x, y) * (f XOR 1): NEXT y, x: k = k + 1: LOOP: m(0) = d1 + p(0): m(1) = d2 + p(1): m = ABS(d1 OR d2) * st: c = ABS(m AND SCREEN(m(1), m(0), 0) <> c0): FOR t = 0 TO 1: p(t) = m(t) * c + p(t) * (c XOR 1): NEXT t: fg = -(SCREEN(p(1), p(0), 0) = c2): mygold = mygold + fg: SOUND 2000, .6 * fg: die = die OR SCREEN(p(1), p(0), 0) = c3: COLOR 15: _PRINTSTRING (p(0), p(1)), LEFT$(CHR$(c4), 1 + (k > j) * j3): j3 = j3 XOR 1: m = 0
FOR c = 0 TO en - 1: die = die OR SCREEN(en(c, 1), en(c, 0), 0) = c4: ti = c MOD 3: t = en(c, 2) - (ti = 0) * 2: DO: t = t + (ti = 0): FOR w = 0 TO 1: b = (t + 16 + w) MOD 4: d(w) = en(c, w) + (((b AND 1) = 0) * ((b = 0) * 2 + 1)) * (ti <> 1) - (SGN(t AND (1 + w)) * 2 - 1) * (ti = 1): NEXT w: u = SCREEN(d(1), d(0), 0): z = -(u = c0): t = (t - INT(4 * RND) * (z AND (ti > 0))) MOD 4: LOOP WHILE z
COLOR 6: _PRINTSTRING (en(c, 0), en(c, 1)), MID$(CHR$(c1), 1, en(c, 3)): en(c, 0) = d(0): en(c, 1) = d(1): en(c, 2) = t: en(c, 3) = -(u = c1): COLOR 2: _PRINTSTRING (d(0), d(1)), MID$(CHR$(c3), 1, en(c, 3)): die = die OR (u = c4) OR (m(0) = en(c, 0) AND m(1) = en(c, 1)): NEXT c: DO UNTIL _MOUSEBUTTON(1) OR st: _PRINTSTRING (1, 1), "Press left mouse button to start": t = _MOUSEINPUT: LOOP: st = 1: COLOR 6
_PRINTSTRING (1, 1), STRING$(50, CHR$(c0)): _LIMIT 8: _DISPLAY: LOOP UNTIL _KEYDOWN(27) OR gold = mygold OR die: COLOR 15: PRINT LEFT$("you dead", -8 * die); LEFT$("congratulation!", -15 * (gold = mygold))


There ya go. Now it's back down to 5-lines.

That's just how Amazing Steve is!!


RE: "5-line" engine - MasterGy - 02-11-2024

Thanks, it's perfect! Big Grin  It feels good to know I could count on you  Smile


RE: "5-line" engine - johannhowitzer - 02-12-2024

The bottom line for me about the colon debate is that sometimes they make code harder to read, but when used well, they can make it easier.  I prefer this:

if condition = true then dx = x2 - x: dy = y2 - y
for y = 1 to dy: for x = 1 to dx
   do_something
next x: next y

Over this:

if condition = true then
   dx = x2 - x
   dy = y2 - y
end if
for y = 1 to dy
   for x = 1 to dx
      do_something
   next x
next y


RE: "5-line" engine - James D Jarvis - 02-15-2024

Man oh man this got contentious. It was a little programming fun. I see these 5-line and 10-line challenges all over the place online and they are more impressive when the editor or on interpreter can't manage hundreds of character deep lines of code.   It's just fun. But I also noted some control structures I use all the time don't work in this layout. That was a lesson for me.


RE: "5-line" engine - Pete - 02-16-2024

As for a bit of historical significance, Americans were the first to use this type of coding style, way back in the 17-hundreds. We knew them as the colon-ists.

Pete

- Resident Histarian


RE: "5-line" engine - Jack - 02-16-2024

LOL Big Grin