teppermath

 

Solar System Activity - Chipmunk Basic

Page history last edited by Dan Tepper 7 mos ago

Copy and paste the following program into Chipmunk Basic and type 'run' to play. You can download Chipmunk Basic from the Internet for free.

 

100 cls

1000 rem VAR ---------------------

2000 planeta = 0

2020 planetb = 0

2040 dx = 0

2060 dy = 0

2080 x1 = 0

2100 x2 = 0

2120 x3 = 0

2140 y1 = 0

2160 y2 = 0

2180 y3 = 0

2200 daystravel = 0

2220 daysmine = 0

2240 daystot = 2

2260 per = 4

2280 deg = pi/180

2300 center = 360

2320 const = 80

2340 distshipday = 6.6

2360 distshiptot = 0

2380 distleft = 0

2420 dim xcoord(4,1085)

2440 dim ycoord(4,1085)

2500 dim visit(4)

2520 dim p$(4)

2540 s$ = " "

3000 graphics window 700,25,720,720

3010 graphics 0

3020 rem graphics cls

3030 graphics color 0,0,100

3040 graphics pensetup 1,1

3200 rem MAIN ------

3225 print "Objective is to visit each planet twice within 720 days"

3250 print "and at the same time maximize the amount of ore mined."

3275 print

3300 for i = 1 to 4

3325 print "Planet ";i;" rotation ";90*(2^(i-1));" days"

3350 next i

3375 print

4020 planetlocstore

4040 planetsetup

4060 input "Select start planet (1,2,3,4) ..  ";planeta

4070 visit(planeta) = 1

4080 while daystot-1 <= 720

4100 input "Select 'm' to mine. Select 't' to travel. ";choice$

4120 select case choice$

4140 case "t","T"

4150 input "Select dest planet (1,2,3,4) .. ";planetb

4160 while planeta = planetb

4180 input "Select dest planet (1,2,3,4)..";planetb

4200 wend

4220 travel

4240 case "m","M"

4260 mine

4280 end select

4300 wend

4320 print

4340 for i = 1 to 4

4360 print "Planet ";i;" visited ";visit(i);" times"

4364 if visit(i) < 2

4366 test = 1

4368 endif

4380 next i

4390 print

4400 if test = 1

4420 print "Mission failed"

4440 else

4460 print "Mission accomplished"

4480 endif

4500 percentmine = (int((daysminetot/720)*1000,0))/10

4520 print "Percent of days mining ";percentmine;"%"

6000 rem SUB ---------------------

6020 sub planetlocstore()

6040 for i = 1 to 4

6060 for j = 0 to 900

6080 xcoord(i,j) = i*const*cos(j*deg*per)+center

6100 ycoord(i,j) = -1*i*const*sin(j*deg*per)+center

6120 next j

6130 per = per/2

6140 next i

6160 per = 4

6180 return

8000 rem SUB ---------------------

8020 sub planetsetup()

8040 for i = 1 to 4

8080 for j = 0 to 720

8100 graphics pset xcoord(i,j),ycoord(i,j)

8120 next j

8140 next i

8145 return

9000 rem SUB -------------------------

9020 sub travel()

10040 x1 = xcoord(planeta,daystot)

10060 y1 = ycoord(planeta,daystot)

10080 x2 = xcoord(planetb,daystot)

10100 y2 = ycoord(planetb,daystot)

10120 x3 = x1

10140 y3 = y1

10160 daystravel = 0

10180 distleft = sqr((y3-y2)^2+(x3-x2)^2)

10220 while distleft > distshipday

10240 dx = abs((distshipday*(x3-x2))/distleft)

10260 dy = abs((distshipday*(y3-y2))/distleft)

10280 if x2 < x3

10300 dx = -1*dx

10320 endif

10340 if y2 < y3

10360 dy = -1*dy

10380 endif

10400 x3 = x3+dx

10420 y3 = y3+dy

10450 graphics pensetup 4,4

10451 graphics color 100,0,0

10452 graphics pset x3,y3

10453 graphics color 0,0,0

10454 graphics fillrect x3-dx,y3-dy,x3-dx+4,y3-dy+4,-1

10460 for i = 1 to 4

10480 graphics pset xcoord(i,daystot),ycoord(i,daystot)

10485 graphics fillrect xcoord(i,daystot-1),ycoord(i,daystot-1),xcoord(i,daystot-1)+4,ycoord(i,daystot-1)+4,-1

10487 graphics pensetup 1,1

10489 graphics pset xcoord(i,daystot-2),ycoord(i,daystot-2)

10491 graphics pensetup 4,4

10498 z = macfunction("wait",0.03)

10500 next i

10510 graphics pensetup 1,1

10520 x2 = xcoord(planetb,daystot)

10540 y2 = ycoord(planetb,daystot)

10560 distleft = sqr((y3-y2)^2+(x3-x2)^2)

10580 daystot = daystot+1

