TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tutosrive/avl_tree_car/llms.txt
Use this file to discover all available pages before exploring further.
Obstacle class is the core value stored in every AVL tree node. It represents a road hazard placed at a precise (x, y) position on the simulation road. Every structural operation the tree performs — insertion, search, deletion, traversal — ultimately works with Obstacle instances, making a solid understanding of this model essential before exploring the tree itself.
Obstacle Class
AnObstacle is constructed with three arguments: the x and y coordinates (both float) that fix its position on the road, and an integer type_id that maps to one of the ten predefined hazard categories. The id field is auto-generated at construction time using RandomsUtils.random_id.
to_dict() returns a flat dictionary suitable for JSON serialisation over Socket.IO or REST:
ID Generation
Every obstacle receives an 8-character string ID generated byRandomsUtils.random_id(8, 2). The second argument (int_every=2) controls the pattern: even-indexed positions (0, 2, 4, 6) receive a random digit (0–9) and odd-indexed positions (1, 3, 5, 7) receive a random capital letter (A–Z). This alternating scheme produces IDs such as 0A2B4C6D or 1X3Y5Z7W.
digit-letter-digit-letter-… pattern:
Type IDs
Each obstacle carries atype_id integer that the frontend maps to a specific sprite, collision hitbox, and damage value. The ten available types are defined in obstacles_types.json:
| ID | Type | Damage |
|---|---|---|
| 1 | Cone | 0.5 |
| 2 | Rock | 1 |
| 3 | Tree | 10 |
| 4 | Tire | 5 |
| 5 | Nail | 4 |
| 6 | Trunk | 6 |
| 7 | Person | 3 |
| 8 | Car | 15 |
| 9 | Bicycle | 7 |
| 10 | Chair | 6 |
src/data/obstacles_types.json:
Node Wrapper
Obstacle objects are never stored directly in the tree — they are wrapped in a Node. Each Node holds the obstacle as value, plus left/right child pointers, a parent pointer, and the height integer used for balance-factor calculations. Newly created nodes start with height = 1.
Node.to_dict() serializes the full subtree rooted at that node, embedding the obstacle’s to_dict() output under the value key alongside the recursively serialized left and right children and the node’s height.
Uniqueness Constraint
Two obstacles are considered duplicates when they share the same
(x, y) coordinate pair. The AVLTree.insert method calls search before inserting and rejects the new obstacle if a node with matching x and y already exists. The x-only BST ordering means two obstacles can share the same x value at different y positions and coexist in the tree; only an exact (x, y) match is refused.