Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"5-line" engine
#21
(02-09-2024, 02:35 PM)GareBear Wrote: MadterGy, You put that the way I wanted to put it. Thank you!

SMcNeil, I am sorry to have offended you. It was not my intention to do any such thing. The difference between the two you did, James D Jarvis and the way you want to do is not much here in the sizes between them. 

Broke down into single command lines - 1.9k 1862 bytes - SMcNeill's
With colons - 1.0k or 1022 bytes - James D Jarvis'
1862 - 1022 = 840 bytes or 0.9k not much compression.

This prove MasterGy's program compression. Which GWBasic needed to run programs in which people then was trying to push the limits of the interpreter. Some like Jame D Jarvis like to have fun with the old way of using very little to no line numbers.

To all involved, Let us all try not take this too seriously and let others have flexibly in our creativity in the language we choose to use and learn from each other. - GareBear.

I'm not offended, and at the end of the day, everyone has to program in the style that suits them the best.  As long as the finished product works, then the program is a success.  Smile

That said, one thing you're not taking into account is that the vast majority of what I posted was nothing more than remarks to help highlight the changes I made.  If you remove those, you get something different:

Code: (Select All)
SCREEN _NEWIMAGE(80, 45, 0)
_FULLSCREEN
_CONTROLCHR OFF
RANDOMIZE TIMER
FOR d = 1 TO INT(200 + RND * (100 * (1 + RND * 4)))
    m$ = m$ + CHR$(49 + INT(RND * 4))
NEXT d
px = 40
py = 20
DO
    dx = 40
    dy = 20
    COLOR 7
    _PRINTSTRING (1, 1), STRING$(3280, 219)
    FOR c = 1 TO LEN(m$)
        _PRINTSTRING (dx, dy), "."
        SELECT CASE MID$(m$, c, 1)
            CASE "1": dy = dy - 1
            CASE "2": dx = dx + 1
            CASE "3": dy = dy + 1
            CASE "4": dx = dx - 1
        END SELECT
        IF dy = 40 OR dy = 1 OR dx = 80 OR dx = 1 THEN dy = 20: dx = 40
    NEXT c
    COLOR 15
    _PRINTSTRING (px, py), CHR$(2)
    kk$ = UCASE$(INPUT$(1))
    pxm = 0
    pym = 0
    SELECT CASE kk$
        CASE "W": pym = -1
        CASE "S": pym = 1
        CASE "D": pxm = 1
        CASE "A": pxm = -1
    END SELECT
    IF SCREEN(pym + py, pxm + px, 0) <> 219 THEN px = px + pxm: py = py + pym
LOOP UNTIL kk$ = CHR$(27)

983 bytes -- which is less than the original -- and it's still in a human-readable format.  Wink

The reason I was sharing what I did, was for the same purpose you stated:  "to use and learn from each other."

One way to think of this type project, is -- as you're doing yourself -- is to do a simple byte-count of a program.  And, oddly enough, colons *don't* reduce byte counts or file size -- in fact, they *increase* it!

Take these two lines for instance:

PRINT: PRINT

vs

PRINT
PRINT

Which is longer and uses more bytes to store that program?

The first is "print: print", for a total of 12-bytes.

The second is "printCRLFprint", which on Windows CRLF is going to be chr$(10) + chr$(13) for a total of 12-bytes, but on Linux and Mac, it's *just* going to chr$(10), which makes the length 11-bytes.

At best, colon + space breaks even on disk size -- and that's only possible where you're using Windows which has a 2-byte CRLF system.  Otherwise, it's just going to make your code LONGER than before; not shorter.

A second thing to note -- I kept the spacing and formatting going with what I shared, just like with the comments.  Take those out and you end up with this:

Code: (Select All)
SCREEN _NEWIMAGE(80, 45, 0)
_FULLSCREEN
_CONTROLCHR OFF
RANDOMIZE TIMER
FOR d = 1 TO INT(200 + RND * (100 * (1 + RND * 4)))
m$ = m$ + CHR$(49 + INT(RND * 4))
NEXT d
px = 40
py = 20
DO
dx = 40
dy = 20
COLOR 7
_PRINTSTRING (1, 1), STRING$(3280, 219)
FOR c = 1 TO LEN(m$)
_PRINTSTRING (dx, dy), "."
SELECT CASE MID$(m$, c, 1)
CASE "1": dy = dy - 1
CASE "2": dx = dx + 1
CASE "3": dy = dy + 1
CASE "4": dx = dx - 1
END SELECT
IF dy = 40 OR dy = 1 OR dx = 80 OR dx = 1 THEN dy = 20: dx = 40
NEXT c
COLOR 15
_PRINTSTRING (px, py), CHR$(2)
kk$ = UCASE$(INPUT$(1))
pxm = 0
pym = 0
SELECT CASE kk$
CASE "W": pym = -1
CASE "S": pym = 1
CASE "D": pxm = 1
CASE "A": pxm = -1
END SELECT
IF SCREEN(pym + py, pxm + px, 0) <> 219 THEN px = px + pxm: py = py + pym
LOOP UNTIL kk$ = CHR$(27)

811 bytes for the same program.

Packing multiple lines together doesn't make the end code any shorter.  It just makes it harder to read and edit.  It's this old-style of thinking which lead to BASIC getting such a bad reputation all those years ago, and it being dropped by Microsoft. 

I'm not trying to pick on James or anything, and I hope he doesn't take it that way.  I was just hoping to help highlight and show that there's really no reason to pack your lines together in such a manner.  You're not really making a shorter program, or one that uses less memory to load or run.  All you're doing is creating a program which is harder to read, understand, and maintain.

Wink
Reply


Messages In This Thread
"5-line" engine - by James D Jarvis - 02-06-2024, 02:13 PM
RE: "5-line" engine - by SMcNeill - 02-06-2024, 02:40 PM
RE: "5-line" engine - by James D Jarvis - 02-06-2024, 05:43 PM
RE: "5-line" engine - by bplus - 02-06-2024, 06:27 PM
RE: "5-line" engine - by GareBear - 02-06-2024, 10:42 PM
RE: "5-line" engine - by JRace - 02-07-2024, 01:30 AM
RE: "5-line" engine - by MasterGy - 02-07-2024, 02:31 PM
RE: "5-line" engine - by TerryRitchie - 02-07-2024, 02:46 PM
RE: "5-line" engine - by JRace - 02-07-2024, 05:25 PM
RE: "5-line" engine - by MasterGy - 02-07-2024, 08:27 PM
RE: "5-line" engine - by GareBear - 02-08-2024, 12:00 AM
RE: "5-line" engine - by SMcNeill - 02-08-2024, 12:15 AM
RE: "5-line" engine - by JRace - 02-08-2024, 03:43 AM
RE: "5-line" engine - by GareBear - 02-08-2024, 01:27 PM
RE: "5-line" engine - by SMcNeill - 02-08-2024, 05:13 PM
RE: "5-line" engine - by MasterGy - 02-08-2024, 05:22 PM
RE: "5-line" engine - by SMcNeill - 02-08-2024, 06:03 PM
RE: "5-line" engine - by SMcNeill - 02-08-2024, 07:12 PM
RE: "5-line" engine - by MasterGy - 02-08-2024, 11:01 PM
RE: "5-line" engine - by GareBear - 02-09-2024, 02:35 PM
RE: "5-line" engine - by SMcNeill - 02-09-2024, 03:23 PM
RE: "5-line" engine - by madscijr - 02-10-2024, 12:25 AM
RE: "5-line" engine - by GareBear - 02-09-2024, 05:48 PM
RE: "5-line" engine - by bplus - 02-09-2024, 08:42 PM
RE: "5-line" engine - by MasterGy - 02-09-2024, 09:24 PM
RE: "5-line" engine - by MasterGy - 02-09-2024, 09:51 PM
RE: "5-line" engine - by SMcNeill - 02-09-2024, 10:36 PM
RE: "5-line" engine - by MasterGy - 02-09-2024, 11:55 PM
RE: "5-line" engine - by bplus - 02-10-2024, 12:04 AM
RE: "5-line" engine - by MasterGy - 02-11-2024, 01:28 AM
RE: "5-line" engine - by SMcNeill - 02-11-2024, 01:35 AM
RE: "5-line" engine - by MasterGy - 02-11-2024, 04:22 PM
RE: "5-line" engine - by johannhowitzer - 02-12-2024, 02:41 AM
RE: "5-line" engine - by James D Jarvis - 02-15-2024, 06:59 PM
RE: "5-line" engine - by Pete - 02-16-2024, 10:05 AM
RE: "5-line" engine - by Jack - 02-16-2024, 11:06 AM



Users browsing this thread: 5 Guest(s)