10600 daystravel = daystravel+1

10602 wend

10604 graphics fillrect x3,y3,x3+4,y3+4,-1

10606 graphics pensetup 4,4

10608 for i = 1 to 4

10610 if planetb = i

10612 graphics color 100,0,0

10614 graphics pset xcoord(i,daystot-1),ycoord(i,daystot-1)

10616 endif

10618 next i

10620 graphics color 0,0,0

10622 graphics pensetup 1,1

10640 daystraveltot = daystraveltot+daystravel

10650 print

10660 print "Planet ";planeta;" to planet ";planetb;" ";daystravel;" days"

10680 print "Total days traveled ";daystraveltot

10690 print "Total days mined ";daysminetot

10700 print "Total days ";daystot-2

10750 print

10760 planeta = planetb

10780 if daystot-1 <= 720

10800 visit(planetb) = visit(planetb)+1

10820 endif

11000 pset 20,20

11025 for i = 1 to 4

11050 p$(i) = visit(i)

11075 graphics drawtext p$(i)

11100 graphics drawtext s$

11125 next i

15000 return

15980 rem SUB --------------------------

16000 sub mine()

16020 if daystot-1 <= 720

16040 input "Days to mine? ";daysmine

16060 if daysmine+daystot-2 > 720

16080 daysmine = 720-(daystot-2)

16100 print "Days to mine reduced to ";daysmine

16120 endif

16215 endif

16250 graphics pensetup 4,4

16280 for j = daystot to daystot+daysmine

16290 for i = 1 to 4

16292 if planeta = i

16294 graphics color 100,0,0

16296 else

16298 graphics color 0,0,0

16299 endif

16300 graphics pset xcoord(i,j),ycoord(i,j)

16302 graphics fillrect xcoord(i,j-1),ycoord(i,j-1),xcoord(i,j-1)+4,ycoord(i,j-1)+4,-1

16304 graphics pensetup 1,1

16305 graphics color 0,0,0

16306 graphics pset xcoord(i,j-2),ycoord(i,j-2)

16308 graphics pensetup 4,4

16310 z = macfunction("wait",0.02)

16315 next i

16320 next j

16350 graphics pensetup 1,1

16365 daystot = daystot+daysmine

16375 endif

16480 daysminetot = daysminetot+daysmine

16500 daysmine = 0

16510 print

16550 print "Total days traveled ";daystraveltot

16570 print "Total days mined ";daysminetot

16590 print "Total days ";daystot-2

16660 print

16680 return

 

 

 

 

 

 

 

 

 

100 cls

1000 rem VAR ---------------------

2000 planeta = 0

2020 planetb = 0

2040 dx = 0

2060 dy = 0

2080 x1 = 0

2100 x2 = 0

2120 x3 = 0

2140 y1 = 0

2160 y2 = 0

2180 y3 = 0

2200 daystravel = 0

2220 daysmine = 0

2240 daystot = 2

2260 per = 4

2280 deg = pi/180

2300 center = 360

2320 const = 80

2340 distshipday = 6.6

2360 distshiptot = 0

2380 distleft = 0

2420 dim xcoord(4,1085)

2440 dim ycoord(4,1085)

2500 dim visit(4)

2520 dim p$(4)

2540 s$ = " "

3000 graphics window 700,25,720,720

3010 graphics 0

3020 rem graphics cls

3030 graphics color 0,0,100

3040 graphics pensetup 1,1

3200 rem MAIN ------

3225 print "Objective is to visit each planet twice within 720 days"

3250 print "and at the same time maximize the amount of ore mined."

3275 print

3300 for i = 1 to 4

3325 print "Planet ";i;" rotation ";90*(2^(i-1));" days"

3350 next i

3375 print

4020 planetlocstore

4040 planetsetup

4060 input "Select start planet (1,2,3,4).. ";planeta

4070 visit(planeta) = 1

4080 while daystot-1 <= 720

4100 input "Select 'm' to mine, 't' to travel, or 'q' to quit. ";choice$

4120 select case choice$

4125 case "q","Q"

4130 end

4140 case "t","T"

4150 input "Select dest planet (1,2,3,4) .. ";planetb

4160 while planeta = planetb or planetb < 1 or planetb > 4 or planetb <> int(planetb)

4180 input "Select dest planet (1,2,3,4) .. ";planetb

4200 wend

4220 travel

4240 case "m","M"

4260 mine

4280 end select

4300 wend

4320 print

4340 for i = 1 to 4

4360 print "Planet ";i;" visited ";visit(i);" times"

4364 if visit(i) < 2

4366 test = 1

4368 endif

4380 next i

4390 print

4400 if test = 1

4420 print "Mission failed"

4440 else

4460 print "Mission accomplished"

4480 endif

4500 percentmine = (int((daysminetot/720)*1000,0))/10

4520 print "Percent of days mining ";percentmine;"%"

6000 rem SUB ---------------------

6020 sub planetlocstore()

