TrafficWorlds

by Theta Games (version 1.1.5)

Instructions

Connect homes (dull-colored squares) to corresponding-color businesses (brighter squares) with roads. If a path is available from a given home to the business of the corresponding color, cars (circles) will generate at the homes and travel there. You (the player) earn money each time a car reaches its destination; which, in turn, allows you to pay for new roads and maintenance on existing roads. Though this gameplay mechanic is not particularly realistic, it can be thought of as an abstraction of taxes from workers and businesses feeding back into public works.

As you try to connect more homes to businesses, your roads will likely intersect and/or provide paths for lots of different cars moving between various homes and businesses. Also, obstacles (dark grey squares, representing other buildings in the city) will appear; roads may not be placed on obstacles. In general, designing an efficient grid is key to this game. To help with this, various stoplight types and color-coded gates may be placed on the roads (please see a description of these under the "Controls" section).

The game measures efficiency of your traffic grid via a metric called flow ratio. An efficient traffic grid (i.e. having a flow ratio near 100%) will allow you to directly earn more money; also, the flow ratio directly affects how likely new homes and businesses will spawn (who would want to develop in a congested, poorly managed city?).

TrafficWorlds (like my previous game ĐiệnWorlds) has no definite end. See how many weeks you can maintain an efficient grid and make money; the game is meant for players to explore and experiment with strategies to see what works best. If you get stuck, just start over ("Regenerate" at the main menu) - the game doesn't take particularly long to "mature."

Controls

  • Left mouse button: Place road (if you can afford it). Clicking again on a road will place a stoplight or color-gate of the selected type on the road (stoplights/color-gates do not cost money).
  • Right mouse button: Delete road with everything on it. If the given road was placed while paused, and you haven't unpaused the game since, then you will be reimbursed the full road cost. Otherwise, you will be reimbursed half the road cost.
  • Ctrl + left mouse button (used on stoplights): Stoplights have two states which (by default) alternate at set, equal time intervals of 120 frames (two seconds if the game is running at a full 60 fps). Ctrl+clicking a stoplight will increment the time interval at which the stoplight will wait at whichever state it was in upon receiving this command. For example, consider a stoplight that alternates between states NS (North-South) and EW (East-West). If you ctrl-click on this stoplight while it is in the NS state, it will subsequently wait 240 frames in each subsequent NS state (while continuing to only wait 120 frames in each subsequent EW state). Ctrl-clicking it again in the NS state will make it wait 360 frames in each subsequent NS state.
  • Ctrl + right mouse button (used on stoplights/color-gates): Delete the stoplight/color-gate at the cursor position, without deleting the road beneath it.
  • SPACE: Pause/unpause the game. Roads and stoplights/color-gates may be placed, deleted, or managed while the game is paused.
  • Digits 1 - 9: Select a stoplight or color-gate type. See below:
    • 1: (NS/WE stoplight): In "state NS," the stoplight admits cars only from the North or South, while in "state WE" it admits cars only from the west or east.
    • 2: (N/S stoplight): In "state N," the stoplight admits cars only from the north, while in "state S" it admits cars only from the south. This stoplight never admits cars from the west or the east.
    • 3: (W/E stoplight): In "state W," the stoplight admits cars only from the west, while in "state E" it admits cars only from the east. This stoplight never admits cars from the north or the south.
    • 4 - 8: (Single color-gates): A color-gate will only allow cars of its corresponding color to pass, and will block all other traffic. Each of these five keys correspond to a different color of color-gate.
    • 9: (Custom color-gate): This will select the current custom color-gate (see "Digit 0" bullet-point).
  • Digit 0: Enter color-gate design mode. When in this mode, digits 4 - 8 will each toggle a color added to a "custom" color-gate. A custom color gate can allow multiple colors to pass through it (even all five, though this is rather pointless). By default, the custom color-gate will be black, indicating that no colors will be allowed to pass through it. When you are finished designing a custom color-gate, press "0" digit key again (or "9") to exit color-gate design mode, and the custom color-gate you just designed will be selected.
  • ESC: Bring up the main menu (from which you can save/load/regenerate). Pressing ESC again at the main menu will return to the game.
  • R: (R)ecall the maintenance fee applied last week (see the "Money/Probabilities/etc." section)
  • B: Recall last (b)uilding spawn (the expanding-square spawn effect will appear again at the last building spawn location).
  • M: Toggle (m)usic muting
  • S: Toggle (s)ound effects muting
  • F: Display (f)ps. The game should run at 60 fps.
  • Ctrl-L: Activate "easy-mode" by granting you a (l)oan of $1,000,000. This "loan" does not have to be re-paid, though it cannot be used if your funds are at least $10,000,000.
  • C: Toggle (c)olorblind mode. This mode displays digit(s) 1 - 5 on everything in the game that would otherwise be differentiated by hue (homes, businesses, cars, color-gates). In this mode, "GO" is displayed on the "green" side of stoplights.

