World Generator

The **World Generator** is an algorithm whose job is to create each new World you play. It uses a variety of random factors to place down Cells on the Planet Map, creating a completely unique experience each time.

The World Generator goes through a few main stages as it prepares a new world. It begins with constructing Dagobah (rarely with any alterations whatsoever), then selects a Mission to be played and a corresponding Objective Cell, and finally begins constructing the Mission Planet itself by placing down Cells in a semi-random fashion. Each of these stages is explained below in as much detail as is currently available.

Unfortunately, the World Generator algorithm is still not 100% understood at this stage, but most of its subroutines are apparent simply through repeated playthroughs.

## Process Overview

The **World Generator** has to construct the entire game World before the game actually begins. It does so through an algorithm that is at least somewhat predictable, and whose primary points are listed below. The only external factor influencing any decisions is the WORLD SIZE slider, which only affects the *next* World to be generated.

**Note:** After the World Generation process is completed, one important matter remains unresolved: The exact Variants used for each Cell. That is only determined once  Luke visits each Cell for the first time.
1. The Generator selects a Mission at random, out of the 15 available choices. This subsequently determines the Planet Type and the  Objective Cell.
2. The Generator creates Dagobah according to a rigid scheme.  Yoda is placed at one of four random locations on the sub-planet. If the player has completed exactly 5, 10 or 15 Missions successfully, the World Generator replaces one of Dagobah's Cells with a unique Variant to facilitate a Dagobah Mission; Yoda is moved to a unique position in that Cell, instead of the usual locations.
3. The Generator uses a randomized algorithm to create an empty layout of accessible grid squares on the Planet's map - the "Main Play Area". This is simply an outline of where Luke can and can't go. The result is a large block of grid squares that are all connected together orthogonally. Most cells can only be placed within this outline.
4. The Generator places the appropriate  Landing Cell on the grid, in one of the four central grid squares.
5. The Generator places a  Locator Puzzle Cell in one of the squares immediately adjacent to the Landing Cell (diagonals included).
6. The Generator places a  Force Puzzle Cell somewhere close to the Landing Cell.
7. The Generator places a random number of  Blockade Cells (or none at all) at the edge of the Main Play Area. It then creates an extension to the playable area that consists of one or more grid squares in a straight line towards the edge of the grid.
8. The Generator places a random number of  Gate Cells (or none at all) inside the Main Play Area. For each Gate Cell, it also places a corresponding  Destination Cell somewhere on the very edge of the grid. It then creates a small playable area in the form of a short line or column extending from that Destination Cell, disconnected from all other playable areas; this is called a "Destination Area".
9. The Generator places an  Objective Cell in a random available grid square further away from the Landing Cell. This includes grid squares behind Gates, but not behind Blockades.
10. The Generator populates the map with a random number of  Puzzle Cells, trying to keep them from touching orthogonally if possible. One Puzzle Cell is placed behind each Blockade and Gate cell. The final number of Puzzle Cells is random, but roughly correlates to the total number of available squares remaining on the grid.
11. The Generator places down a random number of  Teleporter Cells (either zero or at least 2) in any available grid squares in the Main Play Area and Blockade extensions. Teleporters are never placed behind Gates.
12. All remaining grid squares within all playable areas are set as  Empty Cells.
13. The World Generator assigns a specific Cell Template to each cell on the map according to the Planet Type and Cell Type, chosen randomly for most cells. During the process, the Exchange is created to allow Luke to turn his starting and freebie Quest Items into those needed to complete the mission.

## Mission Selection

Before the World Generator can make any other decisions, it must first select a Mission to be played on the newly-generated World.

The game offers 15 missions to select. For most intents and purposes, the mission is selected completely at random; it is possible for the same mission to be selected twice in a row (or more). The only exception seems to be Lokondo, which can never be selected while a Dagobah Mission is in progress (see below).

The choice of mission has the following effects:

1. The type of Planet featured in the main part of the game: Desert, Ice or Forest. This in turn determines which subset of Cells the generator can place down on the planet.
2. The  Objective Cell to be used. There is exactly one Objective Cell unique to each mission; nevertheless, the World Generator can sometimes choose from several Objective Variants, which are different versions of the Objective Puzzle. If so, the choice is made immediately at the start of the game.
3. Yoda's dialog at the start and end of the mission is tailored to the specific mission selected.
4. A potential change in Dagobah occurs during one mission (Lokondo), removing  Yoda altogether and setting up an encounter with  Boba Fett instead.
5. The Exchange is generated specifically to provide  Luke with all the Quest Items he needs in order to solve the Objective puzzle. This has a profound effect on the type and distribution of Cells on the main Planet.

