How to implement a fixed-size stack in Python to simulate maze movement with scoring?

6 days ago 13
ARTICLE AD BOX

I’m a university student working on a Data Structures lab where I need to simulate maze navigation using a stack.

The stack must have a maximum size of 25 and I need to track score based on actions.


Action Stack Operation Score Change

Move forward push(direction) +10

Dead-end(backtrack) pop() –5

Peek current peek() 0

Stack full push → overflow –20

Stack empty pop → underflow (just show error)

Exit reached — +50


Example sequence

push("Left") → score +10 push("Right") → score +10 pop() → score –5 push("Forward") → score +10 push("Left") → score +10 push(...) beyond capacity → overflow (–20) pop until empty → each pop –5

What I need help with

Implementing push, pop, and peek using a Python list (without using any stack library)

Checking overflow (when full) and underflow (when empty)

Updating and printing stack contents and score after every operation


Preferred language

Python


Goal

I want to understand how stack logic works in maze navigation (LIFO). A simple working example with print statements after each step would help a lot.

Thank you!

Read Entire Article