Results 1 to 6 of 6
 03132011, 01:37 PM #1Member
 Join Date
 Mar 2011
 Posts
 26
 Rep Power
 0
Two Dimensional Array Iteration Help
Hi to all,
I'm trying to implement a maze creation class which needs a method to check the adjustment blocks (diagonal) to each block in my two dimensional array.
example:
Java Code://field Block[][] maze = new Block[5][5]; //method pubic boolean chechAdj(int x, int y){ //[I]x[/I] and [I]y[/I] are the current Block's indexes. int count = 0; for(Block[] Xblocks : this.maze){ //how can I slice [I]this.maze[/I] to 1 and +1 of [I]x[/I] and [I]y[/I] [B]excluding[/B] [I]x[/I] and [I]y[/I]? for(Block block : Xblocks){ if(block.wall == true) count +=1; } } return count; }
Any help would be greatly appreciated.
Thank you in advance,
George.
 03132011, 01:50 PM #2
 Join Date
 Jan 2011
 Location
 Richmond, Virginia
 Posts
 3,069
 Blog Entries
 3
 Rep Power
 10
If you are looking for all the diagonals, manually find all of them and see if you see some pattern there.
 03132011, 01:56 PM #3Member
 Join Date
 Mar 2011
 Posts
 26
 Rep Power
 0
Thanks for the reply.
I'm just interested in the adjustment diagonal Blocks and I know that the pattern is:
for x,y < block under check,
a) x1,y1
b) x+1,y1
c) x1,y+1
d) x+1,y+1
only those four blocks are of interest to me but I can't find an appropriate way to iterate them...
 03132011, 02:35 PM #4
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,271
 Blog Entries
 7
 Rep Power
 24
 03132011, 02:36 PM #5Member
 Join Date
 Mar 2011
 Posts
 26
 Rep Power
 0
Trying to be a little clearer,
here is the equivalent of what I'm looking for in Python:Java Code:>>> l = [[i for i in range(5)] for i in range(5)] >>> for i in l: ... print i ... [0, 1, 2, 3, 4] [0, [B]1[/B], 2, [B]3[/B], 4] [0, 1, 2, 3, 4] [0, [B]1[/B], 2, [B]3[/B], 4] [0, 1, 2, 3, 4] >>> l[2][2] # this is the current block! 2 >>> def check(x,y): ... for i in l[x1:x+2:2]: # This kind of [I]list slicing[/I] is ... for j in i[y1:y+2:2]: # what I'm looking for in Java. ... print j ... >>> check(2,2) 1 3 1 3 >>>
Last edited by Stamoulohta; 03132011 at 02:45 PM. Reason: typo
 03132011, 02:39 PM #6Member
 Join Date
 Mar 2011
 Posts
 26
 Rep Power
 0
Similar Threads

2 dimensional array
By sehudson in forum New To JavaReplies: 5Last Post: 02212011, 12:56 AM 
2 dimensional array help!
By ber1023 in forum New To JavaReplies: 9Last Post: 01022011, 01:29 AM 
Two dimensional array
By niu_niu in forum New To JavaReplies: 4Last Post: 06132010, 12:34 AM 
about two dimensional array
By matin1234 in forum New To JavaReplies: 2Last Post: 06012010, 11:09 AM 
twodimensional array
By kHim in forum New To JavaReplies: 4Last Post: 11162008, 08:21 PM
Bookmarks