|
Post by bluatigro on Feb 1, 2022 8:25:42 GMT -5
this is a idea from the ai book i fount on www.ai.hcc.nlnieuws page click on 3de editie to see the content senario : you have a dirty room you have a automatuic cleaner control the cleaner whit a program the room has 2 spots you dont know were the cleaner starts error : the cleaner does not move the dirt is misteroisly disapperd WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
dim actie( 1 , 1 )
dim dirt( 1 ) , place.name$( 1 )
global vacstate , isleft , isright , goleft , goright , suck
global true , false , place , start
''actie :
isleft = 1
isright = 2
goleft = 3
goright = 4
suck = 16
''bool's
false = 0
true = not( false )
''dirt
dirt( 0 ) = 10
dirt( 1 ) = 10
nomainwin
open "h2 vacum cleaner ." for graphics as #m
#m "trapclose [quit]"
[q]
prompt "witch startplace ? type a or b" ; in$
start = instr( "ab" , in$ )
if start = 0 then goto [q]
start = start - 1
place = 100 + start * 200
if start = 1 then
vacstate = isright
else
vacstate = isleft
end if
call room
notice "start sim"
'' timer 200 , [tmr]
wait
sub room
#m "fill white"
''draw dirt
for p = 0 to 1
for i = 0 to dirty( p )
#m "down"
#m "place " ; 100 + 200 * p + i * 10 ; " " ; winy - 100
#m "circlefilled 3"
#m "up"
next i
next p
''draw vacum cleaner
#m "down"
#m "place " ; place ; " " ; winy - 120
if vacstate and suck then
#m "backcolor red"
else
#m "backcolor black"
end if
#m "circlefilled 20"
#m "up"
end sub
[tmr]
select case vacstate and 15
case isleft
if dirt( 0 ) >= 1 then
dirt( 0 ) = dirt( 0 ) - 1
vacstate = vacstate or suck
else
if dirt( 1 ) <= 0 then
vacstate = 0
else
vacstate = goright
end if
end if
case goright
place = place + 5
if place >= 300 then
vacstate = isright
end if
case isright
if dirt( 1 ) >= 0 then
dirt( 1 ) = dirt( 1 ) - 1
vacstate = vacstate or suck
else
if dirt( 1 ) <= 0 then
vacstate = 0
else
vacstate = goleft
end if
end if
case goleft
place = place - 5
if place <= 100 then
vacstate = isright
end if
case else
timer 0
notice "ready cleaning room ."
end
end select
call room
wait
[quit]
close #m
end
|
|
|
Post by Rod on Feb 1, 2022 8:57:34 GMT -5
You are just sitting at a wait statement, you took out the timer because of the subs so you need to direct the program flow.
|
|
|
Post by Rod on Feb 1, 2022 14:35:10 GMT -5
Strikes me the fill algorithm would be the thing to use to get the cleaner to cover the whole floor methodically. This function won't run but it is based on the classic flood fill routine at Rosetta Code.
function floodfill(x,y,tcol$) 'recursive flood fill function see rosetta code if tcol$ = fcol$ then exit function if x>=npix or y >=npix or x<0 or y<0 then exit function if frame$(x,frame*npix+y) <> tcol$ then exit function else null=paint(x,y) end if nul=floodfill(x,y+1,tcol$) nul=floodfill(x,y-1,tcol$) nul=floodfill(x-1,y,tcol$) nul=floodfill(x+1,y,tcol$) end function
|
|
|
Post by bluatigro on Feb 2, 2022 5:18:28 GMT -5
try 2
error : the animation is not good jet
try start a and b to see for yourself
where does those pesky whit lines come from ?
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
dim actie( 1 , 1 )
dim dirt( 1 ) , place.name$( 1 )
global vacstate , isleft , isright , goleft , goright , suck
global true , false , place , start
''actie :
isleft = 1
isright = 2
goleft = 3
goright = 4
suck = 16
''bool's
false = 0
true = not( false )
''dirt
dirt( 0 ) = 10
dirt( 1 ) = 10
nomainwin
open "h2 vacum cleaner ." for graphics as #m
#m "trapclose [quit]"
[q]
prompt "witch startplace ? type a or b" ; in$
start = instr( "ab" , in$ )
if start = 0 then goto [q]
start = start - 1
place = 100 + start * 200
if start = 1 then
vacstate = isright
else
vacstate = isleft
end if
call room
notice "start sim"
timer 200 , [tmr]
wait
sub room
#m "fill white"
''draw dirt
for p = 0 to 1
for i = 0 to dirt( p )
#m "down"
#m "place " ; 100 + 200 * p + i * 10 ; " " ; winy - 100
#m "circlefilled 3"
#m "up"
next i
next p
''draw vacum cleaner
#m "down"
#m "place " ; place ; " " ; winy - 120
if vacstate and suck then
#m "backcolor red"
else
#m "backcolor black"
end if
#m "circlefilled 20"
#m "up"
end sub
[tmr]
select case vacstate and 15
case isleft
if dirt( 0 ) >= 1 then
dirt( 0 ) = dirt( 0 ) - 1
vacstate = vacstate or suck
else
if dirt( 1 ) <= 0 then
vacstate = 0
else
vacstate = goright
end if
end if
case goright
place = place + 5
if place >= 300 then
vacstate = isright
end if
case isright
if dirt( 1 ) >= 0 then
dirt( 1 ) = dirt( 1 ) - 1
vacstate = vacstate or suck
else
if dirt( 1 ) <= 0 then
vacstate = 0
else
vacstate = goleft
end if
end if
case goleft
place = place - 5
if place <= 100 then
vacstate = isright
end if
case else
timer 0
notice "ready cleaning room ."
end
end select
call room
wait
[quit]
close #m
end
|
|
|
Post by bluatigro on Feb 8, 2022 5:07:47 GMT -5
try 4
error : WARNING crtl+alt+del did not work !!
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy winx = WindowWidth winy = WindowHeight dim dirt( 1 ) global vacstate , isleft , isright , goleft , goright , suck global true , false , place , start ''actie : isleft = 1 isright = 2 goleft = 3 goright = 4 ''bool's false = 0 true = not( false ) ''dirt dirt( 0 ) = 10 dirt( 1 ) = 10 nomainwin open "h2 vacum cleaner ." for graphics as #m #m "trapclose [quit]" [q] prompt "witch startplace ? type a or b" ; in$ start = instr( "ab" , in$ ) if start = 0 then goto [q] start = start - 1 place = 100 + start * 200 if start = 1 then vacstate = isright else vacstate = isleft end if call room notice "start sim" timer 200 , [tmr] wait
sub room #m "fill white" ''draw dirt for p = 0 to 1 for i = 0 to dirt( p ) #m "down" #m "place " ; 100 + 200 * p + i * 10 ; " " ; winy - 100 #m "circlefilled 3" #m "up" next i next p ''draw vacum cleaner #m "down" #m "place " ; place ; " " ; winy - 120 if suck then #m "backcolor red" else #m "backcolor black" end if #m "circlefilled 20" #m "up" end sub [tmr] select case vacstate case isleft if dirt( 0 ) >= 1 then dirt( 0 ) = dirt( 0 ) - 1 suck = true else if dirt( 1 ) <= 0 then vacstate = 0 else vacstate = goright suck = false end if end if case goright place = place + 5 if place >= 300 then vacstate = isright end if case isright if dirt( 1 ) >= 0 then dirt( 1 ) = dirt( 1 ) - 1 suck = true else if dirt( 0 ) <= 0 then vacstate = 0 else vacstate = goleft suck = false end if end if case goleft place = place - 5 if place <= 100 then vacstate = isleft end if case else timer 0 notice "ready cleaning room ." end end select call room wait [quit] close #m end
|
|
|
Post by theulimateunltd on Feb 8, 2022 15:39:29 GMT -5
I suggest you clean the code before the room. global winx, winy, vacstate, isleft, _ isright, goleft, goright, suck, _ true, false, place, start
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
winx = WindowWidth
winy = WindowHeight
REM actie :
isleft = 1
isright = 2
goleft = 3
goright = 4
REM bool's
false = 0
true = not( false )
REM dirt
dirt( 0 ) = 10
dirt( 1 ) = 10
nomainwin
open "h2 vacum cleaner ." for graphics as #m
#m "trapclose [quit]"
[q]
prompt "witch startplace ? type a or b" ; in$
start = instr( "ab" , in$ )
if start = 0 then goto [q]
start = start - 1
place = 100 + start * 200
if start = 1 then
vacstate = isright
else
vacstate = isleft
end if
call room
notice "start sim"
timer 200 , [tmr]
wait
sub room
#m "fill white"
REM draw dirt
for p = 0 to 1
for i = 0 to dirt( p )
#m "down"
#m "place " ; 100 + 200 * p + i * 10 ; " " ; winy - 100
#m "circlefilled 3"
#m "up"
next i
next p
REM draw vacum cleaner
#m "down"
#m "place " ; place ; " " ; winy - 120
if suck then
#m "backcolor red"
else
#m "backcolor black"
end if
#m "circlefilled 20"
#m "up"
end sub
[tmr]
select case vacstate
case isleft
if dirt( 0 ) >= 1 then
dirt( 0 ) = dirt( 0 ) - 1
suck = true
else
if dirt( 1 ) <= 0 then
vacstate = 0
else
vacstate = goright
suck = false
end if
end if
case goright
place = place + 5
if place >= 300 then
vacstate = isright
end if
case isright
if dirt( 1 ) >= 0 then
dirt( 1 ) = dirt( 1 ) - 1
suck = true
else
if dirt( 0 ) <= 0 then
vacstate = 0
else
vacstate = goleft
suck = false
end if
end if
case goleft
place = place - 5
if place <= 100 then
vacstate = isleft
end if
case else
timer 0
notice "ready cleaning room ."
close #m
end
end select
call room
wait
[quit]
close #m
end
|
|
|
Post by bluatigro on Feb 20, 2022 6:32:03 GMT -5
UPDATE : i fount the error
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy winx = WindowWidth winy = WindowHeight dim dirt( 1 ) global vacstate , isleft , isright , goleft , goright , suck global true , false , place , start ''actie : isleft = 1 isright = 2 goleft = 3 goright = 4 suck = 16 ''bool's false = 0 true = not( false ) ''dirt dirt( 0 ) = 10 dirt( 1 ) = 10 nomainwin open "h2 vacum cleaner ." for graphics as #m #m "trapclose [quit]" [q] prompt "witch startplace ? type a or b" ; in$ start = instr( "ab" , in$ ) if start = 0 then goto [q] start = start - 1 place = 100 + start * 200 if start = 1 then vacstate = isright else vacstate = isleft end if call room notice "start sim" timer 200 , [tmr] wait
sub room #m "fill white" ''draw dirt for p = 0 to 1 for i = 0 to dirt( p ) #m "down" #m "place " ; 100 + 200 * p + i * 10 ; " " ; winy - 100 #m "circlefilled 3" #m "up" next i next p ''draw vacum cleaner #m "down" #m "place " ; place ; " " ; winy - 120 if vacstate and suck then #m "backcolor red" else #m "backcolor black" end if #m "circlefilled 20" #m "up" end sub [tmr] select case vacstate and 15 case isleft if dirt( 0 ) >= 1 then dirt( 0 ) = dirt( 0 ) - 1 vacstate = vacstate or suck else if dirt( 1 ) <= 0 then vacstate = 0 else vacstate = goright end if end if case goright place = place + 5 if place >= 300 then vacstate = isright end if case isright if dirt( 1 ) >= 0 then dirt( 1 ) = dirt( 1 ) - 1 vacstate = vacstate or suck else if dirt( 0 ) <= 0 then vacstate = 0 else vacstate = goleft end if end if case goleft place = place - 5 if place <= 100 then vacstate = isright end if case else timer 0 notice "ready cleaning room ." CLOSE #m '<<<< THIS WAS I FORGOTEN end end select call room wait [quit] close #m end
|
|
|
Post by tsh73 on Feb 20, 2022 7:08:57 GMT -5
then started from room A it cleaned left then right Then started from B it cleaned right then run away %)
|
|