![]() |
Forum Index : Microcontroller and PC projects : Reverse.bas - a Time Sink
Author | Message | ||||
Chris Roper Senior Member ![]() Joined: 19/05/2015 Location: South AfricaPosts: 280 |
My archaeological dig through long forgotten sources revealed this little gem. It is a simple game of skill originality written for the PDP11 in the early 70's and with only minor code tweaks it runs perfectly on the MicroMite. Try it, but only if you have time to waist, it is so damn addictive: [code] 80 Rem *** REVERSE WRITTEN BY BOB ALBRECHT, PEOPLE'S COMPUTER CO 90 Rem *** MODIFIED AND CONVERTED TO BASIC-PLUS BY DAVID AHL 95 Rem *** MODIFIED AND CONVERTED TO MMBASIC BY CHRIS ROPER 100 Print : Print "REVERSE -- A GAME OF SKILL" : Print 120 Randomize Timer 130 Dim A(20) 140 Rem *** N=NUMBER OF NUMBERS 150 N=9 : G=0 : T1=0 160 Input "DO YOU WANT THE RULES (YES OR NO)";AQ$ 180 If LCase$(Left$(AQ$,1))="n" Then 210 190 GoSub 710 200 Rem *** MAKE A RANDOM LIST A(1) TO A(N) 210 A(1)=Int((N-1)*Rnd)+2 220 For K=2 To N 230 A(K)=Int(N*Rnd)+1 240 For J=1 To K-1 250 If A(K)=A(J) Then 230 260 Next J : Next K 280 Rem *** PRINT ORIGNIAL LIST AND START GAME 290 Print : Print "HERE WE GO ... THE LIST IS:" 310 T=0 320 GoSub 610 330 Input "HOW MANY SHALL I REVERSE";R 340 If R=1 Then Print "OOPS! ONE DOESN'T DO ANYTHING. AGAIN..." : GoTo 330 350 If R=0 Then 530 360 If R<=N Then 390 370 Print "OOPS! TOO MANY - I CAN REVERSE AT MOST"N : GoTo 330 390 T=T+1 400 Rem *** REVERSE R NUMBERS AND PRINT NEW LIST 410 For K=1 To Int(R/2) 420 Z=A(K) 430 A(K)=A(R-K+1) 440 A(R-K+1)=Z 450 Next K 460 GoSub 610 470 Rem *** CHECK FOR A WIN 480 For K=1 To N 490 If A(K)<>K Then 330 500 Next K 510 Print "YOU WON IT IN"T" MOVES !!!" : Print 520 G=G+1 : T1=T1+T 530 Input "TRY AGAIN (YES OR NO)";AQ$ 550 If LCase$(Left$(AQ$,1))="y" Then 210 560 Print : Print "YOU PLAYED"G" GAMES AND REVERSED THE LISTS IN AN" 570 Print "AVERAGE OF"T1/G" MOVES PER GAME. HOPE YOU HAD FUN!" : GoTo 999 600 Rem *** SUBROUTINE TO PRINT LIST 610 Print : For K=1 To N : Print A(K); : Next K 650 Print : Print : Return 700 Rem *** SUBROUTINE TO PRINT THE RULES 710 Print : Print "THIS IS THE GAME OF 'REVERSE'. TO WIN, ALL YOU HAVE" 720 Print "TO DO IS ARRANGE A LIST OF NUMBERS (1 THROUGH"N")" 730 Print "IN NUMERICAL ORDER FROM LEFT TO RIGHT. TO MOVE, YOU" 740 Print "TELL ME HOW MANY NUMBERS (COUNTING FROM THE LEFT) TO" 750 Print "REVERSE. FOR EXAMPLE, IF THE CURRENT LIST IS:" 760 Print : Print "2 3 4 5 1 6 7 8 9" 770 Print : Print "AND YOU REVERSE 4, THE RESULT WILL BE:" 780 Print : Print "5 4 3 2 1 6 7 8 9" 790 Print : Print "NOW, IF YOU REVERSE 5, YOU WIN!" 800 Print : Print "1 2 3 4 5 6 7 8 9" : Print 810 Print "NO DOUBT YOU WILL LIKE THIS GAME OF SKILL, BUT" 820 Print "IF YOU WANT TO QUIT, REVERSE 0 (ZERO)." : Print : Return 999 End [/code] Cheers Chris http://caroper.blogspot.com/ |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
YOU PLAYED 6 GAMES AND REVERSED THE LISTS IN AN AVERAGE OF 11.5 MOVES PER GAME. HOPE YOU HAD FUN! Now I must force myself to stop. What a brute force way to generate the numbers 1-9 in random order! I changed that part of the code to this: 210 Rem *** MAKE A RANDOM LIST A(1) TO A(N) 220 for K = 1 to N : A(K) = K : Next K 230 for K = 1 to N 240 J = Int(N*Rnd(0))+1 'Change "Rnd(0)" to "Rnd" for MMBasic 250 tmp = A(K) : A(K) = A(J) : A(J) = tmp 260 Next K Visit Vegipete's *Mite Library for cool programs. |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1593 |
@Chris I do not want to stop your commitment, but this and many other old and new Basic programs are already available in Hugh's MMBasic Library. Just in case ... ![]() Michael causality ≠ correlation ≠ coincidence |
||||
Chris Roper Senior Member ![]() Joined: 19/05/2015 Location: South AfricaPosts: 280 |
Thanks Michael, I must admit I looked at the library when I first joined but subsequently forgot about it ![]() I wasn't really looking for games but in my research stumbled on these and had a bit of fun with them and thought others may like the diversion too. Next Time I will look in the Library before posting, but at least these have raised awareness of it ![]() Cheers Chris http://caroper.blogspot.com/ |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |