`strategy challenge version 0.000000000000001 by Ric
sync on
sync rate 100
color backdrop 0
autocam off
position camera 0,0,-50
hide light 0
set ambient light 10
make light 1
position light 1,-30,80,-50
 
 
 
 
ink rgb(0,0,80),0
box 0,0,100,100
ink 0,0
box 2,2,98,98
get image 1000,0,0,100,100
 
make object sphere 1000,-1000,20,20
texture object 1000,1000
scale object texture 1000,15,15
xrotate object 1000,90
set object light 1000,0
 
ink rgb(120,120,255),0
set text font "sf automaton_mod"
set text size 20
 
for sphere=1 to 20
make object sphere sphere,5,30,30
red=rnd(1)*255
green=rnd(1)*255
blue=rnd(1)*255
color object sphere,rgb(red,green,blue)
set object specular power sphere,20
set object specular sphere,rgb(200,200,200)
next sphere
 
 
start:
 
for sphere=1 to 20
show object sphere
next sphere
 
number=20
 
sync
text 0,0,"Aim of the game:  Each player removes 1, 2 or 3 balls in turn."
text 0,20,"The winner is the one who removes the last ball."
text 0,60,"Press Space to start."
sync
wait key
 
playergo=rnd(1)
if playergo=0
  computergo=1
  text 0,0,"I'll go first"
else
  text 0,0,"You go first"
endif
sync
wait 1000
 
 
 
do
 
if playergo=1 then gosub playergo
if computergo=1 then gosub computergo
 
rotation#=wrapvalue(rotation#)+0.5
for sphere=1 to 20
position object sphere,20*sin((360/20)*sphere+rotation#),20*cos((360/20)*sphere+rotation#),0
next sphere
scroll object texture 1000,0.02,0.02
text 0,400,"score - Me:"+str$(compscore)+"  You:"+str$(playerscore)
sync
loop
 
 
playergo:
 
  text 0,40,"Your go: How many do you want to remove? (1, 2 or 3): "
 
 
if scancode()>0 and scancode()<5 and scancode()<=number+1
  remove=scancode()-1
  number=number-remove
  for sphere=number+1 to 20
    hide object sphere
  next sphere
  if number=0 then text 0,100,"You win!":sync:wait 2000:inc playerscore:goto start
  playergo=0:computergo=1
endif
 
return
 
computergo:
 
if waitabit=0
 
    repeat
    if number/4.0 = int(number/4)
      remove=(rnd(2)+1)
    else
      calculatebestnumber=number
      repeat
        dec calculatebestnumber
      until calculatebestnumber/4.0 = int(calculatebestnumber/4)
      remove=number-calculatebestnumber
    endif
  until remove<=number
endif
 
text 0,40, "My go: I will remove "+str$(remove)+" balls"
 
inc waitabit
 
if waitabit>300
  number=number-remove
  for sphere=number+1 to 20
  hide object sphere
  next sphere
  if number=0 then text 0,100,"I win!":sync:wait 2000:inc compscore:goto start
  playergo=1
  computergo=0
  waitabit=0
endif
 
return