Professional Documents
Culture Documents
Maze Specification:
Rules of Micromouse:
Software Details:
The Motion Layer: It is comprised of Code that controls the motion of the
robot. The Code from the Logic layer calls this layer to move the robot
from one cell to another as and when required. This layer would also
automatically correct the motion of the robot if it has strayed towards left
or right.
The Logic Layer: Objective of this competition is to find the shortest path
towards the center therefore a logic or algorithms are used for deciding
the optimal path. Some of the algorithms commonly used are:
o Depth first search.
o Floodfill
o Follow the wall on left( basic algorithm)
o LRSRT
o LSRRT
o RLSRT
o Center first routing theorem.
2|P ag e
CENTER FIRST ROUTING –THEOREM ALGORITHM
The basic ideas of CFRT algorithm is as follows. According to CFRT, the algorithm
finds out several short roads and records the details of the road with coordinate,
then calculate the number of the total steps of the road and the times of turning
it has. Using a matrix to record the directions that micro-mouse searching in
maze, it select another direction when reach the same bifurcation junction next
time. The messages mentioned above is also used by the mouse to avoid
searching the same route and turn back when it has no direction to go (meet a
cul-de-sac). Each time a new route being found out, it is compared with former
shortest route which is stored in the mouse. If total steps of the new route is less
than the former shortest one, the former shortest route is replaced by the new
route, otherwise do nothing. And the original shortest route is the route searched
at first time. Searching within the allowed time and getting the shortest route, the
best speed is tuned to run to the end.
3|P ag e
DETAILS OF ALGORITHM
1. Maze Information:
A maze can be very confusing because every cell has four possible paths and
choosing the optimal path is complicated. The four possible paths are:
Cul-de-sac
Straight
Turning
Crossroad
T-shaped Road
4|P ag e
In order to maintain the maze information one byte is used to mark traffic
information of each cell of the roads, lower four bits 0-3 of the byte mark whether
four sides (the right, down, left and up of cell, respectively to the directions of
east, south, west and north, as shown in Figure 2) of the cell have obstacles or
not. If one side has obstacle, set the marker of it to1, or do nothing. The middle
two bits, 4th and 5th of the byte, mark the state of cul-de-sac. If there is no cul
de-sac, set the marker to 11, and, one cul-de-sac corresponding to 01 and two to
10, or do nothing. The rest two bits mark the situation of road. While 00denotes
one side to go (straight, left and right turning), 01 denotes T-shaped road and 10
means crossroad.(Given the original state of byte is 00H).
BIT 3 2 1 0
DIRECTION NORTH(U) WEST(L) SOUTH(D) EAST(R)
BIT 5 4
NO CUL DE-SAC 1 1
1 CUL DE-SAC 0 1
2 CUL DE-SAC 1 0
BIT 7 6
1 SIDE TO GO 0 0
T-SHAPED ROAD 0 1
CROSSROAD 1 0
Original state of the register: 00H
5|P ag e
2. Recording coordinate and information of maze’s cell
The information of cell is recorded in a matrix whose name is maze and size is
15×15. Making the cell’s location of maze respectively to coordinate, the left-
down corner starting cell is to origin (0,0), north toy-axis and east to x-axis ( a
quarter random maze as shown in Figure ). At the same time, members of the
matrix strictly fit to the coordinate. For example, the cell 3× 4 maze fits the
coordinate (3, 4). And, except the start and the end, set all the original message of
the maze’s cell to FFH.
Using a register named Dir to recording the direction each time mouse selected.
Dir Direction
0 Y++ : north
1 X++: east
2 y--: south
3 X++: west
6|P ag e
In process, once micro-mouse turns left, 1 is subtracted from the value of register
Dir . And when the value of Dir is 0, it becomes 3 if the subtraction is done. The
same thing is do for right turn, but the subtracting 1 is replaced by adding 1, and
the value becomes 0 when 1 is added to the value 3. For turning back from left or
from right, subtracting 1 or adding 1are become subtracting 2 and adding 2. And
the valueof Dir circulates among 0 and 3. However, nothing is done to the value
of the Dir when micro-mouse keeps going ahead straightly. Therefore, we mouse
can deduce variation between adjacent cells’ coordinates from value change
between current Dir and the former Dir . And we can deduce two formulas to
calculate coordinate of current cell as follows:
7|P ag e
3. Cut Cul de-sac.
There are some roads can’t lead to end and has no way to go to next cell of the
maze, we call it cul-de sac. In order to avoid micro-mouse to walk into those roads
again, we should make a marker and block its information from the road and
matrix maze. Specific method are taken as follows: Firstly, each time when micro-
mouse makes a back turning (means there is a cul-de-sac), both turning back from
left and from right, making a marker in a register whose name is noroad ,with the
value of 1 means there is a cul-de-sac while 0 is no. So we can know if there is a
cul-de-sac or not by the value of register noroad , and set values of all cells to FFH,
which belong to the cul-de-sac between the end of it and the crossing cell nearest
to it. Then ,marker of this direction of the nearest crossing cell is set to 1 to
prevent micro-mouse from selecting this direction when it goes here again. At
last, micro-mouse turns to other directions from the crossing by judging the
information stored before.
For instance, in Figure 3cell (3, 0) is a cul-de-sac. When micro-mouse reaches this
cell, it must make a back turning and set the value of noroad to 1. Because the
value of noroad is 1,micro-mouse should keep walking forward and changing the
information of the passed cells from (3,0) to (1, 1) to FFH while it comes back.
After it reached the nearest crossing cell (1, 2), it clears the register noroad to 0,
sets the marker of cul-de-sac of this cell and selects a new direction to go by
judging the information of this cell stored before.
8|P ag e
Implementation Of CFRT
From the starting cell, micro-mouse detects which direction of the front, left, right
sides can be taken. In consideration of the information stored in the register Dir ,
micro-mouse selects a direction to go. When micro-mouse comes to a cell that
has only one direction to go, it doesn’t make choice but just go by this direction.
For a crossing, it chooses the direction pointing to the end which can makes the
value of Dir become 0 or 1 after it made a action ( That is direction of x++ or y++),
than other directions. If there are two adjacent road junctions or be a crossing
again, let x++ and y++ direction be prior alternatively. And if the direction leads to
the end, other directions are not taken into consideration. By this way, micro-
mouse keep on searching roads till it reached the end cell (7, 7).But, how to select
searching direction? Given value of the former cell Dir is dn-1 and the current is
dn , the relation between them can be shown in the following:
Dn=dn-1 + m
Where, m = (-2, -1, 0, 1, 2), and the value -2 means turning back from left (exiting
a cul-de-sac), -1 means turn left (no obstacle at left side), 0 for going ahead (no
obstacle at front), 1 for turning right (no obstacle at right side) and 2 for turning
back from right (exiting from a cul-de-sac). So the direction corresponding to
the action that can make the value of Dir turn to 0 or 1 is prior to the other
directions. At the same time, it uses a times register named times (original value is
0) to alternate priority of direction x++ and y++ between
two adjacent road junctions. The value 0 means y++ first and 1 means x++ first.
9|P ag e
THE SHORTEST PATH
Two arrays are used to store the coordinate of roads being searched out. One
array [] New Road stores the road’s coordinate of current time, another array[]
Short Road stores the coordinate of the shortest route picked out before. Each
time a new route is searched out, the information of it is recorded in matrix maze
and the coordinate of it is in [] New Road . If the total steps of the new route are
less than the former, replace the shortest route’s coordinate in [] Short Road with
the coordinates of the new route in array [] New Road . If not, do nothing but
keep searching new route. And the original state of [] Short Road is coordinate of
the route searched out at first time.The time cost in straight road and turning is
different, and the difference will becoming more large if the running speeds of
straight road and turning are different, therefore, the total steps of a route is not
simply equals to the sum of all steps taken in the route. Because the turning costs
more time, method of calculating total steps can be shown as following
formula [7]:
10 | P a g e
ROUTING BY CFRT
First Attempt
Picking the quarter random maze as example again, we show the way how to
select direction and calculate the total step. According to CFRT, micro-mouse
starts the first searching road from cell (0, 0). At the T-shaped cell (1, 2), it selects
x++ (east) to go for only x++ go next. When it reaches the crossing road cell (2, 2),
it chooses the direction y++ (north) to go because it is the first time ( times is 0).
And to the second T-shape road cell (5, 7), it chooses the direction x++ (east) to go
because of no y++. When being the third T-shape road cell (6, 7), it chooses
direction x++ again because of no y++ again, then it can go to the end. So a road
can be shown in Figure above And the information of this route is stored in
matrix maze. At the same time, the coordinates of this route are recorded in []
Short Road . From the figure and table, we can know the number n of cell in this
road is 25, with 7 turnings of 90 degree. So s =25+7× 0.5=28.5 (Given a is 0.5).
11 | P a g e
Second Attempt
The second time searching: At the first T-shape road cell (1, 2), it also chooses x++
because of no y++ lead to next. And at the crossing cell (2, 2), it changes
priority of direction x++ and y++, and chooses x++ to go, Then it reaches the
second T-shape cell (6, 4), and chooses direction y++ to go because of no x++.
After this, it can get to the second crossing cell (5, 5) and selects the direction y++
because of last is x++. When to the third T-shape road cell (5, 7), it selects
direction x++. And at the last T-shape road cell (6, 7), it chooses direction x++ to
go and can go to the end. The route is shown in Figure 4, and the information of
this route is stored in matrix maze (As shown in table 2 with a two-dimension
table). Also, the coordinates of this route are recorded in [] New Road . In this
time, n is 23, t is 7, s =23+7 × 0.5=26.5. It is smaller than last s 28.5. So we store
the coordinate of the route of this time in [] Short Road replace with former.
But, t of each road maybe different, so we should choose a carefully on
experiments. And different micro-mouse of the same style may have different a .
For example, there are two routes, n is 26 and t is 4 for one route, n is 24 and t is
7 for another route. If we choose a as 0.5 at first time and 0.8 at second, we will
get different shortest routes.
12 | P a g e
SPRINT
After we got the shortest road, sprint is the key to win the game. Micro-mouse
should sprint to the end with a best speed according to the coordinate of the
road stored in [] New Road . The Followings denotes how to do it.
Because we have got the shortest road, micromouse needn’t do any searching
and detecting. What it should to do is making actions and running to the end by
judging coordinate of the road’s cells. For instance, given that micro-mouse is on
square cell (1, 4) and direction it running to is y++(north), and if the next cell is (1,
5), what it should do is running straight. And if the next cell is (2, 4), it should turn
right. If next cell is (0, 4), it should turn left. The hardware’s performance of
micro-mouse plays an important place in sprint. If the micro-mouse can change
speed while it running, a faster speed should be chose on straight in straight road
and a slower speed in turning. And if the micro-mouse’s speed can’t be changed
in running, a best fixed speed should be selected to do the sprint. All those speeds
should be chose carefully with specific micro-mouse after we do several
experiments.
13 | P a g e
COMPARISON WITH OTHER ALGORITHMS
Many different algorithms are there for solving micromouse maze. Some of them
are enlisted below:
Given the searching rule adopt by other algorithms is that the priorities of
directions which have not been searched before are higher than those have at a
crossing, and the time cost for searching a cell is 1s. Comparing with result of
CFRT we can conclude that other algorithms often search more cells, cost more
times and find out longer roads. We can see the result in the following table, too.
And the differences will become more evidence if the searching time is added.
SRLRT
14 | P a g e
Conclusion
15 | P a g e
REFRENCES
16 | P a g e