Main Menu

At the main menu (accessible by pressing ESC), you can save/load your game (the save file is stored locally), or regenerate the board (which starts over with a newly randomized configuration).

Car Movement

While it is not necessary to understand every detail of the underlying simulation, having a basic understanding of some topics might help with making an optimal grid.

First and foremost, nothing in the game acts on diagonals. Cars will only move in the four cardinal directions, and roads should be constructed to produce paths accordingly.

A car will begin its journey with a path (if there is no available path from a given home to the corresponding business, cars will not spawn). Spawned cars' paths may be temporarily have other cars or red stoplights in the way (but not color-gates). The selected path will always be no longer (in number of adjacent squares) than any other possible paths.

With a path set, the car will set an internal timer to 16 frames; when this timer hits zero, the car will move to the first square on its path (but only if the adjacent square is unoccupied by a car, and isn't blocked by a "red" stoplight or a color-gate of a different color than the given car's color). A successful move will trigger a new timer of 14 frames; whereas if the car could not move, a timer of 16 frames is set again. Any time a car successfully moves, the next timer is set for two fewer frames than the previous timer was set (with a minimum of 2 frames for the set timer), while a blocked car's timer will always set to 16. Additionally, a car's timer will be set to 16 if it enters a non-stoplight square that is adjacent to at least one other car (this mechanic simulates "stop-sign" behavior at intersections where stoplights are not placed). This "timer" mechanic is a reasonable approximation to motion-by-acceleration (we invite the player to work this out as an exercise).

Within each frame of the game, the priority in which cars are given to move is determined randomly, though all cars will have a chance to move in the given frame. Because of this, two cars cannot enter the same square simultaneously.

If a car was stopped (i.e. its timer was set to 16), yet an adjacent square opens up, there is a chance that it will try to re-calculate a path. A path calculated at this state must not have any other stopped cars in the way. Hence, cars may try to circumvent a jam if such a path exists.

Money/Probabilities/etc.

