

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Traffic Tiles
incomplete
2: Traffic Grid
incomplete
3: A* Search Algorithm
incomplete
4: A* Code
incomplete
5: A* Search Review
incomplete
This lesson's interactive features are locked, please to keep using them
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.
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: