 Author Topic: Micromouse Code  (Read 8876 times)

0 Members and 1 Guest are viewing this topic. harisankarsa • Jr. Member
•  • Posts: 23 Micromouse Code
« on: March 30, 2008, 07:35:39 AM »
Can anyone pls help me? I have been trying to implement the floodfill algo in my micromouse and it just isnt working right.... can u pls give me a sample code so tht i can know how to do it correctly..... hazzer123 Re: Micromouse Code
« Reply #1 on: March 30, 2008, 08:43:43 AM »
For my micromouse i store the wall information in a 16x16 array of integers. The LSB of each integer is the south wall of a cell, and the 2nd bit is the east wall of a cell. 1 means the wall exists...

So if i want to check if there is a wall to the west of cell A, then i have to look at the cell west of cell A and see if it has a wall east of it.

My MATLAB algorithm ( very similar to C ) goes like this :

Code: [Select]

flooded = zeros(16,16);     %Create an array of 0s to store the flood values

flooded(mouse_y, mouse_x) = 1;  %Give the mouse's current position a flood value of 1

while 1                         %Loop until break command

for x = 1:16                %Scan across the grid
for y = 1:16

%Check if current cell already has a flood value.
%If it does then move on.

if flooded(y,x) > 0
continue
end
%Check the cell North of the current cell

if y-1 > 0                                      %If the cell exists...
if flooded(y-1,x) > 0                       %If the cell is flooded...
if bitand(maze(y-1,x),1) == 0           %If there is no wall between them...
flooded(y,x) = flooded(y-1,x) + 1;  %Then give the current cell a flood value 1 higher than the north cell.
continue;                           %Move onto the next cell
end
end
end

%Check South

if y+1 < 17
if flooded(y+1,x) > 0
if bitand(maze(y,x),1) == 0
flooded(y,x) = flooded(y+1,x) + 1;
continue;
end
end
end

%Check West

if x-1 > 0
if flooded(y,x-1) > 0
if bitand(maze(y,x-1),2) == 0
flooded(y,x) = flooded(y,x-1) + 1;
continue;
end
end
end

%Check East

if x+1 < 17
if flooded(y,x+1) > 0
if bitand(maze(y,x),2) == 0
flooded(y,x) = flooded(y,x+1) + 1;
continue;
end
end
end

end
end

if flooded(target_y, target_x) > 0   %If there is a flood value in the target cell, then enough flooding has occurred for a route to be planned.
break
end

end

I know my coding isn't the most legible, so if you have any problems... just ask Imperial College Robotics Society
www.icrobotics.co.uk Admin Re: Micromouse Code
« Reply #2 on: April 06, 2008, 10:55:01 AM »