In this section, we discuss some money-related and chance-based aspects of the game.

  • Roads cost $50 to place
  • A car successfully reaching its corresponding business will earn $16*(flow ratio)
  • At the end of each week, a "maintenance fee" is applied. This fee increases with the number of roads on the board and with the number of weeks played. The formula is listed below:

    Maintenance fee = $250 * sqrt(# roads) * (1 + 0.25*((week number) - 1)).

  • The chance of home/business generation is proportional to the flow ratio. A global timer is set to a random integer between (inclusively) 80 and 160 frames. When this timer goes off, it is reset to another random integer, and there is a (20*(flow ratio))% chance that a new home/business will try to spawn. The new building is chosen to be a new business with 40% probability; otherwise, it will be a home. The location of the new building is randomly assigned to an unoccupied square (though new homes or businesses will not spawn adjacent to roads). Note that if the board is very crowded, buildings may not spawn, as they will only try a maximum of 500 times to place themselves).
  • At the end of each day, flow ratio is computed. Heuristically, flow ratio is the ratio of the number of cars reaching their destinations to an expected number of cars reaching their destinations (both computed over a day). The flow ratio is appropriately normalized so that free-flowing traffic yields a flow ratio of 100%.
  • Homes generate cars on timers according to the formula

    new timer = R - round(100*sin^2 (pi*(time of day))),

    where R is a random integer between (inclusively) 180 and 220, and "time of day" is a number between 0 and 1, which increases as the day progresses. The "sin^2 term" represents a crude "rush hour" effect (though there is only one "rush hour" per day cycle.

Hints/Tips

I would like to encourage players to experiment and discover strategies on their own (as the dev, I don't even yet know what kinds of layouts yield the best results). Still, there are some basic hints that might help out new players.

  • Stoplights often help with traffic flow. Any time cars slow down, there runs a risk of causing a backup elsewhere. Stoplights may cause temporary backups, but if planned correctly, they will release these backups regularly, and allow for cars to move quicker.
  • Ctrl-clicking stoplights can be very useful for allowing a high-volume road to have more "green-light" time.
  • There are no one-way streets. Cars (especially newly-spawned ones) will sometimes try to enter a road that they shouldn't, and block traffic by trying to go the opposite way of the other cars (this happens because cars will always try for the shortest path to the destination - even if other cars might end up going the opposite direction along the same path). Color-gates (and general, careful planning) can be very useful for preventing this; but if it does happen, temporarily place some extra roads to try to alleviate the gridlock.

Other Information

TrafficWorlds was created with Game Maker: Studio by myself (Theta Games). All sound effects are by myself, along with the soundtrack piece "Traffic Melody and Variations." This piece can be found at the following places:

Bandcamp

SoundCloud

YouTube

A download link is available (near the bottom of the page) for users who might want a stand-alone Windows executable. Make sure you unzip the archive before playing.

Have fun, and thanks for playing!


Changelog

  • v1.0.1: Fixed a small bug with ctrl-clicked stoplights slowly falling out of sync relative to non-ctrl-clicked stoplights placed at the same step.
  • v1.0.2: Ensured that houses do not spawn in inaccessible areas (i.e. blocked from the corresponding business by obstacles, other houses, or businesses of a different color). Also, ensured that a new color business will not spawn immediately after a previous business spawn.
  • v1.0.3: Now, the next spawn after a new color business will be a house of the same color.
  • v1.0.4: (Hopefully) fixed a strange bug in which the music occasionally stopped upon pressing "Regenerate."
  • v1.0.5: Increased length of time that the "new building" effect lingers, to improve visibility and allow players to easily pick out where new buildings spawn.
  • v1.0.6: Ensured that homes will not spawn next to businesses of different color, and vice-versa.
  • v1.0.7: Made a small adjustment to the "stopsign" behavior; now, cars will not incur this penalty at all if an stoplight is present on the square. Also, made some small cosmetic changes to improve visibility (made color-gates less bright, homes more dull).
  • v1.1.0: Added "custom" color-gates, which can be designed by the player. These gates can allow multiple colors through.
  • v1.1.1: Some more cosmetic changes to improve visibility. Made businesses/homes contrast more, changed the look of intersections, implemented a keypress ("B") to recall last building spawn.
  • v1.1.2:


    • A car immediately behind a permanent red-light (e.g. a car sitting south of an E/W intersection) will now try to get around it. Also, did some "balance" work with fees and revenues.
    • Each car reaching its destination now earns $16*(flow ratio) (so flow ratio now essentially affects overall revenue quadratically).
    • Maintenance base fees are now increased, but the rate (per week) at which the fees increase has been decreased a lot. Also, maintenance is now proportional to the square root of the number of roads (it was previously proportional to the number of roads).
    • Changed the look of E/W and N/S intersections.
    • Finally, for those who wish to experiment with no money problems, there is now an "easy-mode" which grants the player $1,000,000 (activated with Ctrl-L).
  • v1.1.3: Bumped up the rate at which maintenance fees increase again.
  • v1.1.4: Bumped up base maintenance fee.
  • v1.1.5: Implemented a "colorblind mode" (toggled by the C key). This mode displays digit(s) 1 - 5 on everything in the game that would otherwise be differentiated by hue (homes, businesses, cars, color-gates). In this mode, "GO" is displayed on the "green" side of stoplights.



StatusReleased
PlatformsWindows, HTML5
Release date Oct 25, 2016
Rating
Rated 4.4 out of 5 stars
(20 total ratings)
AuthorThetaGames
GenreStrategy
Made withGameMaker
TagsCity Builder, traffic
Average sessionAbout an hour
InputsKeyboard, Mouse
AccessibilityColor-blind friendly
LinksHomepage

Download

Download
trafficworlds_v1_1_5_windows.zip 14 MB

Comments

Log in with itch.io to leave a comment.

i made everything road for ,max flow ratio

Good Game :)

Hope your doing fine

I've played much and found some issiues:

1. Whole path is set when car starts. If we change roads during it's journey it will stop and mostly will stuck. Sometimes it regenerates path but mostly stay at position. If we add some roads near - it may try change path. I need to create 2 separate paths (new and old) and wait if all will drive by new path, than can delete old one.

It should regenerate path if cannot move because there is no road (from calculated path).

(1 edit)

Thanks for the comments.  Unfortunately, it kills performance if stuck cars constantly check for new paths.  I tried to strike a good balance between quickly-adapting AI and performance.

Also, one might argue that quickly adapting to new routes is somewhat unrealistic.  Drivers that have set out to work already have their routes in mind (or programmed into GPS).  Yes, people certainly take other routes when stuck in traffic - but they usually don't do it instantly

(1 edit)

I haven't played so much time. Right, it may kill the performance, but maybe it should check new route only if car stuck - this means, that not moving for some time, but have other free path/road to go. So it will check for path for first stuck car and move it, then next time for next one. The last one - will wait, but after some time all cars can go. Additional one or few cars (if many tracks changes for last day) won't need additional performance. Now it is impossible to check new solutions without stopping the source point.

(+1)

This reminds me of mini metro. I really like the game

Thank you! I've played Mini Metro as well; I like it.

(+1)

Three-way traffic lights would be nice too.

(1 edit)

That might work well; it's a possibility in the future as well.

(+1)

Could you add one-way roads? (Love the game, btw - I've spent way too many hours playing it!)

(+1)

I'm glad you like it, thanks! One-way roads is a little hard with the current car pathfinding, unfortunately. If I ever revamp that aspect, it's a possibility, though.

(Little late) but it would be nice if there was like a one-way gate system instead of a true "one-way road"

Could you make a speedup feature?

I think I could give it a go.

(+1)

fix the fullscreen please

(+1)

The fullscreen button is more of an itch.io thing, but I'll see if I can do anything about it.

versionthat works on ipad plz

Placing roads would work nicely with touchscreen, but I'd have to rethink all the the other controls (e.g. SPACE to pause, ctrl-clicking, etc.) to make everything else work on such a device. Maybe in the future, though.

(+1)

Your pathfinding implementation doesn't properly check whether a stoplight is never going to be green when approaching from a certain side, as demonstrated in this screenshot: https://i.imgur.com/xvqKPSY.png

(+1)

Right, the pathfinding actually ignores stoplights. This is because it's built on squares either being "on" or "off," while a stoplight adds a directional aspect to it. If I generalize the pathfinding to allow for directed graphs (it would be a serious generalization), then it could allow for permanently blocked stoplights and even one-way streets.

Turning undirected Dijkstra/A* to directed should only be a few lines. Especially in this case it's feasible to just hack in a specific check for permanently blocked stoplights and skip if true.

This is certainly something I would consider generalizing in the future.

I've implemented a change (v1.1.2) that should address this somewhat.