## Dagobah

*Main article: Dagobah*

Dagobah is the starting area of each World. The World Generator creates it according to very strict specifications; with a few rare exceptions, Dagobah is almost exactly the same in each game you play.

Dagobah always consists of four Cells, named Dagobah NW, Dagobah NE, Dagobah SW and Dagobah SE. These are arranged in a square pattern in the center of the Dagobah map. Under no circumstances will the surface of Dagobah be of any different shape or size.

Normally,  Yoda is placed at one of four possible positions - one in each cell (the fourth is inside Yoda's hut, a Subcell of Dagobah NE). He remains at the selected position until  Luke completes his Mission, and is then moved into his hut.

### Lokondo

*Main article: Lokondo*

When generating a new world for the Lokondo mission, a special Variant is used for Dagobah NE, showing  Boba Fett's ship outside Yoda's hut. The interior Subcell of Yoda's Hut is also replaced with a variant containing Boba Fett himself, as well as an interactive spot on a table in the back containing the Mission Briefing and starting Quest Item.

Yoda himself is not placed anywhere on Dagobah during this mission.

### Dagobah Missions

*Main article: Dagobah Missions*

If  Luke Skywalker has completed *exactly* 5, 10 or 15 Missions so far, the next generated world features a slightly different version of Dagobah. One of the four main Dagobah cells is replaced with a Variant that allows access to a unique Subcell where Luke must complete a short task.

 Yoda is initially placed at a specific position dictated by the Dagobah Mission itself. After Luke accomplishes his task, Yoda is immediately teleported to one of his four normal positions, and the game proceeds as normal.

## Objective

The choice of Mission at the start of the generation process determines which  Objective Cell will be placed down on the planet. Solving the Objective puzzle fulfills  Luke's mission.

Each Mission features its own unique Objective Cell; no two missions share the same objective.

Each mission only has one Objective Cell it can use, but many Objective Cells have more than one Variants to choose from. These are different versions of the same Objective Cell, with potentially significant differences. The differences could include a rearrangement of the Objective's Subcells, different Enemies, or even different puzzles.

As a result of the Objective Variant choice, the Quest Items required for solving the puzzle could be different. This is why the choice of Objective Variant has to be made early in the World Generation process: Changing the number or type of items required means that a different Exchange is required, affecting the number and type of  Puzzle Cells the generator has to place down during the Planet Layout process.

Note that the Objective Variant typically affects the Objective Cell as a whole, but individual Subcells may still use their own Variants selected at the last minute (when they are first visited). This differs from one Objective Cell to the next, and is explained separately for each of them in its own article.

## Planet Layout

The final and most complicated part of World Generation is the creation of a Planet for the mission to take place on.

This process begins by creating a randomized "playable area" on a 10x10 grid, placing down key Cells at randomized positions within that area, and randomly expanding that area in various directions in order to extend gameplay. Finally, the World Generator must create a chain of item exchanges that would ultimately allow  Luke Skywalker to acquire all of the necessary Quest Items to finish the mission.

This process is handled in many discrete steps. Unfortunately, the exact order of these steps, as well as many of the decisions themselves, are vague if not totally unknown. The subsections below describe the process according to a "best guess" based on over a hundred playthroughs and careful examination of the results.

### Main Play Area

A Planet is a 10x10 grid. Each square on this grid can fit a single Cell, with an unlimited number of Subcells underneath. However, not all 100 squares will actually contain cells in each playthrough; Only about 40-60 do, when the WORLD SIZE slider is set to maximum. The World Generator decides which squares will actually contain Cells. All other squares are left empty and inaccessible.

The process begins with a 2x2 box at the center of the planet map. This "center box" is always accessible on each and every Planet, regardless of any other factors. One of these squares will contain the  Landing Cell, which is where Luke arrives on the planet initially.

Once the center box is set up, the game begins expanding it in random directions, simply by placing empty squares next to existing squares (always orthogonally - no diagonals allowed). This slowly builds a randomized shape extending outwards to the edge. The resulting shape is always continuous; it is always possible to walk from one end to the other simply by moving from one square to another orthogonally.

The resulting shape is called the "main play area". It forms the basis for the planet's map. Subsequent steps below may adjust it, or add more play areas disconnected from it.

The size of this main play area is random, within certain thresholds. When the WORLD SIZE slider is set to maximum, this main area will contain an average of about 35 cells.

### Landing Cell

*Main article: Landing Cell*

Once a main play area has been established, one of the cells within the 2x2 center box is set as the  Landing Cell corresponding to the planet's Type (Desert, Ice or Forest). Each planet type has only a single Landing Cell, so the World Generator does not have to make any decisions except where to place it.

### Locator Puzzle Cell

*Main article: Locator Puzzle Cell*

After placing down the Landing Cell, the Generator can now place a single  Locator Puzzle Cell in any of the adjacent squares.

The Locator Puzzle is always placed inside the 2x2 Center Box, making it easy to find early on by simply walking around the perimeter of the  Landing Cell.

### Force Puzzle Cell

*Main article: Force Puzzle Cell*

Next, the World Generator places a single  Force Puzzle Cell in an available square on the map.

The Force Puzzle Cell may only be placed in the squares immediately adjacent to the 2x2 Center Box.

### Blockade Cells

*Main article: Blockade Cell*

The World Generator has a chance of placing down one or more  Blockade Cells. The higher the WORLD SIZE setting, the higher the chance. However, there is no guarantee that *any* Blockade Cells will be placed, even on the largest of worlds. The larger the Main Play Area, the less chance there is for any Blockades to be placed, and the fewer will be placed on average.

Blockade Cells are very particular about where they can be placed. First the World Generator must find a position suitable for the Blockade Cell itself, and then it must determine whether the Main Play Area can be extended in that direction without creating a way to bypass the blockade and reach the area hidden behind it.

A Blockade Cell can be placed anywhere immediately adjacent to the Main Play Area (no diagonals), except it cannot touch the outer edge of the map. The Generator picks one such position at random. It then checks to see if there is enough free space (not yet part of the main play area) to insert a 3-square-wide rectangle stretching from the Blockade Cell's proposed position all the way to the edge of the map. If any part of that rectangle intersects with the Main Play Area (or with anything else), the Blockade Cell cannot be placed at the proposed position.

The example on the right shows such a footprint check. The square marked in yellow is being tested to see whether a Blockade Cell can be inserted there. If any part of the red area intersects with anything, this position would be invalid. In this case the red area does not contain anything yet, and the Blockade Cell is placed at the indicated position.

After placing down the Blockade Cell, the main play area is then extended by a random number of squares directly behind the Blockade (towards the edge of the map), in a *straight line*. The minimum number of squares added is always 1, and the maximum is determined by the distance to the edge.

In the example on the right, we see that there is enough room for up to three Cells. The World Generator can add anywhere between 1 and 3 Cells. It chooses 2.

Note that the orientation of the Blockade Cell always faces the edge of the map. This cell will initially only be accessible from the main play area. Once the blockade is opened, it allows proceeding into the extension. Blockade Cells never have more than one entrance and one exit. Thanks to the checks done previously, the blocked-off area cannot be accessed in any way except by opening the blockade.

The world Generator repeats the entire process a random number of times, correlating to the WORLD SIZE slider. Each attempt may or may not succeed in placing a Blockade cell. On average, no more than 2 or 3 Blockade Cells will be placed, in total.

### Gate and Destination Cells

*Main articles: Gate Cell and Destination Cell*

The World Generator has a chance of placing down one or more  Gate Cells. The higher the WORLD SIZE setting, the higher the chance. However, there is no guarantee that *any* Gate Cells will be placed, even on the largest of worlds. The larger the Main Play Area -- including any previously-placed Blockade Cells and their extensions -- the less chance there is for any Gates to be placed, and the fewer will be placed on average.

Gate Cell placement is complicated, because the game must find a valid location for the Gate Cell itself, a matching  Destination Cell cell, and a small area connected to the Destination Cell. If no suitable location can be found for all three, none of them will be placed.

The Gate Cell itself has relatively simple requirements for placement:

1. It must be inside the existing Main Play Area.
2. It must be at least 2 squares away from the 2x2 center box, and at least one square away from the outer edge of the map.
3. The selected square must not already contain a  Blockade Cell, nor be in an extension area behind a Blockade Cell.

Note that the game seems to prefer placing Gate Cells *exactly* 2 squares away from the 2x2 center box. Around 99% of all Gate Cells will be found at that distance.

The image on the right shows all possible locations for Gate Cells on this example map. Squares marked in green are exactly 2 squares away from the center box, where Gate Cells are most likely to be placed. Squares colored in purple *can* be used for a Gate Cell, but are highly unlikely to be picked.

 Destination Cells are much more tricky to place. A Destination Cell has the following requirements for placement:

1. It must be placed in a square immediately adjacent to the edge of the grid.
2. It must not be adjacent to any square that already contain something else (diagonals included).
3. The first two requirements must also apply to *at least* one adjacent square (no diagonals).

The image on the right shows all possible locations for a Destination Cell on our example map (marked in yellow). They are all arrayed around the edge of the map (rule #1). The red squares show the enforced boundary around potential Destination Cells, which must be empty (rule #2). Note how the square in the top left corner is not a valid location despite having nothing around it - because there is no adjacent square that would also fulfill the same requirements (rule #3).

If a suitable location has been found for both the Gate and Destination squares, each of them is placed down at a randomly-selected position that matches its requirements. The example on the right shows both cells on the map.

After placing down the Destination Cell, the World Generator must create a small area to be explored beyond the gate. This is known as the "Destination Area" for that gate. The Destination Area extends a short distance out of the Destination Cell, in a straight line along the edge of the map.

Note that all of the cells in the Destination Area must conform to the same requirements as Destination Cells: They must be placed along the edge of the map, and must not touch the Main Play Area nor any other Destination Areas. The resulting Destination Area is always **completely disconnected** from anything else, and can only be reached by passing through the Gate Cell; it cannot be bypassed.

In the example to the right, we see that the game can extend a Destination Area to either side of the Destination Cell it placed down. It chooses East, and randomly decides to place 2 squares.

The process repeats a random number of times, each time placing a new Gate Cell, Destination Cell, and Destination Area, only if a suitable position can be found for all three. The chance of placing more cells decreases each time. In this example, only one more set of Gate/Destination cells has been placed, for a total of two.

At this point in the process, the shape of all playable areas has been finalized, and will no longer expand for any reason.

### Objective Cell

*Main article: Objective Cell*

With the shape of the map finally established, an  Objective Cell can be placed to serve as the final stage of the Mission.

The Objective Cell can be placed in any square in the playable area that meets the following requirements:

1. It must not be within the 2x2 center box nor directly adjacent to it (diagonals included).
2. It must not be behind a  Blockade Cell.
3. The square must not already be occupied by something else.

The Objective Cell *can* be placed in a Destination Area (behind a  Gate Cell). In our example map on the right, this is exactly what happaned: The Objective is inside the north Destination Area.

### Puzzle Cells

*Main article: Puzzle Cell*

Placing  Puzzle Cells on the map is performed in two steps: Placing them inside each Blockade Extension and Destination Area; and then placing more inside the Main Play Area.

Before this can begin, the World Generator first calculates how many Puzzle Cells in total it needs to place.

The minimum number of Puzzle Cells that must placed on the map is calculated using the following formula:

```
Minimum Puzzle Cells = <ObjectiveItems> + <NumBlockades> + <NumGates> - 1
```

Where:

* **ObjectiveItems** is the number of Quest Items required by the  Objective Cell on this map.
* **NumBlockades** is the number of  Blockade Cells on the map, if any.
* **NumGates** is the number of  Gate Cells on the map, if any.
* 1 is subtracted for the Starting Item given by  Yoda.

If this many Puzzle Cells are placed on the map,  Luke will be able to acquire enough items to unlock every Blockade and Gate, and to solve the Objective Puzzle itself.

However, due to the importance of the Exchange in making the game interesting (and prolonging the experience), a random number of extra Puzzle Cells are added to this total. In larger worlds, the total number of Puzzle Cells placed could easily reach over a dozen. These extra Puzzle Cells are where Luke exchanges Quest Items for other Quest Items, until he ends up with the correct Quest Items needed to complete the mission.

Once the game knows how many puzzle cells it wants to place, it is ready to start placing them. First off, a single Puzzle Cell is placed behind each  Blockade Cell on the map - one each, and no more. Then, a single Puzzle Cell is placed inside each Destination Area (behind  Gate Cells). If the  Objective Cell happens to be inside a Destination Area, that area is skipped.

Finally, the game places as many of the remaining Puzzle Cells as it can inside the Main Play Area. These cells may be placed in any square that does not already contain anything else. Additionally, the World Generator also makes sure that no two Puzzle Cells are adjacent to one another in any of the cardinal directions (north, east, south, west). They may however be placed adjacent to the  Force Puzzle Cell and/or  Locator Puzzle Cell.

### Teleporters

*Main article: Teleporter Cell*

With the final Puzzle Cells placed, all that remains is to place down  Teleporter Cells.

The World Generator has a certain chance of placing down Teleporter Cells, and may in fact choose not to place any at all. The larger the world, the more chance it has to place any Teleporters.

If any Teleporters at all are placed, at least 2 will appear. The maximum number of Teleporters encountered on a single map so far has been 6, but there is currently no evidence that this is a hard limit.

Teleporters can only be placed within the Main Play Area or behind  Blockade Cells. They cannot be placed in Destination Areas (behind  Gate Cells). Naturally, a Teleporter cannot be placed in a square already occupied by something else.

There is no limitation about what a Teleporter can be placed next to; in fact, two Teleporters can end up being placed right next to each other - rendering them both effectively useless.

## Cell Template Assignment

Now that the **World Generator** has decided which type of Cell goes in each square on the grid, it is time to decide which specific Cell Template will be used for each of them.

A Cell Template is a set of instructions - a "script" - telling the game exactly what to put inside each Cell. This includes terrain, obstacles, Enemies, Movables, Items, and any interactive object required for puzzles or any other purpose. The Template also applies to all Subcells connected to the main cell.

The World Generator can only use a given template *once* in each World. The same template may repeat in subsequent Worlds, but will never be encountered twice on the same planet.

Some Cell Types have few options to choose from - and in some cases just one. For example, the World Generator has no choice to make regarding the  Landing Cell, since there is only one Template to use for each Planet Type. Similarly, the  Objective Cell has already been picked during an earlier stage of the process, to match the selected Mission.  Force Puzzle Cells,  Locator Puzzle Cells and  Teleporter Cells do come in multiple varieties for each Planet Type, but the choices are very limited and effectively inconsequential.

 Gate Cells also have a relatively limited number of options to choose from, but it is important to note that when the World Generator sets the template for a Gate Cell, it will also immediately set the template for the corresponding  Destination Cell. A specific Gate will always lead to the same exact Destination every time it is encountered.

 Blockade Cells are more complicated, since they must match the orientation of neighbouring cells. For example, if a Blockade Cell can be accessed from the south initially, and exited to the north once solved, the World Generator has to pick a template that matches these specific entry and exit directions. This limits the choices to one or two templates at the most.

 Empty Cells have a much wider variety to choose from, with each Planet Type having upwards of 30 different Empty Cell Templates.

The choice of  Puzzle Cell templates is significantly more complicated than any of the above, and is explained fully in its own article on the Exchange.

### Puzzle Cells and The Exchange

*Main article: Exchange*

The choice of Cell Template for  Puzzle Cells is the most complex and important decision the World Generator has to make. The World Generator must create a "chain" of puzzles, known on this Wiki as the Exchange, which will ultimately provide  Luke with all the Quest Items required to open every  Blockade Cell and  Gate Cell, solve every single Puzzle Cell on the map, and ultimately solve the  Objective Cell.

First, the game must figure out exactly how many Freebie Puzzle Cells to place down. Each of these puzzles provides Luke with a single Quest Item for free (no need to expend any Quest Items). The number of Freebie Cells required in a World is calculated by the following formula:

```
Freebie Cells = <Gates> + <Blockades> + <Objective Items> - 1
```

Where:

* **Gates** is the number of  Gate Cells on the map. Each requires one Quest Item to open.
* **Blockades** is the number of  Blockade Cells on the map. Each requires one Quest Item to open.
* **Objective Items** is the number of Quest Items required to solve the  Objective Cell - usually two, sometimes one.
* 1 is subtracted for the Quest Item already given to Luke by  Yoda at the start of the Mission.

Freebie Cell templates are always assigned to Puzzle Cells in the Main Play Area. This way, Luke can acquire the items to unlock each Gate and Blockade (if any are on the map at all) simply by exploring the entire Main Play Area.

In order to prolong the game and make it more interesting, additional non-Freebie Puzzle Cell templates are also assigned, to any remaining Puzzle Cell that is not a Freebie Puzzle. These Puzzles require a Quest Item to solve, with each Puzzle Cell requiring a different item. Once the puzzle is solved, Luke receives a new Quest Item to "replace" the one they used up. They are arranged in "chains", where each consecutive puzzle replaces an otherwise "useless" item until Luke ends up with one of the Objective Items. Since the objective puzzle often requires two items, there will usually be two such chains: one to replace the Starting Item given by Yoda, and another to replace one of the Freebie Items.

Construction of the Exchange is complex, since not every Puzzle Cell Template can exchange any item for any other item. The World Generator has to ensure that it picks the correct templates to form a proper chain. Random Exchange Puzzle Cells, which can convert almost any item to any other item, are often used to solve the problem.

Nevertheless, some Quest Items can only be acquired from only one specific Puzzle Cell template. For example,  Chewbacca can only be acquired from Jungle Puzzle Cell 02, and is required for solving the Endor Objective Cell. In this case, the Endor mission will always feature Jungle Puzzle Cell 02, which will always be the last Puzzle Cell in one of the Exchange chains.

Non-Freebie puzzle cell templates can be assigned to any Puzzle Cell not yet assigned a Freebie Puzzle template.