Skip to content

Commit a880084

Browse files
Merge pull request steam-bell-92#1150 from yuvraj-k-singh/bug/Number-Sliding-Puzzle-game
[Bug]: Scoping errors and misplaced imports in sliding puzzle game
2 parents 373043f + d835b50 commit a880084

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

games/Number-Sliding-Puzzle/Number-Sliding-Puzzle.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import sys
21
import os
2+
import sys
3+
import random
34

4-
# Point Python to the root directory so it can find the utils folder
5-
def main():
6-
global choice, empty_col, empty_row, i, item, j, moves, number_col, number_row, numbers, puzzle, row, winning_puzzle
7-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
8-
from utils.validation import get_int, get_yes_no
9-
import random
5+
# 1. Fix sys.path FIRST before trying to import custom utilities
6+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
107

8+
from utils.validation import get_int, get_yes_no
119

10+
11+
def main():
1212
print("🧩 Emoji Sliding Puzzle Game 🧩")
1313

1414
while True:
@@ -66,6 +66,7 @@ def main():
6666
print("⚠️ Number not found!")
6767
continue
6868

69+
# Validate neighbor logic and swap
6970
if (abs(number_row - empty_row) == 1 and number_col == empty_col) or \
7071
(abs(number_col - empty_col) == 1 and number_row == empty_row):
7172
puzzle[empty_row][empty_col] = choice
@@ -77,9 +78,10 @@ def main():
7778

7879
print("\n👋 Thanks for playing Emoji Sliding Puzzle!\n")
7980

80-
# get_yes_no loops automatically and returns True for 'y' and False for 'n'
81+
# Check if the player wants to replay
8182
if not get_yes_no("\n🔄 Play again? (y/n): "):
8283
break
8384

85+
8486
if __name__ == '__main__':
85-
main()
87+
main()

0 commit comments

Comments
 (0)