20 Line Programming Challenge

Anything QL Software or Programming Related.
User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: 20 Line Programming Challenge

Post by dilwyn »

Just to stay one step ahead of Mr Navigator :D here's another effort. This is a Guess The Animal game where you have to think of an animal and the computer tries to guess it. As it fails to guess the answer it asks more questions to help it distinguish between the various animals, e.g. does it go moo would have na answer of y for yes for a cow but no for a pig. The longer you play it, the bigger the database becomes and the better it becomes at guessing everything. If the facility to save the database was added (aw, come on, i'm only allowed 20 lines!) it would rapidly build up a good knowledge of the animal world. Trivial as it stands, I guess it could be taught to ask medical questions to become an expert at diagnosing illnesses by asking all sorts of Yes/No questions. It's adapted from a much longer program I wrote back in 1985 IIRC :roll:

Code: Select all

100 REMark Guess The Animal: think of an animal,computer guesses it
110 CLS : CLS #0 : DIM question$(50,56),p(50,2) : free = 2
120 question$(1)='a monster' : num=1 : REMark start from somewhere,I suppose
130 PRINT'Think of an animal, computer will try to guess it and learn from replies.'\\
140 REPeat ask
150   IF p(num,1) = 0 THEN
160     PRINT'Is it ';question$(num);'?'
170     IF INKEY$(-1)=='y' THEN
180       PRINT'I knew that!'\\'Think of an animal' : REMark a correct guess
190     ELSE
200       question$(free) = question$(num) : INPUT'What was it?';question$(free+1)
210       INPUT'Enter a question to distinguish between them:';question$(num)
220       PRINT'What is the answer for ';question$(free+1);'?'
230       IF INKEY$(-1) == 'y' THEN p(num,1) = free + 1 : p(num,2) = free:ELSE p(num,1) = free : p(num,2) = free+1
240       free = free + 2 : PRINT'A new one!'\\'Think of an animal'
250     END IF : num = 1
260   ELSE
270     PRINT question$(num);'?' : IF INKEY$(-1) == 'y' THEN num = p(num,1) : ELSE num = p(num,2)
280   END IF
290 END REPeat ask
animals.jpg


User avatar
Mr_Navigator
QL Fanatic
Posts: 782
Joined: Mon Dec 13, 2010 11:17 pm
Location: UK, Essex
Contact:

Re: 20 Line Programming Challenge

Post by Mr_Navigator »

Hey DJ, it's not a competition you know...









oh wait a minute, yes it is :lol:


-----------------------------------------------------------------------------------
QLick here for the Back 2 the QL Blog http://backtotheql.blogspot.co.uk/
User avatar
vanpeebles
Commissario Pebbli
Posts: 2821
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

Re: 20 Line Programming Challenge

Post by vanpeebles »

I think you're getting beaten up a bit :lol:


RWAP
RWAP Master
Posts: 2837
Joined: Sun Nov 28, 2010 4:51 pm
Location: Stone, United Kingdom
Contact:

Re: 20 Line Programming Challenge

Post by RWAP »

A guess the animal program was even sold as a commercial title back in the day !

It was however, written in Archive BASIC - see http://www.rwapadventures.com/ql_wiki/i ... AL&lang=en

Now if only I had time to do some QL programming - I am sure we could manage a cut down space invaders in 20 lines... (although it would be slow...!)


User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: 20 Line Programming Challenge

Post by dilwyn »

My original was on a PD disk from CGH Services.
There was an expanded version and databases, but I can't get the disk to fully read on my PC.
If I can get my ED drives and QL set up, I might be able to copy and rescue it and put it on my website as I don't think it's there already.
At the time, there was a lot of Animal-type program listings as there was a lot of interest in AI-type programs back then (not that this one is in any way intelligent!)
Space Invaders in 20 lines, now there's a challenge... :geek:
Get out the old ZX81 books and adapt a 1K space invaders, that should be fun.

Dilwyn


User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: 20 Line Programming Challenge

Post by dilwyn »

RWAP wrote:Now if only I had time to do some QL programming - I am sure we could manage a cut down space invaders in 20 lines... (although it would be slow...!)
Did someone say a cut down space invaders in 20 lines?
OK, here's one. Sound effects and all. Just about makes it into 20 lines at the cost of some long lines.
Press cursor left or right to move your base laser left/right. Press space to fire at the invaders. They may fire back at you from time to time.
It's a bit c**p really, but just about meets the suggestion, crying out for someone to improve it (too tired to do more work on it tonight). Now to see if I can remember how to put the code, zip attachment and screen in...
100 REMark (very) cut-down invaders by Dilwyn Jones
110 WINDOW 484,252,0,0:BORDER 1,255 : CLS : CSIZE 2,0
120 inv$ = ' X X X X X X ' : invdrs=6 : basex = RND(0 TO 39) : invy = 1 : invx = 0 : direc = 1 : firey = 25 : AT 24,basex:PRINT'A'; : speed%=10 :speedcount%=speed%:AT invy,invx:PRINT inv$; : bomby = 0
130 REPeat program
140 key = CODE(INKEY$(1)) : IF key=32 THEN IF firey = 25 THEN firey=23 : firex = basex : END IF : END IF
150 IF key=192 OR key = 200 THEN AT 24,basex:PRINT' ';: basex = basex-(key=192 AND basex>0)+(key=200 AND basex<39) : AT 24,basex : PRINT'A'; : END IF
160 IF firey < 25 THEN
170 AT firey,firex : PRINT' ';
180 IF firey = invy THEN
190 IF firex >= invx AND firex<(invx+22) THEN IF inv$(firex-invx+1) = 'X' THEN BEEP 2000,10 : inv$(firex-invx+1) = ' ' : AT firey,firex : PRINT '*'; : invdrs = invdrs-1 : PAUSE 2 : AT firey,firex : PRINT' '; : firey = 25 : END IF : REMark hit invader
200 END IF
210 END IF
220 IF firey < 25 THEN firey = firey-1 : IF firey < 0 THEN firey = 25 : ELSE AT firey,firex : PRINT '|'; : END IF : END IF : speedcount% = speedcount%-1
230 IF speedcount%<1 THEN BEEP 10,50:speedcount% = speed% :invx = invx+direc:IF invx > (40-LEN(inv$)) THEN invx = 40-LEN(inv$): AT invy,invx : PRINT FILL$(' ',LEN(inv$));:direc=-direc:invy=invy+1:ELSE IF invx<0 THEN direc=-direc : invx = 0 : AT invy,invx : PRINT FILL$(' ',LEN(inv$)); : invy = invy+1:END IF : AT invy,invx : PRINT inv$; : END IF
240 IF bomby > 0 THEN AT bomby,bombx : PRINT ' '; : bomby = bomby+1 : AT bomby,bombx : PRINT'#'; : END IF : IF bomby > 23 THEN IF bombx = basex THEN BEEP 5000,50 : AT 0,0 : PRINT'Oops, the aliens got you...' : EXIT program : ELSE AT 24,bombx : PRINT' ';:bomby=0:END IF
250 IF bomby = 0 AND RND(1 TO 100) = 1 THEN
260 no=RND(1 TO invdrs):FOR x=1 TO LEN(inv$):IF inv$(x)='X' THEN no=no-1:IF no<=1 THEN bombx=x+invx-1: bomby=invy+1:AT bomby,bombx:PRINT'#';:EXIT x:END IF :END FOR x
270 END IF
280 IF inv$ = FILL$(' ',LEN(inv$)) THEN AT 0,0 : PRINT'Congratulations - you saved earth!!!' : EXIT program : REMark won
290 IF invy = 24 THEN BEEP 5000,20,70,50,1 : AT 0,0 : PRINT'Oops, the aliens landed.' : EXIT program:REMark landed
300 END REPeat program
invaders20_bas.zip
invaders20.jpg


thorsinclair
Trump Card
Posts: 199
Joined: Mon Jan 10, 2011 5:08 pm

Re: 20 Line Programming Challenge

Post by thorsinclair »

Hi all,

Congratulations to the programmers! Very well done and very interesting. To support your efforts, today I sat down for a couple of hours and pixeled the original Space Invader Sprites - as can be found in the original Arcade Edition - using DP's Super Sprite Generator. I was doing this on QEmulator on my Mac and it was a bit of a mess as the screen is not always looking as it should, but anyway, it was also great fun. I try to post the sprites, partly animated, attached as a ZIP file and I hope that somebody can pick them up and do the real deal - coding the game :mrgreen:
.... just found the original artwork of Galaga .... hmmm .. worth a try I think.

I would be interested if DPs Super Sprite Generator is the best tool to create animated sprites with frames etc. or if there is a better piece of software around. Can somebody let me know? Thanks.
Best,
Thor
Space Invaders Sprites.zip
Space Invaders Sprites
(15.42 KiB) Downloaded 290 times


User avatar
Mr_Navigator
QL Fanatic
Posts: 782
Joined: Mon Dec 13, 2010 11:17 pm
Location: UK, Essex
Contact:

Re: 20 Line Programming Challenge

Post by Mr_Navigator »

I found problems running this software on Qemulator, the X-axis was jumping by 4 pixels at a time, how does yours fair?

See
http://www.qlforum.co.uk/viewtopic.php? ... ator#p764


-----------------------------------------------------------------------------------
QLick here for the Back 2 the QL Blog http://backtotheql.blogspot.co.uk/
thorsinclair
Trump Card
Posts: 199
Joined: Mon Jan 10, 2011 5:08 pm

Re: 20 Line Programming Challenge

Post by thorsinclair »

I just did the artwork Job with this sprites using the Design and Construct programs. I tried the Demo program and noticed that it is flickering a lot which apparently is caused by the 4 pixels a time movements you have experienced. It's far from smooth movements ... Do you know any other sprite packages you know of?

Cheers
Thor


User avatar
Mr_Navigator
QL Fanatic
Posts: 782
Joined: Mon Dec 13, 2010 11:17 pm
Location: UK, Essex
Contact:

Re: 20 Line Programming Challenge

Post by Mr_Navigator »

I am afraid not as I would like to do more in this area but SSG doesn't cut the mustard for me RWAP did mention at one point I think, that there were other(s). However this is going off topic for the post :)


-----------------------------------------------------------------------------------
QLick here for the Back 2 the QL Blog http://backtotheql.blogspot.co.uk/
Post Reply