A
Mini Project
Report on
“SNAKE AND LADDERS”
SUBMITTED TO THE SAVITRIBAI PHULE PUNE UNIVERSITY, PUNE IN
PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE AWARD OF
SECOND YEAR COMPUTER ENGINEERING
SUBMITTED BY
SHUBHAM KAMBLE EXAM SEAT NO- S190264294
UNDER THE GUIDANCE OF
Prof. Shilpa Vishwabrahma
DEPARTMENT OF COMPUTER ENGINEERING
PUNE DISTRICT EDUCATION ASSOCIATION’S
COLLEGE OF ENGINEERING, MANJARI, PUNE-412307.
AFFILIATED TO
1
CERTIFICATE
This is to certify that the seminar report entities
“SNAKE AND LADDERS”
Submitted by
SHUBHAM KAMBLE EXAM SEAT NO-S190264294
is a bonafide work carried out by above students under the guidance of Prof.
Shilpa Vishwabrahma and it is approved for the Computer Graphics Laboratory
– Mini Project fulfilment of the requirement of Savitribai Phule Pune
University
Prof. Shilpa Vishwabrahma Prof. Dr. M. P.Borawake
Subject Teacher HOD, Computer Engineering
Dr. R.V. Patil
Principal
PUNE DISTRICT EDUCATION ASSOCIATION’S
COLLEGE OF ENGINEERING, MANJARI, PUNE-412307
2
DATA STRUCTURES AND
ALGORTIHMS
MINI PROJECT
Problem Statement:-
Design a mini project to implement Snake and Ladders Game using Python.
Introduction:-
Snake and Ladders is a classic board game enjoyed by people of all ages.
Implementing this game in Python provides a great opportunity to practice
programming concepts such as data structures, loops, conditionals, and user
interaction. In this mini project, we will design and implement a Snake and Ladders
game using Python. Let's embark on this exciting journey of building our own Snake
and Ladders game in Python!
3
PYTHON PROGRAM CODE
import random
def create_board():
"""Initialize the game board with snakes and ladders positions."""
board = list(range(1, 101))
snakes = {16: 6, 47: 26, 49: 11, 56: 53, 62: 19, 64: 60, 87: 24, 93: 73, 95: 75, 98: 78}
ladders = {1: 38, 4: 14, 9: 31, 21: 42, 28: 84, 36: 44, 51: 67, 71: 91, 80: 100}
return board, snakes, ladders
def get_num_players():
"""Ask the user for the number of players."""
num_players = int(input("Enter the number of players: "))
return num_players
def get_player_names(num_players):
"""Ask the user for the names of each player."""
players = [input(f"Enter name for Player {i+1}: ") for i in range(num_players)]
return players
def roll_dice():
"""Simulate rolling a dice."""
return random.randint(1, 6)
def move_player(player, player_position, snakes, ladders):
"""Move the player on the board."""
current_position = player_position[player]
dice_roll = roll_dice()
new_position = current_position + dice_roll
if new_position in snakes:
new_position = snakes[new_position]
print(f"{player} landed on a snake! Moved to position {new_position}")
elif new_position in ladders:
new_position = ladders[new_position]
print(f"{player} landed on a ladder! Moved to position {new_position}")
else:
print(f"{player} rolled a {dice_roll}. Moved to position {new_position}")
return new_position
def check_win(player, position):
"""Check if the player has won the game."""
if position >= 100:
print(f"{player} wins!")
return True
return False
4
def play_game(players, board, snakes, ladders):
"""Main game loop."""
player_position = {player: 0 for player in players}
while True:
for player in players:
input(f"{player}, press Enter to roll the dice.")
player_position[player] = move_player(player, player_position, snakes, ladders)
if check_win(player, player_position[player]):
return
play_again = input("Do you want to play again? (yes/no): ")
if play_again.lower() != 'yes':
break
# Main code
board, snakes, ladders = create_board()
num_players = get_num_players()
players = get_player_names(num_players)
play_game(players, board, snakes, ladders)
5
OUTPUT:-
6
CONCLUSION
In conclusion, the journey of designing and implementing a Snake and Ladders game
using Python has been both educational and enjoyable. Through this mini project,
we've explored various programming concepts and techniques, while also creating a
classic board game that provides entertainment and challenges for players.
Throughout the project, we've gained valuable experience in:
1. Problem Solving: Tackling challenges related to game logic, player movement,
and win conditions required creative problem-solving skills.
2. Python Programming: Applying Python programming concepts such as data
structures, loops, conditionals, and functions to implement the game's
functionalities.
3. User Interaction: Designing a user-friendly interface for players to interact with
the game, including inputting dice rolls and viewing game progress.
4. Testing and Debugging: Testing the game thoroughly and debugging issues to
ensure smooth gameplay and functionality.
5. Project Organization: Structuring the project code in a clear and organized
manner, making it easy to understand and maintain.