Python stack implementation for maze navigation with scoring (fixed capacity)

6 days ago 12
ARTICLE AD BOX

I am a university student working on a Data Structures lab about simulating maze navigation using a stack with limited memory.

The stack must have a fixed capacity of 25 moves, and the movement rules are:

Move forward → push(direction) → +10 points

Dead-end → pop() → –5 points

Current position → peek/top

Try to push when stack is full → overflow (–20 points)

Try to pop when stack is empty → underflow

Exit reached → +50 points

Example movement sequence:

push("Left") push("Right") pop() # dead-end push("Forward") push("Left") push(...) # beyond stack capacity → test overflow pop repeatedly # return to start

What I need help with:

Stack implementation using a Python list (no built-in stack libraries)

Handling overflow, underflow, and scoring

Printing stack content and score after each move

Missing Code:
I started defining a stack class but I am unsure how to apply scoring and full/empty conditions properly.

class Stack: def __init__(self, capacity=25): self.items = [] self.capacity = capacity self.score = 0 # missing push, pop, peek logic with scoring...

I need a complete example that simulates the sequence above and prints stack state and score step-by-step.

Preferred language: Python
Thanks!

Read Entire Article