# A Swarm-Based Approach to Generate Challenging Mazes
## 3 Swarm Movements to Generate Challenging Mazes
### Proposed Methodology to Generate a Challenging Maze
The foregoing operations of the presented approach are outlined as Algorithm 1```
initialize:  maze's parameters: \(n\), \(m\)  parameters: population size (\(k\)), visual scope (_visual_), maximum number of iterations (_MaxIt_)  randomly population of \(k\) individuals (each individual is one generated maze) for\(i=1\) to \(k\)do  evaluate the quality of its solution (the complexity of the maze) endfor  find the best complicated maze (\(P_{g}\)) in initial population whileiteration < _MaxIt_do for each individual \(i\)do // start procedure: _swarm movement_ for each individual \(j\)do if the complexity of individual \(j\) is higher than the complexity of individual \(i\), within its _visual_**then** move \(i\) towards \(j\); endif if the complexity of the \(i\)th maze is a local optimum (within its _visual_) then move \(i\) towards \(P_{g}\); endif endfor endfor if the new solution is better than \(P_{g}\)then update \(P_{g}\); endif for\(i=1\) to \(k\)do // start procedure: _random dispersion_  move the \(i\)th individual towards its temporary solution endfor if the new solution is better than \(P_{g}\)then update \(P_{g}\); endif endwhile  return the most complicated maze with the highest measure of complexity
```

**Algorithm 1**

In order to understand the architecture of our approach, it is necessary to present the individual movement. Therefore, this step of implementing the individual movement (the individual moves in the direction of its temporary solution or tends toward another individual) can be stated as follows:

```
STEP: the individual movement if the number of common points in the path is greater than visualthen  randomly select two common points;  change the elements of the path vector of the \(i\)th individual into elements of the path vector of the \(j\)th individual between common points;  move (from \(j\)th to \(i\)th individual) the corridors reaching the replaced segment of the path if there are cut-off corridors (not connected with the start or end points) then add the cut-off corridor to the nearest corridor; endif if there is a solution different from the set path vector then introduce changes to the maze structure by replacing a randomly selected element not belonging to the path vector with a value corresponding to the wall; endif if four elements corresponding to the walls are concentrated in the maze then replace one randomly selected element in a cluster of these walls to the value corresponding to the corridors; endif endif endif
```

**Algorithm 2**

## 4 Experiments and Results

Let us examine several results of the conducted experiments in order to test the effectiveness of the implemented algorithm. We assumed that all mazes had regular shapes. Although we carried out many experiments for different size of maze, we report our results for square mazes. Moreover, the maze has two free cells: start and target, and all the others are unknown. The algorithm was implemented in the Matlab programming language, using a Windows 8.1 operating system on an Intel@CoreTM i3-4000M 2.40 GHz processor equipped with 8 GB RAM. We explore two different variants of the complexity objective function. ### Experiments for the Complexity of the Path

The first step in our research is the determination of the complexity of a maze in relation to the population size in the operation of the presented swarm-based approach. Therefore, the selected results will be discussed with a view to characterizing the information content resulting from the algorithm's run. In what follows, we will restrict attention to the results obtained for the 25-by-25 maze. In all experiments, we assumed _visual_ = 10 during all iterations. Moreover, the maximum number of iterations was 40. The population size was set to 5, 15 and 25 respectively. It is important to note that these experiments were done using other fixed parameters during all iterations.