TIB: Re: TI-Basic Digest V1 #863


[Prev][Next][Index][Thread]

TIB: Re: TI-Basic Digest V1 #863




On 2001.02.17 at 12:00a, owner-ti-basic-digest@lists.ticalc.org (TI-Basic
Digest) wrote:

> Thanx for tha support. I've tried to mess round with tha random stuff, and it 
> just dosnt work for a game like this. For instance, u never want a unit to 
> move when its right next to an enemy! Also, if anyone has any pointers on a 
> moving algorithim/program or knows any good examples, i would appreciate it. 
> Like u know, from A to B, and stuff,with at least some simple logic on how to 
> get round an object (and i know random numbers wont work there). Well, 
> somebody help me out!   
>                                                                          
> Thanx!
>                                                                               
>  Stephen

You could create a matrix similar to this:

-1 -1 -1 -1 -1 -1
-1 99 99 99 99 -1
-1 99 99 99 99 -1
-1 99 99 -1 99 -1
-1 99 99 -1 99 -1
-1 99 99 99 99 -1
-1 -1 -1 -1 -1 -1

-1 is not traversable, 99 is a large number (more than max distance to an
endpoit) Then place zeros at endpoint(s) like this:

-1 -1 -1 -1 -1 -1
-1 99 99 99 99 -1
-1 99 99 99 99 -1
-1 99 99 -1 99 -1
-1 99 99 -1 99 -1
-1 99 99 99  0 -1
-1 -1 -1 -1 -1 -1

Iterate through matrix until no changes are made. If an element is > 2 of an
traversable adjacent then change the value of element to value of adjacent + 1,
repeat.

I am going from left to right, top to bottom.

After 1st iteration:

-1 -1 -1 -1 -1 -1
-1 99 99 99 99 -1
-1 99 99 99 99 -1
-1 99 99 -1 99 -1
-1 99 99 -1  1 -1
-1 99 99  1  0 -1
-1 -1 -1 -1 -1 -1

After 2nd iteration:

-1 -1 -1 -1 -1 -1
-1 99 99 99 99 -1
-1 99 99 99 99 -1
-1 99 99 -1  2 -1
-1 99 99 -1  1 -1
-1 99  2  1  0 -1
-1 -1 -1 -1 -1 -1

After 3rd iteration:

-1 -1 -1 -1 -1 -1
-1 99 99 99 99 -1
-1 99 99 99  3 -1
-1 99 99 -1  2 -1
-1 99  3 -1  1 -1
-1  3  2  1  0 -1
-1 -1 -1 -1 -1 -1

After 4th iteration:

-1 -1 -1 -1 -1 -1
-1 99 99 99  4 -1
-1 99 99  4  3 -1
-1 99  4 -1  2 -1
-1  4  3 -1  1 -1
-1  3  2  1  0 -1
-1 -1 -1 -1 -1 -1

After 5th iteration:

-1 -1 -1 -1 -1 -1
-1 99 99  5  4 -1
-1 99  5  4  3 -1
-1  5  4 -1  2 -1
-1  4  3 -1  1 -1
-1  3  2  1  0 -1
-1 -1 -1 -1 -1 -1

After 6th iteration:

-1 -1 -1 -1 -1 -1
-1 99  6  5  4 -1
-1  6  5  4  3 -1
-1  5  4 -1  2 -1
-1  4  3 -1  1 -1
-1  3  2  1  0 -1
-1 -1 -1 -1 -1 -1

After 7th iteration:

-1 -1 -1 -1 -1 -1
-1  7  6  5  4 -1
-1  6  5  4  3 -1
-1  5  4 -1  2 -1
-1  4  3 -1  1 -1
-1  3  2  1  0 -1
-1 -1 -1 -1 -1 -1


After 8th iteration:

-1 -1 -1 -1 -1 -1
-1  7  6  5  4 -1
-1  6  5  4  3 -1
-1  5  4 -1  2 -1
-1  4  3 -1  1 -1
-1  3  2  1  0 -1
-1 -1 -1 -1 -1 -1

No changes so the fast route map is:

######
#7654#
#6543#
#54#2#
#43#1#
#3210#
######

This tells you how many moves it takes to from any point to a 0 point. Just
travel to a smaller number each time.

You can make this go faster is you travel top to bottom via left to right back
to top via right to left, rather than as show (top to bottom).

To make the search faster add multiple 0 points, troops move to closes enemy,
rather than a specific one. Or some variation on this.

Good luck,

Michael Van Der Kolk
michael@michaelvdk.com
http://www.michaelvdk.com