Mini Project
Mini Project
Submitted by -
Sr.no Name of the student Roll No.
1
CERTIFICATE
We take this opportunity to thank our project guide Prof. Kalpana Sonval
mam and Head of the department Prof. Dikshendra Sir for their valuable
guidance and for providing all the necessary facilities, which were
indispensable in the completion of this project report.
We are also thankful to all the staff members of Artificial Intelligence &
Data Science Department for their valuable time, support, comments,
suggestions and persuasion. We would also like to thank the institute for
providing the required facilities, Internet access and important books.
Index
1 Abstract 5
2 Software Requirement 6
3 Introduction 7
4 Problem Statement 8
5 Objective & Outcome 8
6 Implementation 9
7 Outcome 14
8 Conclusion 14
Abstract
Snakes and Ladders is a classic board game played by two or more players,
typically on a 10x10 grid of numbered squares. The objective is to navigate
one's game piece from the start (bottom square) to the finish (top square),
helped or hindered by ladders and snakes, respectively .
Players take turns rolling a dice and moving their token forward by the number
that appears on the top of the dice.
If a player lands on a square with the base of a ladder, they must climb the
ladder to the square at the top of the ladder.
If a player lands on the square in which there is a mouth of a snake, they must
slide down to the square which is at the end of the snake.
The game terminates until one player reaches the final square.
The game has been used in teaching various subjects, such as mathematics,
social studies, and oral health, due to its educational effectiveness in
improving students' knowledge, attitude, and behavior.
The game can be implemented using a six-faced die and a square board with
a series of numbered squares arranged in a grid.
The players use different color tokens to represent themselves.
The game can be enhanced by adding elements such as cards containing
questions, science cards, bonus cards, surprise questions, and zonk cards.
SOFTWARE AND HARDWARE REQUIREMENT
Software Requirements :
1. C++ Compiler: The program is written in C++, so a C++ compiler is
necessary.
Recommended compilers include:
● GCC (GNU Compiler Collection)
● Clang
● Microsoft Visual C++
2. Operating System : The Progarm can run on various operating systems
Including:
● Windows
● Linux
● macOS
3. Text Editor Or IDE : A text editor or integrated development environment is
needed for editing and compiling the source code. Popular choices include:
● Visual Studio Code
● Code :: Blocks
● Ecilpse
● Microsoft Visual Studio
Hardware Requirements :
3. Storage: Minimal storage space is required for storing the source code,
executable files, and any necessary libraries. A few megabytes should be
sufficient.
4. Display: A standard monitor or display screen to interact with the program
through the user interface.
5. Input Devices: A keyboard and mouse (or equivalent input devices) are
required for user interaction with the program
Introduction
Snakes and Ladders is a classic board game that has been enjoyed by
children and adults alike for generations. Originating in ancient India as
"Moksha Patam," the game has evolved over time and spread globally,
captivating players with its simple yet engaging gameplay. The game is played
on a grid of numbered squares, with players aiming to navigate their pieces
from the start to the finish, encountering ladders that help them advance and
snakes that hinder their progress .
Background
Originally created in the 13th century by Marathi Saint Sant Dnyaneshwar, Snakes
and Ladders was designed as a tool to teach children about morality and the
consequences of their actions. The game was played on a board with squares
representing virtues and vices, where players advanced or retreated based on the
square they landed on. Over time, the game spread to the Western world, where it
was introduced as a recreational pastime, emphasizing the importance of virtues like
honesty and kindness, while highlighting the consequences of vices such as greed
and dishonesty.
Key Features
1. Educational Value: Snakes and Ladders is not just a game but also a valuable
educational tool used to teach moral lessons and social values to players of
all ages.
2. Symbolism: The game's design, with ladders representing virtues and snakes
representing vices, serves as a metaphor for life's ups and downs, teaching
players about the consequences of their actions and the importance of
making ethical choices.
3. Global Appeal: From its origins in India, Snakes and Ladders has
transcended borders and cultures, becoming a universally recognized and
enjoyed board game that continues to entertain and educate players
worldwide.
4. Gameplay: With its simple rules and reliance on chance through dice rolls,
Snakes and Ladders offers a fun and interactive experience that encourages
strategic thinking and decision-making.
5. Evolution: Over the years, the game has evolved and adapted to different
cultures, with variations like "Chutes and Ladders" in the United States,
maintaining the core mechanics while incorporating local themes and
nuances.
Problem statement:
Design a mini project to implement Snake and Ladders Game using
Python.
Project Outcome:
Project Objective:
self.rank = -1
self.position = 1
def get_pos(self):
return self.position
def get_rank(self):
return self.rank
class MovingEntity:
self.end_pos = end_pos
self.desc = None
def get_end_pos(self):
if self.end_pos is None:
raise Exception("no_end_position_defined")
return self.end_pos
class Snake(MovingEntity):
"""Snake entity"""
def __init__(self, end_pos=None):
super(Snake, self).__init__(end_pos)
self.desc = "Bit by Snake"
class Ladder(MovingEntity):
"""Ladder entity"""
class Board:
self.board = {}
def get_size(self):
return self.size
self.board[pos] = moving_entity
def roll(self):
# return random number between 1 to sides
import random
ans = random.randrange(1, self.sides + 1)
return ans
class Game:
def __init__(self):
self.board = None
self.dice = None
self.players = []
self.turn = 0
self.winner = None
self.last_rank = 0
self.consecutive_six = 0
def can_play(self):
if self.last_rank != len(self.players):
return True
return False
def get_next_player(self):
"""
Return curr_turn player but if it has already
won/completed game , return
next player which is still active
"""
while True:
# if rank is -1 , player is still active so return
if self.players[self.turn].get_rank() == -1:
return self.players[self.turn]
# check next player
self.turn = (self.turn + 1) % len(self.players)
def play(self):
while self.can_play():
curr_player = self.get_next_player()
player_input = input(
f"Player {self.turn+1}, Press enter to roll the
dice")
dice_result = self.dice.roll()
print(f'dice_result: {dice_result}')
_next_pos = self.board.get_next_pos(
curr_player.get_pos() + dice_result)
if self.can_move(curr_player, _next_pos):
self.move_player(curr_player, _next_pos)
self.change_turn(dice_result)
self.print_game_state()
self.print_game_result()
def print_game_state(self):
print('-------------game state-------------')
for ix, _p in enumerate(self.players):
print(f'Player: {ix+1} is at pos {_p.get_pos()}')
print('-------------game state-------------\n\n')
def print_game_result(self):
print('-------------final result-------------')
for _p in sorted(self.players, key=lambda x:
x.get_rank()):
print(f'Player: {_p._id+1} , Rank: {_p.get_rank()}')
def sample_run():
board = Board(10)
board.set_moving_entity(7, Snake(2))
board.set_moving_entity(4, Ladder(6))
game = Game()
game.initialize_game(board, 6, 2)
game.play()
sample_run()
Output :
Conclusion :