home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AMOS PD CD
/
amospdcd.iso
/
226-250
/
apd246
/
nim.amos
/
nim.amosSourceCode
Wrap
AMOS Source Code
|
1990-10-09
|
3KB
|
88 lines
'
' Nim
'
' (c) 1991 Jason D Banks
'
' I'm in a very good mood today - I almost locked the computer move procedure
' to drive you even further up the wall than this will!
'
' Ok, given that this is a hard program to beat, I congratulate in advance,
' anyone who eventually manages to win 10 out of 10 games.
'
' Naturally, now I've said that, you'll ALL do it first time around....
' Oh by the way - it IS possible to win it - just difficult!
'
_START_SYS:
NO=0 : CWIN=0 : HWIN=0 : NAM$="" : MN=21 : MX=36 : DIFF=MX-MN
Screen Open 0,320,256,8,Lowres : Curs Off : Flash Off : Pen 1 : Paper 0 : Palette Colour(1),0 : Cls 0
Input "Player Name : ";NAM$
Cls 0 : PLYR=1
_START_GAME_LOOP:
NO=MN+Rnd(DIFF) : Cls 0 : Home
If PLYR=0 Then PLYR=1 Else PLYR=0
_GAME_LOOP:
If PLYR=0 Then Print "There are ";NO;" matches remaining" : Gosub _GET_HUME
If PLYR<>0 Then Gosub _GET_COMP
If PLYR=0 Then PLYR=1 Else PLYR=0
If NO<=0 Then Goto _GAME_OVER
Goto _GAME_LOOP
_GET_HUME:
Print "Number of matches to take [1..3]"
_GET_OPT["123"] : OPT$=Param$
NO=NO-Val(OPT$)
Return
_GET_COMP:
NN=0 : Print : Print "the computer takes ";
'
' This is the bit that makes the computer so difficult to beat.
' It could have been written much more efficiently, there's a formula
' I worked out for it, with something to do with (N+1)/3 in it. I think
' so anyhow - still to make the computer easier to beat, just delete lines
' from the END of the routine...
'
If NO=2 Then NN=1
If NO=3 Then NN=2
If NO=4 Then NN=3
If NO=5 Then NN=1
If NO=6 Then NN=1
If NO=7 Then NN=2
If NO=8 Then NN=3
If NO=9 Then NN=2
If NO=10 Then NN=1
If NO=11 Then NN=2
If NO=12 Then NN=3
If NO=13 Then NN=3
If NO=14 Then NN=1
If NO=15 Then NN=2
If NO=16 Then NN=3
If NO=17 Then NN=1
If NO=18 Then NN=1
If NO=19 Then NN=2
If NO=20 Then NN=3
If NO=21 Then NN=1
If NO=22 Then NN=1
If NO=23 Then NN=2
If NO=24 Then NN=3
If NO=25 Then NN=1
If NO=26 Then NN=1
If NO=27 Then NN=2
If NO=28 Then NN=3
If NN=0 Then NN=Rnd(2)+1
NO=NO-NN : Print NN;" matches."
Return
Procedure _GET_OPT[TXT$]
TXT$=Upper$(TXT$) : OUT$="" : While Instr(TXT$,OUT$)<1 : OUT$=Upper$(Inkey$) : Wend
End Proc[OUT$]
_GAME_OVER:
If PLYR=0 Then Inc HWIN Else Inc CWIN
Print "winner : - ";
If PLYR=0 Then Print NAM$ Else Print "Computer."
Print "Scores are :-"
Print NAM$;At(25,);HWIN
Print "COMPUTER";At(25,);CWIN
Print "Out of ";HWIN+CWIN
Print : Print "Another Game ?"
_GET_OPT["YN"] : OPT$=Param$
If OPT$="Y" Then Goto _START_GAME_LOOP
Cls 0
End