There are many programs that can be done quickly. Suppose that you only have 15 minutes to write a computer program. What do you think you would write? Let's start a quick one. The quickest program that you can write would be a simple game. Coin flips. Heads or Tail. Or in this case, A/B buttons. The program simply checks whether or not you pushed the right buttons. It's a simple one-liner.
- ?"A/B?":WAIT 180:IF BUTTON(0)==16*RND(2) THEN "YOU WIN!" ELSE "YOU LOSE!"
Yes, it's that simple! There's nothing to it, is there? Let's take it a little more and do a simple Rock-Paper-Scissor game. Let's take a look at this table(A-B) (RPS=012):
B\A R P S
R 0 1 2
P -1 0 1
S -2 -1 0
Now, consider this: Looking at the diagonals, we see that the values are the same. zero means draw. one means win. two means lose. -1, -2 means lose, win. So, how about if we shift it up and set the range to modulus 3?
The range then becomes 0-2, 0=Win,1=Lose,2=Draw, and everything is peachy! The program then clearly writes itself:
- DIM T$(3)
- WAIT 180
- IF B AND 32 THEN A=1
- IF B AND 64 THEN A=2
- ?"YOU CHOSE ";T$(A)
- ?"I CHOOSE ";T$(B)
- IF O==0 THEN ?"YOU WIN" ELSE IF O==1 THEN ?"YOU LOSE" ELSE ?"DRAW"
That's all there is to it. Pretty quick to do and implement.
Let's keep moving on. How about random outcome? That's important in a game. However, there's something that you can do for a purely random device, such as dice. Here's a quick implementation of the Magic 8 Ball, although I don't bother putting in too many responses.
- DIM T$(6)
- T$(0)="ABSOLUTELY YES"
- T$(4)="ABSOLUTELY NOT"
- T$(5)="NO WAY JOSE!"
If the example looks lean, that's because it is. The Magic 8 Ball is quite famous. Another example, using the same structure, would be Yoda's Wisdom. Quotes of Yoda from Star Wars, presented with pictures of him is a rather entertaining program. Another one would be Bingo, or lottery, or anything random. One of my stand by program is a dice roller for playing board games.
Some games requires you to roll so many dice, and they're not all six dice, either. Let's say that you want to roll 1-4 dice, ranging from D6,D10,D20. It's a simple process using the touch screen and do it. I'm doing it quick, so there's no text. You certainly want to dress it up for practical use.
- DIM D(3)
- VSYNC 1:TX=TCHX:TY=TCHY
- FOR I=0 TO FLOOR(TX/64)
- NEXT I
- IF TCHST THEN LOCATE 0,0:?"YOU ROLL ";R;" "
- GOTO @MAIN
I actually implemented Snake and Ladder game in less than 10 minutes. One thing that is interesting about it, is that the program really doesn't require any user input other than rolling the dice. In that sense, all the activities that you do can be boiled down into rolling the dice. We can improve this further simply by letting the computer run it straight.
- IF A>100 OR B>100 THEN GOTO @END
- GOTO @MAIN
- IF A>100 THEN ?"A WINS!"
- IF B>100 THEN ?"B WINS!"
- IF A==B THEN ?"IT'S A DRAW!"
The program will resolve the race immediately. You may find it interesting to input some kind of delay in the output, so as to make it more readable as it goes.
All of these programs can be done really quick. In fact, I do these while waiting for something. Or maybe when I was in bed, trying to sleep. Most people would take a book to read in bed. I would take a Nintendo 3DS and write programs, instead.
One more quick example of the program, and this time it's useful when you're trying to do something regarding sleep: An alarm clock.
- AH=6:'ALARM HOUR
- AM=0:'ALARM MINUTE
- LOCATE 0,2:?AH;":";AM
- WAIT 60
- LOCATE 0,0:?TIME$
- IF AH==CH AND AM==CM THEN BEEP
- GOTO @MAIN
Oh, one more bonus program since not one hour has passed, yet. You know how timers have lap times? Usually, there's only one room for lap times. With this, you can have as many as you want. I'm going to limit it to just 20 for simplicity. You may modify to suit.
- VSYNC 1:T=T+1
- IF BTRIG() THEN I=I+1
- LOCATE 0,I:?I,M$;":";S$;":";J$
- IF I>=20 THEN END
- GOTO @MAIN
These programs are rough, and really, for distribution, you may want to dress them up a little. However, for something that you can doodle in 10 minutes, while waiting for something, these are perfectly suited as a pleasant time waster. Did I just do 7 programs in one hour? I guess so.