Re: ideas for grid scanning system?
Oops, made a mistake in my example. Should have put in a way to keep track of previously scanned tiles, so:
def gridcheck():
# based on an implementation by Eric S. Raymond
x = 5
y = 5
tile_id = grid[y][x] test = grid[:] connected = [[x,y]] edge = [(x, y)] while edge: newedge = [] for (x, y) in edge: for (s, t) in ((x+1, y), (x-1, y), (x, y+1), (x, y-1)): try: p = test[t][s] except IndexError: pass else: if p == tile_id: test[t][s] = 99 connected.append([s,t]) newedge.append((s, t)) edge = newedge return connected
I've taken a bit of time looking over your code and I think I can offer a solution, haven't played with BGT before so appologies if it implodes, heh.
void examine(int a, int b) {
int target=board[a][b];
int temp_board=board;
vector[] remove;
vector[] tmp;
processed = tmp;
vector new;
new.x=a;
new.y=b;
remove.insert_last(new);
processed.insert_last(new);
temp_board[a][b] = 99;
while(remove.length()>0) {
vector[] new_remove;
for(int c=0; c<remove.length(); c++) {
vector new;
new.x=remove[c].x;
new.y=remove[c].y;
if(new.x-1>0) {
if(temp_board[new.x-1][new.y]==target) {
vector temp;
temp.x=new.x-1;
temp.y=new.y;
new_remove.insert_last(temp);
processed.insert_last(temp);
temp_board[new.x-1][new.y] = 99;
}//if
}//if
if(new.x+1<board.length()-1) {
if(temp_board[new.x+1][new.y]==target) {
vector temp;
temp.x=new.x+1;
temp.y=new.y;
new_remove.insert_last(temp);
processed.insert_last(temp);
temp_board[new.x+1][new.y] = 99;
}//if
}//if
if(new.y-1>0) {
if(temp_board[new.x][new.y-1]==target) {
vector temp;
temp.x=new.x;
temp.y=new.y-1;
new_remove.insert_last(temp);
processed.insert_last(temp);
temp_board[new.x][new.y-1] = 99;
}//if
}//if
if(new.y+1<board.length()-1) {
if(temp_board[new.x][new.y+1]==target) {
vector temp;
temp.x=new.x;
temp.y=new.y+1;
new_remove.insert_last(temp);
processed.insert_last(temp);
temp_board[new.x][new.y+1] = 99;
}//if
}//if
}//for
remove = new_remove;
}//while
}//examine
This creates a copy of the board array and iterates over it, it creates a new array called "new_remove" every cycle of the while loop, it checks adjacent tiles to the current tile, then adds any that match to new_remove to check their adjacent tiles next cycle, marks them off on the copy of board, and adds them to processed to deliver the final results. At the end of the for loop new_remove replaces remove to check the new list of tiles, and new_remove is recreated/emptied for the next cycle, i'm not sure what the BGT syntax is for clearing or copying arrays so don't know if thats correct.
_______________________________________________ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector