We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Traffic Tiles

We need to build out the landscape of the next algorithm we'll be learning. We want the algorithm to be able to traverse a grid of tiles, each representing a section of road in a city that has a grid layout. The interesting thing about this grid is that each tile will have a cost – how jammed up traffic is in that location. The more traffic, the harder it is for our algorithm to pass through that tile.

Assignment

Implement the __init__ and cost methods. You'll notice that the __hash__ and __repr__ methods are completed for you.

The __hash__ method's purpose is to allow us to hash the Tile's x/y coordinates so they can be used as a unique ID.

The __repr__ method is so that we can print out a Tile and have it nicely display the coordinates.

The cost method returns how expensive it is for an algorithm to move through this tile: how much traffic there is. Because we're in charge of building tests for our algorithm, we'll be generating our own fake costs for now. We'll generate a pseudorandom number between 1 and 25.

You can use the following steps: