diff --git a/Codes/Python/Number-Puzzle-Game/Puzzle_game.py b/Codes/Python/Number-Puzzle-Game/Puzzle_game.py new file mode 100644 index 0000000..63d2f6b --- /dev/null +++ b/Codes/Python/Number-Puzzle-Game/Puzzle_game.py @@ -0,0 +1,67 @@ +import random + +# Function to display the board +def display(board): + for row in board: + print(" ".join(str(x) if x != 0 else " " for x in row)) + print() + +# Function to find the position of 0 (empty space) +def find_empty(board): + for i in range(3): + for j in range(3): + if board[i][j] == 0: + return i, j + +# Function to check if the puzzle is solved +def is_solved(board): + target = [[1, 2, 3], + [4, 5, 6], + [7, 8, 0]] + return board == target + +# Function to make a move +def move(board, direction): + i, j = find_empty(board) + if direction == 'up' and i < 2: + board[i][j], board[i+1][j] = board[i+1][j], board[i][j] + elif direction == 'down' and i > 0: + board[i][j], board[i-1][j] = board[i-1][j], board[i][j] + elif direction == 'left' and j < 2: + board[i][j], board[i][j+1] = board[i][j+1], board[i][j] + elif direction == 'right' and j > 0: + board[i][j], board[i][j-1] = board[i][j-1], board[i][j] + else: + print("โŒ Invalid move!") + +# Function to shuffle the board +def shuffle_board(board): + moves = ['up', 'down', 'left', 'right'] + for _ in range(50): + move(board, random.choice(moves)) + +# Main Game +def puzzle_game(): + board = [[1, 2, 3], + [4, 5, 6], + [7, 8, 0]] + + shuffle_board(board) + print("๐Ÿงฉ Welcome to the Number Puzzle Game!") + print("Arrange the numbers from 1 to 8. Use commands: up, down, left, right\n") + + while True: + display(board) + if is_solved(board): + print("๐ŸŽ‰ Congratulations! You solved the puzzle!") + break + + move_input = input("Move (up/down/left/right or 'quit'): ").lower() + if move_input == "quit": + print("๐Ÿ‘‹ Thanks for playing!") + break + move(board, move_input) + +# Run the game +if __name__ == "__main__": + puzzle_game() diff --git a/Codes/Python/Number-Puzzle-Game/Readme b/Codes/Python/Number-Puzzle-Game/Readme new file mode 100644 index 0000000..e182431 --- /dev/null +++ b/Codes/Python/Number-Puzzle-Game/Readme @@ -0,0 +1,121 @@ +# ๐Ÿงฉ Number Puzzle Game + +A lightweight, console-based **Number Puzzle Game** implemented in Python. +The objective is to arrange the numbers **1โ€“8** in ascending order by sliding tiles into the empty space. + +--- + +## ๐Ÿ“– Overview + +This project is a simple implementation of the classic 8-puzzle (3ร—3 sliding puzzle). +It demonstrates basic Python concepts such as loops, lists, conditionals, and user interaction. + +The puzzle starts in a randomized configuration, and the player can move the empty space using simple commands until all tiles are correctly arranged. + +--- + +## ๐ŸŽฏ Objective + +Arrange the numbers to achieve the following order: + +1 2 3 +4 5 6 +7 8 + +yaml +Copy code + +--- + +## โš™๏ธ Requirements + +- Python **3.8** or higher +- Works on **Windows**, **macOS**, and **Linux** + +--- + +## ๐Ÿš€ Getting Started + +### 1. Clone the Repository +```bash +git clone https://github.com//Number-Puzzle-Game.git +cd Number-Puzzle-Game +2. Run the Game +bash +Copy code +python Puzzle_game.py +3. Play +Use the following commands to move the blank space: + +css +Copy code +up +down +left +right +Type quit to exit the game. + +๐Ÿง  Game Logic +The game board is represented as a 3ร—3 list of lists. + +The blank space is represented by 0. + +A random shuffle generates the initial layout. + +The player moves the blank space using direction commands. + +The game checks if the current state matches the solved configuration. + +๐Ÿงฉ Example Gameplay +sql +Copy code +๐Ÿงฉ Arrange 1โ€“8 in order using up/down/left/right. + +1 3 +4 2 5 +7 8 6 + +Move (up/down/left/right or 'quit'): up +๐Ÿ“ Project Structure +bash +Copy code +Number-Puzzle-Game/ +โ”‚ +โ”œโ”€โ”€ Puzzle_game.py # Main game script +โ””โ”€โ”€ README.md # Project documentation +โœจ Features +โœ… Interactive command-line gameplay + +โœ… Randomized puzzle generation + +โœ… Win condition detection + +โœ… Lightweight and easy to understand + +๐Ÿ”ฎ Future Enhancements +Support for arrow key controls + +Add a Tkinter GUI version + +Implement an AI solver for demonstration + +Option to select puzzle size (3ร—3, 4ร—4, etc.) + +๐Ÿค Contributing +Contributions are welcome! +To contribute: + +Fork this repository + +Create a new branch (feature/new-feature) + +Commit your changes + +Submit a pull request + +๐Ÿงพ License +This project is licensed under the MIT License. + +๐Ÿ‘ฉโ€๐Ÿ’ป Author +Srishti Kumari +B.Tech CSE (DATA SCIENCE), Haldia Institute of Technology \ No newline at end of file diff --git a/.gitattributes b/GITATTRIBUTES Folder/.gitattributes similarity index 100% rename from .gitattributes rename to GITATTRIBUTES Folder/.gitattributes diff --git a/CONTRIBUTING.md b/MD Folder/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING.md rename to MD Folder/CONTRIBUTING.md diff --git a/README.md b/MD Folder/README.md similarity index 100% rename from README.md rename to MD Folder/README.md diff --git a/LICENSE b/NONE Folder/LICENSE similarity index 100% rename from LICENSE rename to NONE Folder/LICENSE