Skip to content

Redwall MUCK Site

Sections
Personal tools
You are here: Home » Members » Riverdale's Home » Code Examples » Cartographer
« January 2009 »
Su Mo Tu We Th Fr Sa
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
 

Cartographer

A drone that explores an area and generates map data.

This code generates a bot that, once started, will explore any area with exits named for the cardinal directions (n, s, e, w) and collect information about the area. Its navigational logic is primitive, so it will sometimes spend time pacing back and forth, but I was concerned about bumping into MPI's limits on function invocations. As an example, this is a good demonstration of one of the more sophisticated things that is possible in MPI. To map the results stored by the bot, see the map file. Some example maps are here

@create Cartographer=me=laserbot
@set $laserbot=Xforcible
@flock $laserbot=me
@desc $laserbot=A bot that maps rooms.
+reg $laserbot:maploc=$lasertest:act/test
@act start;stop=$laserbot=$laserbot:start=$nothing
@lock $laserbot:start=$laserbot
@succ $laserbot:start={if:{eq:{&cmd},stop},{kill:{prop:_pid}},{null:{store:5,_x,{loc:this}},{store:100,_y,{loc:this}}}{exec!:run}}
@set $laserbot:start=run:{null:{store:{delay:2,\{lexec:scan\,{loc:this}\}\{exec:run\}},_pid}}
lsedit $laserbot=scan
.del ^ $
{func:ninety,__dir,{if:{eq:{&__dir},n},e,{if:{eq:{&__dir},s},w,{if:{eq:{&__dir},e},s,{if:{eq:{&__dir},w},n}}}}}
{with:x,{default:{prop:_explore/{loc:this}/x},{prop:_x}},
{with:y,{default:{prop:_explore/{loc:this}/y},{prop:_y}},
{with:loc,{loc:this},
{null:
	{store:
		{&loc},
		_map/1/{&y}/{&x}},
	{with:xits,{mklist:n,s,e,w},
	{with:choice,,
	{with:sel,
		{filter:xt,{&xits},
			{not:{prop!:_explore/{&loc}/{&xt}}}},
		{with:trial,1,
			{while:
				{and:
					{eq:{loc:this},{&loc}},
					{le:{&trial},8}},
				{set:choice,
					{if:{le:{&trial},{count:{&sel}}},
						{sublist:{&sel},{&trial}},
						{if:{and:
								{prop:_trend},
								{or:{not:
									{prop:_explore/{loc:this}/{ninety:{prop:_trend}}}},
								{lt:{div:
									{prop:_explore/{loc:this}/{prop:_trend}/count},
									{prop:_explore/{loc:this}/{ninety:{prop:_trend}}/count}},
								2}}},
						{prop:_trend}
						{delprop:_trend},
						{lrand:w\re\rs\rn}}}}
				{force:this,go {&choice}}
				{inc:trial}}
			{if:{gt:{subt:{&trial},{count:{&sel}}},1},
				{store:{&choice},_trend}}}
		{if:{ne:{&loc},{loc:this}},		
			{with:opp,,
				{if:{eq:{&choice},n},
					{dec:y}
					{set:opp,s},
					{if:{eq:{&choice},s},
							{inc:y}
							{set:opp,n},
							{if:{eq:{&choice},e},
								{inc:x}
								{set:opp,w},
								{if:{eq:{&choice},w},
									{dec:x}
									{set:opp,e}}}}}
				{store:{loc:this},_explore/{&loc}/{&choice}}
				{store:{add:1,{prop:_explore/{&loc}/{&choice}/count}},_explore/{&loc}/{&choice}/count}
				{store:{&loc},_explore/{loc:this}/{&opp}}
				{store:{&x},_explore/{loc:this}/x}
				{store:{&y},_explore/{loc:this}/y}
				{store:{&x},_x}
				{store:{&y},_y}}
			}}}}}}}}
.end
Created by Riverdale
Last modified 2008-08-22 06:24 PM
 

Powered by Plone

This site conforms to the following standards: