option base 1 ! randomize
graphics ! graphics clear ! draw color 0,0,0
dim vm(3),vo(3),v(3),val(9),sol(5,2)
init_prog
loop: slowdown
if bp("reset") then reset_cans(vm,v)
if bp("sol") then
reset_cans(vm,v)
for i=1 to k_ind
draw text sol(i,1) & "->" & sol(i,2) at 270-60*k_ind+120*i,820
next i
end if
get touch 0 as xt,yt ! if xt=-1 then loop
for i=1 to 3
xo=200*i-100 ! ye=700-30*vm(i)
if xt>xo and xt<xo+120 and yt<700 and yt>ye then break
next i
if i=4 then loop else pause .3
if select=0 then
draw_can(vm(i),v(i),200*i-100,700,.3)
select=i ! goto loop
end if
if select=i then
draw_can(vm(i),v(i),200*i-100,700,1)
select=0 ! goto loop
end if
q=trans(select,i) ! v(select)-=q ! v(i)+=q
draw_can(vm(select),v(select),200*select-100,700,1)
draw_can(vm(i),v(i),200*i-100,700,1)
select=0 ! pause .3
if not done then loop
end
def reset_cans(vm(),v())
for i=1 to 3 ! v(i)=.vo(i) ! next i ! draw_cans(vm,v)
end def
def draw_cans(vm(),v())
for i=1 to 3 ! draw_can(vm(i),v(i),200*i-100,700,1) ! next i
end def
def draw_can(size,vol,x,y,alfa)
t=12 ! draw size t ! draw color .3,.3,.3
h=30*size ! w=120 ! tt=t/2
fill rect x-tt+1,y+tt-1 to x+w+tt-1,y-h
draw alpha alfa ! fill alpha alfa
draw line x,y to x,y-h
draw line x-tt,y to x+w+tt,y
draw line x+w,y to x+w,y-h
draw size 2 ! draw line x-tt,y-h to x+w+tt,y-h
fill rect x+tt,y-tt to x+w-tt,y-h+2
fill color .9,.9,0
if vol then fill rect x+tt,y-tt to x+w-tt,y-30*vol
fill color 1,1,1
xm=x+60-t/2
for i=1 to size ! ym=y-30*i ! draw line xm,ym to xm+t,ym ! next i
end def
def done
for i=1 to 3 ! if .v(i)=.target then break ! next i
if i>3 then return 0
draw color 0,0,1 ! draw text .target & "!" at 200*i-58,612
return 1
end def
def bp(a$) = button_pressed(a$)
def trans(i,j) = min(.v(i),.vm(j)-.v(j))
def init_prog
for i=1 to 5 ! read .diff$(i) ! next i
for i=1 to 3 ! read .vm(i),.vo(i) ! .v(i)=.vo(i) ! next i
for i=1 to 7 ! read .val(i) ! next i
for i=1 to 5 ! for j=1 to 2 ! read .sol(i,j) ! next j ! next i
data "little kids","easy","moderate","difficult","irritating"
data 5,3, 8,5, 8,5
data 0,2,8,6,7,1,4
data 2,3, 3,1, 1,2, 3,1, 1,2
draw font size 30
draw text "Pour cans into other cans and try to get" at 20,10
draw text "the indicated quantity in one of the cans" at 20,40
draw text "with the least amount of operations." at 60,70
draw font size 20
draw text "first touch the can to pour from, then touch" at 80,110
draw text " the can to pour into" at 230,130
draw color 0,0,1
draw text "choose difficulty level" at 230,180
for i=1 to 5 ! button i text .diff$(i) at 140*i-120,220 size 120,30 ! next i
wait: slowdown
for k=1 to 5 ! if bp(""&k) then break ! next k
if k>5 then wait
button "6" title "^" at 140*k-70,260 size 20,25 ! .k_ind=k
if k=1 then .target=.val(1+rnd(3))
for i=2 to 5 ! if k=i then .target=.val(i+2) ! next i
draw font size 30
draw text "Try to produce a can with " & .target & " liters." at 50,320
draw_cans(.vm,.v)
button "reset" title "reset" at 200,740 size 120,50
button "sol" title "solution" at 400,740 size 120,50
end def
Fill a can with a given quantity (old game)
- GeorgeMcGinn
- Posts: 435
- Joined: Sat Sep 10, 2016 6:37 am
- My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10 - Location: Venice, FL
- Flag:
- Contact:
Re: Fill a can with a given quantity (old game)
This code doesn't work - it does not like the "loop" as a label. Do not know if it is because loop is a reserved word, but I changed all of them to SBloop and still got syntax errors.
Somewhere when dealing with GOTO's, I was only allowed to use numbers, even though the SB Manual says it allows any label. So I changed then to linenumbers and it also failed with a syntax error.
Is there another version of this program?
What have I done wrong in running this?
Thanks
Somewhere when dealing with GOTO's, I was only allowed to use numbers, even though the SB Manual says it allows any label. So I changed then to linenumbers and it also failed with a syntax error.
Is there another version of this program?
What have I done wrong in running this?
Thanks
Henko wrote: ↑Sun Jun 04, 2017 10:04 amoption base 1 ! randomize
graphics ! graphics clear ! draw color 0,0,0
dim vm(3),vo(3),v(3),val(9),sol(5,2)
init_prog
loop: slowdown
if bp("reset") then reset_cans(vm,v)
if bp("sol") then
reset_cans(vm,v)
for i=1 to k_ind
draw text sol(i,1) & "->" & sol(i,2) at 270-60*k_ind+120*i,820
next i
end if
get touch 0 as xt,yt ! if xt=-1 then loop
for i=1 to 3
xo=200*i-100 ! ye=700-30*vm(i)
if xt>xo and xt<xo+120 and yt<700 and yt>ye then break
next i
if i=4 then loop else pause .3
if select=0 then
draw_can(vm(i),v(i),200*i-100,700,.3)
select=i ! goto loop
end if
if select=i then
draw_can(vm(i),v(i),200*i-100,700,1)
select=0 ! goto loop
end if
q=trans(select,i) ! v(select)-=q ! v(i)+=q
draw_can(vm(select),v(select),200*select-100,700,1)
draw_can(vm(i),v(i),200*i-100,700,1)
select=0 ! pause .3
if not done then loop
end
def reset_cans(vm(),v())
for i=1 to 3 ! v(i)=.vo(i) ! next i ! draw_cans(vm,v)
end def
def draw_cans(vm(),v())
for i=1 to 3 ! draw_can(vm(i),v(i),200*i-100,700,1) ! next i
end def
def draw_can(size,vol,x,y,alfa)
t=12 ! draw size t ! draw color .3,.3,.3
h=30*size ! w=120 ! tt=t/2
fill rect x-tt+1,y+tt-1 to x+w+tt-1,y-h
draw alpha alfa ! fill alpha alfa
draw line x,y to x,y-h
draw line x-tt,y to x+w+tt,y
draw line x+w,y to x+w,y-h
draw size 2 ! draw line x-tt,y-h to x+w+tt,y-h
fill rect x+tt,y-tt to x+w-tt,y-h+2
fill color .9,.9,0
if vol then fill rect x+tt,y-tt to x+w-tt,y-30*vol
fill color 1,1,1
xm=x+60-t/2
for i=1 to size ! ym=y-30*i ! draw line xm,ym to xm+t,ym ! next i
end def
def done
for i=1 to 3 ! if .v(i)=.target then break ! next i
if i>3 then return 0
draw color 0,0,1 ! draw text .target & "!" at 200*i-58,612
return 1
end def
def bp(a$) = button_pressed(a$)
def trans(i,j) = min(.v(i),.vm(j)-.v(j))
def init_prog
for i=1 to 5 ! read .diff$(i) ! next i
for i=1 to 3 ! read .vm(i),.vo(i) ! .v(i)=.vo(i) ! next i
for i=1 to 7 ! read .val(i) ! next i
for i=1 to 5 ! for j=1 to 2 ! read .sol(i,j) ! next j ! next i
data "little kids","easy","moderate","difficult","irritating"
data 5,3, 8,5, 8,5
data 0,2,8,6,7,1,4
data 2,3, 3,1, 1,2, 3,1, 1,2
draw font size 30
draw text "Pour cans into other cans and try to get" at 20,10
draw text "the indicated quantity in one of the cans" at 20,40
draw text "with the least amount of operations." at 60,70
draw font size 20
draw text "first touch the can to pour from, then touch" at 80,110
draw text " the can to pour into" at 230,130
draw color 0,0,1
draw text "choose difficulty level" at 230,180
for i=1 to 5 ! button i text .diff$(i) at 140*i-120,220 size 120,30 ! next i
wait: slowdown
for k=1 to 5 ! if bp(""&k) then break ! next k
if k>5 then wait
button "6" title "^" at 140*k-70,260 size 20,25 ! .k_ind=k
if k=1 then .target=.val(1+rnd(3))
for i=2 to 5 ! if k=i then .target=.val(i+2) ! next i
draw font size 30
draw text "Try to produce a can with " & .target & " liters." at 50,320
draw_cans(.vm,.v)
button "reset" title "reset" at 200,740 size 120,50
button "sol" title "solution" at 400,740 size 120,50
end def
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)
-
- Posts: 816
- Joined: Tue Apr 09, 2013 12:23 pm
- My devices: iPhone,iPad
Windows - Location: Groningen, Netherlands
- Flag:
Re: Fill a can with a given quantity (old game)
This is very strange.
I copied the code back from the posting into my SB app (as you have done, i suppose) and it worked correctly.
This is cumbersome, as i cannot reproduce the erronuous functioning.
Possibly your SB app has become corrupted in some way. If you have another SB app on another iOS device, you might try to run the game there and check if it is indeed a corrupted SB app.
Henk
I copied the code back from the posting into my SB app (as you have done, i suppose) and it worked correctly.
This is cumbersome, as i cannot reproduce the erronuous functioning.
Possibly your SB app has become corrupted in some way. If you have another SB app on another iOS device, you might try to run the game there and check if it is indeed a corrupted SB app.
Henk
- GeorgeMcGinn
- Posts: 435
- Joined: Sat Sep 10, 2016 6:37 am
- My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10 - Location: Venice, FL
- Flag:
- Contact:
Re: Fill a can with a given quantity (old game)
Hi Henk,
I redownloaded the code after showing it works and it now works, so I must have not copied it correctly the first time.
Thanks for looking into it. I love this game too.
George,
I redownloaded the code after showing it works and it now works, so I must have not copied it correctly the first time.
Thanks for looking into it. I love this game too.
George,
Henko wrote: ↑Wed Jun 07, 2017 7:03 amThis is very strange.
I copied the code back from the posting into my SB app (as you have done, i suppose) and it worked correctly.
This is cumbersome, as i cannot reproduce the erronuous functioning.
Possibly your SB app has become corrupted in some way. If you have another SB app on another iOS device, you might try to run the game there and check if it is indeed a corrupted SB app.
Henk
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)