September 29, 2026

Text based pointing game for car driving

One problem with grounded language that its hard to give a sense making example which can be implemented in a short amount of code lines. A possible answer is a NPC quest generator which is generating tasks as textual output. The following python program has only 33 lines of code and generates random quests for a car driving game.

All the quests are pointing challenges, the human is asked to point at a certain object in the scene. The software can't verified if the human has pointed at the correct object, but only the quest itself is shown on the screen.

The implementation in python is as simple as possible. There is a python dict with possible target location which are selected randomly by the software. So its some sort dictionary with a random element. To solve the tasks, that human needs to know what a certain word means. For example "Focus on the pedestrian on sidewalk." is asking for a certain object at a certain position. 

screenshot:

==================================================
  3D DRIVING GAME: NPC POINTING QUEST GENERATOR
==================================================
Press [ENTER] for a new quest | Type 'q' + [ENTER] to quit

[Quest #1] Ready? 
 >> NEW QUEST: Focus on the pedestrian on sidewalk.
--------------------------------------------------
[Quest #2] Ready? 
 >> NEW QUEST: Focus on the parking spot.
--------------------------------------------------
[Quest #3] Ready? 
 >> NEW QUEST: Track the parking spot.
--------------------------------------------------
[Quest #4] Ready? 
 >> NEW QUEST: Locate the car on the left lane.
--------------------------------------------------
[Quest #5] Ready? 
 

source code:

import random

# Driving game targets organized by relative 3D perspective from behind the wheel
TARGETS = {
    "traffic_controls": ["traffic light", "speed limit sign", "stop sign", "yield sign"],
    "road_features": ["street ahead", "crosswalk", "lane line", "pothole", "guardrail"],
    "vehicles": ["car in front", "car on the left lane", "car on the oncoming side", "truck in side mirror", "motorcycle in rearview mirror"],
    "environment": ["pedestrian on sidewalk", "billboard", "parking spot", "street lamp"]
}

VERBS = ["point at", "focus on", "locate", "target", "track"]

def generate_quest():
    category = random.choice(list(TARGETS.keys()))
    obj = random.choice(TARGETS[category])
    verb = random.choice(VERBS)
    return f'{verb.capitalize()} the {obj}.'

def main():
    print("=" * 50 + "\n  3D DRIVING GAME: NPC POINTING QUEST GENERATOR\n" + "=" * 50)
    print("Press [ENTER] for a new quest | Type 'q' + [ENTER] to quit\n")
    
    count = 1
    while True:
        cmd = input(f"[Quest #{count}] Ready? ").strip().lower()
        if cmd == 'q':
            print("\nGenerator stopped. Keep your eyes on the road!")
            break
        print(f" >> NEW QUEST: {generate_quest()}\n" + "-" * 50)
        count += 1

if __name__ == "__main__":
    main()


No comments:

Post a Comment