Jump to content
IGNORED

How can I shorten the code of my one-line guess the number game with feedback in Family BASIC?


Recommended Posts

With some help from some other forums on the Internet, especially the NesDev forums, the code of my one-line guess the number game with feedback in Family BASIC is down to being 131 characters long (simply referred to as "the code" from now on in this comment) (solution courtesy of Controllerhead over at the NesDev forums (simply referred to as Controllerhead from now on in this comment)). Here's the code:

0N=RND(10)+1:F.T=0TO0:I."WHAT'S MY NUMBER? (1-10) ",G:T=G<>N:RES.0:F.I=0TO(-(G>N)-T):READC$:N.:?C$:N.:D.CORRECT.,TOO LOW.,TOO HIGH.

I'm looking for a shorter solution to the code. For me to accept any solution I get*:

  1. Each line of text must render below the previous line. The aforementioned code does that correctly.
  2. The same text must be printed if your code were to print the same text.
  3. I'd prefer the code to be on one line. If the code is on multiple lines, it'll be accepted, but in a different category, which might have a lesser status to me.
  4. Any solutions that break any of the other three rules can still be posted. However, I'd still rather any solutions you share fit within those rules.

Controllerhead also suggested how the code could be made shorter (quote from https://forums.nesdev.com/viewtopic.php?f=2&t=19950&p=248910#p249009, which is on the same thread Controllerhead helped me get the code down to 131 characters):

Quote

Anyway, i still think the loading / storing / displaying of the messages could be shrunk, somehow. I was hoping to just load everything into your array without having to declare each spot specifically. I noticed the DATA command in the manual, and went with that instead. I tried to avoid using the RESTORE command by declaring the DATA every time before the READ, but that didn't work. The DATA had to be at the end of the line, or its own line. The way the READ pointer is incremented now could probably be more elegant, instead of the nested FOR loop. The only real savings i ended up with was avoiding the double quotes in the responses, because of how the DATA / READ work, but i was hoping to get it down more, and i still think it can be improved, somehow...

After that, Controllerhead says they think they're probably done with looking for new solutions for now, but wishes me or anyone else luck for whoever tries to find any shorter solutions (I do.) (quote from the same NesDev forums thread, and even comment, linked to in this comment):

Quote

I think i'm probably done with this challenge, for now, but i wish you (or anyone else) luck if you pursue it further!

By the way, I'm using Family BASIC V3.0 running under Nestopia v1.40 to run the code.

P.S. Here's some documentation you could use to help me reduce the length of the code: https://gamefaqs.gamespot.com/nes/938747-family-basic-v3/faqs/59317

* Fun fact: If you can see the bold letters in the list, you should find a coincidence in the list in which the first letters of some of the points spell TIA, the name of a chip in the Atari 2600. I said the fact, partially because this website has the Atari name in it.

Does that oneliner still work, given that you reuse variable T from the endless FOR loop into a value comparison? I realize you could use any variable name for the latter.

 

This is my attempt, 118 characters. Perhaps SGN and MID$ can be abbreviated as well?

 

0N=RND(10)+1:C$="TOO LOW. CORRECT. TOO HIGH.":F.T=0TO0:I."WHAT'S MY NUMBER? (1-10) ",G:?MID$(C$,1+(SGN(G-N)+1)*9,9):N.

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...