1 Replies - 483 Views - Last Post: 26 May 2018 - 06:34 PM

#1 ociebieda   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-May 18

Detecting movement range with array

Posted 26 May 2018 - 02:40 PM

I have one dimension array like this:
0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 0,
0, 0, 0, 0, 0, 1, 1,
0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 1, 1,
0, 1, 0, 1, 1, 1, 0,
0, 1, 0, 1, 0, 0, 0,
Legend: 0 = empty floor, 1 = wall that blocks the way, 2 = starting point, 3 = floor that is possible to reach from starting point.
Movement is possible horizontally, vertically, and diagonally, if value is 0.
Example map array is 7x7 and example movement range is 3, but these parameters might be even 15x9 with 6.
What I am trying to do is getting one dimension array that shows possible movement range from chosen point like this (example range is 3 steps, and diagonal can pass between walls if position has 0 as you can see in bottom left corner):
0, 0, 0, 0, 0, 0, 0,
3, 1, 1, 1, 1, 1, 0,
3, 3, 3, 3, 3, 1, 1,
3, 3, 3, 2, 3, 3, 3,
1, 3, 3, 3, 3, 1, 1,
3, 1, 3, 1, 1, 1, 0,
0, 1, 3, 1, 0, 0, 0,
That was easier version, because it would be good if range can be limited to specified shape that can be different in one dimension mask array like this example (0 = outside range):
0, 0, 0, 1, 0, 0, 0,
0, 0, 1, 1, 1, 0, 0,
0, 1, 1, 1, 1, 1, 0,
1, 1, 1, 1, 1, 1, 1,
0, 1, 1, 1, 1, 1, 0,
0, 0, 1, 1, 1, 0, 0,
0, 0, 0, 1, 0, 0, 0,
In this case, result would be like this:
0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 0,
0, 3, 3, 3, 3, 1, 1,
3, 3, 3, 2, 3, 3, 3,
1, 3, 3, 3, 3, 1, 1,
0, 1, 3, 1, 1, 1, 0,
0, 1, 0, 1, 0, 0, 0,

<div id="results" style="font-family: monospace; font-weight: bold; font-size: 24pt; background-color: #000000; color: #FFFFFF;">
</div>
<script>
var map=[0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,1,0,1,1,1,0,0,1,0,1,0,0,0,];
var mask=[0,0,0,1,0,0,0,0,0,1,1,1,0,0,0,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,0,1,0,0,0,];

function path_create(map,width,height,point,range,mask)
{
// map = pure map with 0 as floor and 1 as wall
// width, height = size of map
// point = starting point to calculate movement range
// range = number of moves from starting point to each direction of horizontal, vertical, and diagonal
// mask = (optional) if possible to do, array mask (0 is not in range) can change range for diagonal moves with special shapes like circle or rhombus
var matrix=[];
return matrix;
// one dimension array where 0 is no range, and 1 is ok
}

function path_show(matrix,width,height)
{
var v="";
for(var i=0; i<matrix.length; i++)
{
if(i!=0 && i%7==0){v=v+"<br>";}
v=v+matrix[i]+" ";
}
document.getElementById('results').innerHTML=v;
}

path_show(path_create(map,7,7,25,3,mask));
//path_show(path_create(map,7,7,16,3,mask));
</script>



Is This A Good Question/Topic? 0
  • +

Replies To: Detecting movement range with array

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14501
  • View blog
  • Posts: 58,134
  • Joined: 12-June 08

Re: Detecting movement range with array

Posted 26 May 2018 - 06:34 PM

I'm not following - what's the question? Does the existing code not fulfill the search?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1