home *** CD-ROM | disk | FTP | other *** search
/ AMOS PD CD / amospdcd.iso / 226-250 / apd246 / nim.amos / nim.amosSourceCode
AMOS Source Code  |  1990-10-09  |  3KB  |  88 lines

  1. '
  2. ' Nim
  3. '
  4. ' (c) 1991 Jason D Banks 
  5. '
  6. ' I'm in a very good mood today - I almost locked the computer move procedure
  7. ' to drive you even further up the wall than this will!
  8. '
  9. ' Ok, given that this is a hard program to beat, I congratulate in advance,
  10. ' anyone who eventually manages to win 10 out of 10 games. 
  11. '
  12. ' Naturally, now I've said that, you'll ALL do it first time around....
  13. ' Oh by the way - it IS possible to win it - just difficult! 
  14. '
  15. _START_SYS:
  16.    NO=0 : CWIN=0 : HWIN=0 : NAM$="" : MN=21 : MX=36 : DIFF=MX-MN
  17.    Screen Open 0,320,256,8,Lowres : Curs Off : Flash Off : Pen 1 : Paper 0 : Palette Colour(1),0 : Cls 0
  18.    Input "Player Name : ";NAM$
  19.    Cls 0 : PLYR=1
  20. _START_GAME_LOOP:
  21.    NO=MN+Rnd(DIFF) : Cls 0 : Home 
  22.    If PLYR=0 Then PLYR=1 Else PLYR=0
  23. _GAME_LOOP:
  24.    If PLYR=0 Then Print "There are ";NO;" matches remaining" : Gosub _GET_HUME
  25.    If PLYR<>0 Then Gosub _GET_COMP
  26.    If PLYR=0 Then PLYR=1 Else PLYR=0
  27.    If NO<=0 Then Goto _GAME_OVER
  28. Goto _GAME_LOOP
  29. _GET_HUME:
  30.    Print "Number of matches to take [1..3]"
  31.    _GET_OPT["123"] : OPT$=Param$
  32.    NO=NO-Val(OPT$)
  33. Return 
  34. _GET_COMP:
  35.    NN=0 : Print : Print "the computer takes ";
  36.    '
  37.    ' This is the bit that makes the computer so difficult to beat.
  38.    ' It could have been written much more efficiently, there's a formula
  39.    ' I worked out for it, with something to do with (N+1)/3 in it. I think
  40.    ' so anyhow - still to make the computer easier to beat, just delete lines 
  41.    ' from the END of the routine... 
  42.    '
  43.    If NO=2 Then NN=1
  44.    If NO=3 Then NN=2
  45.    If NO=4 Then NN=3
  46.    If NO=5 Then NN=1
  47.    If NO=6 Then NN=1
  48.    If NO=7 Then NN=2
  49.    If NO=8 Then NN=3
  50.    If NO=9 Then NN=2
  51.    If NO=10 Then NN=1
  52.    If NO=11 Then NN=2
  53.    If NO=12 Then NN=3
  54.    If NO=13 Then NN=3
  55.    If NO=14 Then NN=1
  56.    If NO=15 Then NN=2
  57.    If NO=16 Then NN=3
  58.    If NO=17 Then NN=1
  59.    If NO=18 Then NN=1
  60.    If NO=19 Then NN=2
  61.    If NO=20 Then NN=3
  62.    If NO=21 Then NN=1
  63.    If NO=22 Then NN=1
  64.    If NO=23 Then NN=2
  65.    If NO=24 Then NN=3
  66.    If NO=25 Then NN=1
  67.    If NO=26 Then NN=1
  68.    If NO=27 Then NN=2
  69.    If NO=28 Then NN=3
  70.    If NN=0 Then NN=Rnd(2)+1
  71.    NO=NO-NN : Print NN;" matches."
  72. Return 
  73. Procedure _GET_OPT[TXT$]
  74.    TXT$=Upper$(TXT$) : OUT$="" : While Instr(TXT$,OUT$)<1 : OUT$=Upper$(Inkey$) : Wend 
  75. End Proc[OUT$]
  76. _GAME_OVER:
  77.    If PLYR=0 Then Inc HWIN Else Inc CWIN
  78.    Print "winner : - ";
  79.    If PLYR=0 Then Print NAM$ Else Print "Computer."
  80.    Print "Scores are :-"
  81.    Print NAM$;At(25,);HWIN
  82.    Print "COMPUTER";At(25,);CWIN
  83.    Print "Out of ";HWIN+CWIN
  84.    Print : Print "Another Game ?"
  85.    _GET_OPT["YN"] : OPT$=Param$
  86.    If OPT$="Y" Then Goto _START_GAME_LOOP
  87.    Cls 0
  88. End