6040 for i = 1 to 4

6060 for j = 0 to 900

6080 xcoord(i,j) = i*const*cos(j*deg*per)+center

6100 ycoord(i,j) = -1*i*const*sin(j*deg*per)+center

6120 next j

6130 per = per/2

6140 next i

6160 per = 4

6180 return

8000 rem SUB ---------------------

8020 sub planetsetup()

8040 for i = 1 to 4

8080 for j = 0 to 720

8100 graphics pset xcoord(i,j),ycoord(i,j)

8120 next j

8140 next i

8145 return

9000 rem SUB -------------------------

9020 sub travel()

10040 x1 = xcoord(planeta,daystot)

10060 y1 = ycoord(planeta,daystot)

10080 x2 = xcoord(planetb,daystot)

10100 y2 = ycoord(planetb,daystot)

10120 x3 = x1

10140 y3 = y1

10160 daystravel = 0

10180 distleft = sqr((y3-y2)^2+(x3-x2)^2)

10220 while distleft > distshipday

10240 dx = abs((distshipday*(x3-x2))/distleft)

10260 dy = abs((distshipday*(y3-y2))/distleft)

10280 if x2 < x3

10300 dx = -1*dx

10320 endif

10340 if y2 < y3

10360 dy = -1*dy

10380 endif

10400 x3 = x3+dx

10420 y3 = y3+dy

10450 graphics pensetup 4,4

10451 graphics color 100,0,0

10452 graphics pset x3,y3

10453 graphics color 0,0,0

10454 graphics fillrect x3-dx,y3-dy,x3-dx+4,y3-dy+4,-1

10460 for i = 1 to 4

10480 graphics pset xcoord(i,daystot),ycoord(i,daystot)

10485 graphics fillrect xcoord(i,daystot-1),ycoord(i,daystot-1),xcoord(i,daystot-1)+4,ycoord(i,daystot-1)+4,-1

10487 graphics pensetup 1,1

10489 graphics pset xcoord(i,daystot-2),ycoord(i,daystot-2)

10491 graphics pensetup 4,4

10498 z = macfunction("wait",0.03)

10500 next i

10510 graphics pensetup 1,1

10520 x2 = xcoord(planetb,daystot)

10540 y2 = ycoord(planetb,daystot)

10560 distleft = sqr((y3-y2)^2+(x3-x2)^2)

10580 daystot = daystot+1

10600 daystravel = daystravel+1

10602 wend

10604 graphics fillrect x3,y3,x3+4,y3+4,-1

10606 graphics pensetup 4,4

10608 for i = 1 to 4

10610 if planetb = i

10612 graphics color 100,0,0

10614 graphics pset xcoord(i,daystot-1),ycoord(i,daystot-1)

10616 endif

10618 next i

10620 graphics color 0,0,0

10622 graphics pensetup 1,1

10640 daystraveltot = daystraveltot+daystravel

10650 print

10660 print "Planet ";planeta;" to planet ";planetb;" ";daystravel;" days"

10680 print "Total days traveled ";daystraveltot

10690 print "Total days mined ";daysminetot

10700 print "Total days ";daystot-2

10750 print

10760 planeta = planetb

10780 if daystot-1 <= 720

10800 visit(planetb) = visit(planetb)+1

10820 endif

11000 pset 20,20

11025 for i = 1 to 4

11050 p$(i) = visit(i)

11075 graphics drawtext p$(i)

11100 graphics drawtext s$

11125 next i

15000 return

15980 rem SUB --------------------------

16000 sub mine()

16020 if daystot-1 <= 720

16040 input "Days to mine? ";daysmine

16060 if daysmine+daystot-2 > 720

16080 daysmine = 720-(daystot-2)

16100 print "Days to mine reduced to ";daysmine

16120 endif

16215 endif

16250 graphics pensetup 4,4

16280 for j = daystot to daystot+daysmine

16290 for i = 1 to 4

16292 if planeta = i

16294 graphics color 100,0,0

16296 else

16298 graphics color 0,0,0

16299 endif

16300 graphics pset xcoord(i,j),ycoord(i,j)

16302 graphics fillrect xcoord(i,j-1),ycoord(i,j-1),xcoord(i,j-1)+4,ycoord(i,j-1)+4,-1

16304 graphics pensetup 1,1

16305 graphics color 0,0,0

16306 graphics pset xcoord(i,j-2),ycoord(i,j-2)

16308 graphics pensetup 4,4

16310 z = macfunction("wait",0.02)

16315 next i

16320 next j

16350 graphics pensetup 1,1

16365 daystot = daystot+daysmine

16375 endif

16480 daysminetot = daysminetot+daysmine

16500 daysmine = 0

16510 print

16550 print "Total days traveled ";daystraveltot

16570 print "Total days mined ";daysminetot

16590 print "Total days ";daystot-2

16660 print

16680 return

 

Comments (0)

You don't have permission to comment on this page.