Ludo game using c++ with documentation

Mauryasuraj98 8,243 views 12 slides Jun 22, 2019
Slide 1
Slide 1 of 12
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12

About This Presentation

Ludo game using c++ with documentation


Slide Content

PROFESSIONAL LUDO


Computer Graphics


S. E. Computer Engineering
Division B

Under the guidance of
Ms. Vannesa D’Britto

By

Suraj Maurya 53
Neel Shukla 65











Department of Computer Engineering
St. Francis Institute of Technology
University of Mumbai
2018-2019

TABLE OF CONTENTS
Chapter Contents Page
No.
1 INTRODUCTION 3
2 PROBLEM DEFINITION 3
3 ALGORITHM / STEP 4
4 IMPLEMENTATION 5-12
5 RESULTS 13
6 CONCLUSIONS AND FUTURE SCOPE 14
7 REFERENCES 14

INTRODUCTION

Ludo is a board game for two to four players, in which the players race their four tokens from
start to finish according to die rolls. PK just landed on earth and found this game. He’s alone.
He found this game, but no one to play with. So he decided to play alone. He made some
tweaks in the board. In the path from the origin to home (H) he placed some check points(C)
and some restricted cells(X). On the journey from source to destination he has to cover all the
check points and cannot stay at the restricted cells (should skip over).
Assuming he can get any number on the die. Also, he plays with only one die and always starts
with his favorite color yellow.
The cells are marked (1 - 56, Home is 57) from source to destination, he needs a six to start off.
Its main purpose lies in the comparison of several approaches in the area of artificial
intelligence. At one side, Ludo is instead a very simple game and is fully observable but on the
other s de it contains a few challenges due to t e stochastic and multi agent environment.
Therefore it offers a good balance between simplicity and complexity and is able to attract a
wide audience and not only professionals. In addition, it is very common and well- known
around the world.
LUDO means, “I play “. It is a board game for two, three, or four players. In this game the
players’ race against their four tokens from initial to end state according to roll of a dice Played
by four players, Ludo is a board divided into four main areas:

• Red
• Blue
• Green
• Yellow

Each player occupies one area of a color. In this he is given four to kens of his chosen color
that he race around the board to win. The Ludo board is generally a square with the game track
that is cross-shaped. Here each arm in the cross consists of three columns that are subdivided
into again squares—generally six squares within a single column. Representing the home
column of player, there are five colored squares in the middle column of every cross part,.
There is a sixth colored square that is not a home column square but the initial point of every
player to start the race. At the board center there is a large square that is home for every player.
If a player reaches in this area with all four tokens, he wins.

2. PROBLEM DEFINITION
THE SOURCE CODE DECLARED ABOVE FOR THE PROGRAM OF PROFESSIONAL
LUDO HAS BEEN TESTED AND IT HAS BEEN FOUND THAT THE ABOVE SOURCE
CODE IS OKAY AND CORRECT. THE PROGRAM INVOLVES MANY
TYPE OF CONVERSIONS. THESE CONVERSIONS HAS TO DONE CAREFULLY.
MAINLY THERE ARE TWO TYPES OF TESTING:
1-SYSTEM TESTING AND
2-INTEGRATION TESTING
SYSTEM TESTING INVOLVES WHOLE TESTING OF PROGRAM AT ONCE AND
INTEGRATION TESTING
INVOLVES THE BREAKING OF PROGRAM INTO MODULES & THEN TEST.


3. Algorithm / Step (Explain the different modules/functions used)

 We have to run the code in turbo C.
 Give name of 4 payers as per the color code you like. Select the option between computer
player or a real player
 To roll the dice press enter once if 6 came at first attempt your token will be ready for
playing else next chance will be passed to another player.
 In the same way until a player gets his all 4 tokes at home he is the winner and accordingly
ranks are set
 The player who is unable to get all his tokens at home before another player is termed as
looser.

4. IMPLEMENTATION (Code)

#include<graphics.h>
#include<fstream.h>
#include<string.h>
#include<stdlib.h>
#include<limits.h>
#include<ctype.h>
#include<conio.h>
#include<stdio.h>
#include<dos.h>
int ppos[53][2],wincount=0,win[4]={0,0,0,0},seed=0;
int safepos[8]={1,9,14,22,27,35,40,48};
int ipos[4][8]={
65,125, 335, 65, 395,335, 125,395, 65, 65, 395, 65, 335,395, 65,395,
125, 65, 335,125, 335,335, 125,335, 125,125, 395,125, 395,395, 65,335,
};
int grid[58][8]={
65,125, 335, 65, 395,335, 125,395, 50,200, 260, 50, 410,260, 200,410,
80,200, 260, 80, 380,260, 200,380, 110,200, 260,110, 350,260, 200,350,
140,200, 260,140, 320,260, 200,320, 170,200, 260,170, 290,260, 200,290,
200,170, 290,200, 260,290, 170,260, 200,140, 320,200, 260,320, 140,260,
230,440, 20,230, 230, 20, 440,230, 200,440, 20,200, 260, 20, 440,260,
20,260, 200, 20, 440,200, 260,440, 20,230, 230, 20, 440,230, 230,440,
50,230, 230, 50, 410,230, 230,410, 80,230, 230, 80, 380,230, 230,380,
110,230, 230,110, 350,230, 230,350, 140,230, 230,140, 320,230, 230,320,
170,230, 230,170, 290,230, 230,290, 210,230, 230,200, 260,230, 230,260,
};
int st1a[]={200, 67,189, 87,211, 87},st1b[]={189, 73,200, 93,211, 73};
int st2a[]={380,187,369,207,391,207},st2b[]={369,193,380,213,391,193};
int st3a[]={260,367,249,387,271,387},st3b[]={249,373,260,393,271,373};
int st4a[]={ 80,247, 69,267, 91,267},st4b[]={ 69,253, 80,273, 91,253};
class player
{
int colour[4],key,code,dice[4],dnum,tnum,AI;
int calpos(int,int);
int decide(int);
int dscore(int);
int movecheck(int,int);
void roll();
void show(int);
void killcheck(int);
int stchk(int);
void repaint(int);
void typewinner();
void mksound()
{
sound(1500);delay(55);
nosound();tnum++;
}
public:

}
gotoxy(78,24);for(i=77;i>=4;i--)
{
gotoxy(i,24);putch(205);
}
gotoxy(3,24);putch(200);
for(i=23;i>=3;i--)
{
gotoxy(3,i);putch(186);
}
}

void intro()
{
clrscr();box();
char name[20],ch;
textcolor(6);
gotoxy(21,3);cputs("____________________________________");
gotoxy(22,4);cputs("Welcome to Professional LUDUS ");
gotoxy(21,5);cputs("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
textcolor(2);
gotoxy(10,7);cputs("GREEN PLAYER");
gotoxy(15,8);cputs("Enter Name:");gets(name);
gotoxy(15,9);cputs("Computer Controlled? (y/n):");ch=getche();
if(toupper(ch)=='Y')
green.pinit(2,14,9,4,0,name,1);
else
green.pinit(2,14,9,4,0,name,0);
textcolor(14);
gotoxy(10,11);cputs("YELLOW PLAYER");
gotoxy(15,12);cputs("Enter Name:");gets(name);
gotoxy(15,13);cputs("Computer Controlled? (y/n):");ch=getche();
if(toupper(ch)=='Y')
yellow.pinit(14,9,4,2,2,name,1);
else
yellow.pinit(14,9,4,2,2,name,0);
textcolor(9);
gotoxy(10,15);cputs("BLUE PLAYER");
gotoxy(15,16);cputs("Enter Name:");gets(name);
gotoxy(15,17);cputs("Computer Controlled? (y/n):");ch=getche();
if(toupper(ch)=='Y')
blue.pinit(9,4,2,14,4,name,1);
else
blue.pinit(9,4,2,14,4,name,0);
textcolor(4);
gotoxy(10,19);cputs("RED PLAYER");
gotoxy(15,20);cputs("Enter Name:");gets(name);
gotoxy(15,21);cputs("Computer Controlled? (y/n):");ch=getche();
if(toupper(ch)=='Y')
red.pinit(4,2,14,9,6,name,1);
else
red.pinit(4,2,14,9,6,name,0);
delay(100);
}
void quit()
{
cleardevice();closegraph();
clrscr();box();textcolor(4);
gotoxy(20,11);cputs("*************************************\n");
gotoxy(20,12);cputs("Thank you for using this software....\n");
gotoxy(20,13);cputs("*************************************\n");
delay(2000);
for(int i=23;i>=7;i-=1)
{
clrscr();box();textcolor(14);
gotoxy(32,5);cputs("CREDITS");
gotoxy(32,6);cputs("~~~~~~~");
if(i<24)
{
gotoxy(23,i);
cputs("Professional LUDUS ");
}
if(i<23)
{
gotoxy(22,1+i);
cputs("~~~~~~~~~~~~~~~~~~~~~~~~~~");

}
if(i<21)
{
gotoxy(22,3+i);
cputs("Concept & Coding : Suraj & Neel");
}
if(i<20)
{
gotoxy(22,4+i);
cputs("Design & Graphics : Neel");
}
if(i<19)
{
gotoxy(22,5+i);
cputs("Supervisor : Ms. Vanessa D'Britto");
}
if(i<18)
{
gotoxy(22,6+i);
cputs("Language : Borland Turbo C++");

}

delay(100);
}
delay(2000);getch();
exit(0);
}
void drawstar()
{
setcolor(2);setfillstyle(1,2);fillpoly(3,st1a);fillpoly(3,st1b);
setcolor(14);setfillstyle(1,14);fillpoly(3,st2a);fillpoly(3,st2b);
setcolor(9);setfillstyle(1,9);fillpoly(3,st3a);fillpoly(3,st3b);
setcolor(4);setfillstyle(1,4);fillpoly(3,st4a);fillpoly(3,st4b);
}
void board()
{
char str[100]={"Professional LUDUS "};
setcolor(2);settextstyle(1,0,2);
outtextxy(115,455,str);
strcpy(str,"Made By - Suraj & Neel");
setcolor(14);settextstyle(2,0,5);
outtextxy(420,465,str);
int ar1[]={185,185,230,230,185,275};
int ar2[]={185,185,230,230,275,185};
int ar3[]={275,185,230,230,275,275};
setcolor(15);
setfillstyle(1,2);bar3d(35,185,65,245,0,0);bar3d(65,215,185,245,0,0);
setfillstyle(1,14);bar3d(215,35,275,65,0,0);bar3d(215,65,245,185,0,0);
setfillstyle(1,4);bar3d(215,275,245,395,0,0);bar3d(185,395,245,425,0,0);
setfillstyle(1,9);bar3d(275,215,395,245,0,0);bar3d(395,215,425,275,0,0);
for(int i=5;i<=455;i+=30)
{
line(5,i,455,i);line(i,5,i,455);
}
setfillstyle(1,2);bar3d(5,5,185,185,0,0);
setfillstyle(1,15);bar3d(35,35,155,155,0,0);
setcolor(2);
setlinestyle(1,1,3);
circle(65,65,14);circle(65,125,14);
circle(125,65,14);circle(125,125,14);
setlinestyle(0,0,1);setcolor(15);
setfillstyle(1,14);bar3d(275,5,455,185,0,0);
setfillstyle(1,15);bar3d(305,35,425,155,0,0);

setcolor(14);
setlinestyle(1,1,3);
circle(335,65,14);circle(395,65,14);
circle(335,125,14);circle(395,125,14);
{
case 0: green.typewinner();
case 1: yellow.typewinner();
case 2: blue.typewinner();
case 3: red.typewinner();
}
break;
}
case 4:
{
outtextxy(520,345,name);
getch();quit();
}
}
}
void player::show(int n)
{
setcolor(0);setfillstyle(1,15);
bar3d(530,50,570,90,0,0);
switch(n)
{
case 1:
{
setfillstyle(1,0);
fillellipse(550,70,4,4);
break;
}
case 2:
{
setfillstyle(1,0);
fillellipse(540,60,4,4);
fillellipse(560,80,4,4);
break;
}
case 3:
{
setfillstyle(1,0);
fillellipse(560,60,4,4);
fillellipse(550,70,4,4);
fillellipse(540,80,4,4);
break;
}
case 4:
{
setfillstyle(1,0);
fillellipse(540,60,4,4);
fillellipse(540,80,4,4);
fillellipse(560,60,4,4);
fillellipse(560,80,4,4);
break;
int flag1=1;
for(int l=0;l<4;l++)
if(gpos[i]+d==gpos[l] && stchk(gpos[l])!=1)
if(gpos[l]!=57)
flag1=0;
if(flag1)
return(1);
}
}
}

else
{
if(gpos[num]==0 && d==6)
return(1);
if(gpos[num]!=0 && (gpos[num]+d)<=57)
{
for(int l=0;l<4;l++)
if(gpos[num]+d==gpos[l] && stchk(gpos[l])!=1)
if(gpos[l]!=57)
return(0);
return(1);
}
}
return(0);
}
void player::roll()
{
char ch,str[10];
setcolor(0);setfillstyle(1,0);bar3d(461,113,634,274,0,0);
setcolor(6);setfillstyle(1,0);
randomize();
if(dnum==0)
for(int i=0;i<3;i++)
bar3d(520+20*i,92,540+20*i,112,0,0);
settextstyle(2,0,5);outtextxy(480,30, "Hit any key to Roll.");

if((a<51 && b>51) || stchk(b)==1) //future position
score[i]+=3;
if(movecheck(dic,i)==1 && b<52)
{
for(int j=1;j<13;j++) //look enemy behind
{
if((y-j)>=0)
if(ppos[y-j][0]!=-1 && ppos[y-j][0]!=code)
score[i]-=dscore(j);
else
{
int ind=(52+y-j);
if(ppos[ind][0]!=-1 && ppos[ind][0]!=code)
score[i]-=dscore(j);

outtextxy(465,128,"3 Sixes cancel Out..");
dnum=0;delay(1000);
}
}
int sum=gpos[0]+gpos[1]+gpos[2]+gpos[3];
if(sum==228)
typewinner();
if(sum!=228 && tnum>0)
{
setcolor(0);setfillstyle(1,0);
bar3d(461,113,634,274,0,0);settextstyle(2,0,5);
setcolor(6);outtextxy(465,120,"You get Extra Turn..");
tnum--;delay(1000);turn();
}
}
void player::repaint(int k)
{
if(gpos[k]!=0 && gpos[k]!=57)

if(n==-1)
{
setcolor(0);setfillstyle(1,0);
}

if(i==0)
{
}
else if(i==15)
{
setcolor(colour[1]);setfillstyle(1,colour[1]);
fillellipse(grid[14][key],grid[14][key+1],10,10);
}
else if(i==28)
{
setcolor(colour[2]);setfillstyle(1,colour[2]);
fillellipse(grid[27][key],grid[27][key+1],10,10);
}
else if(i==41)
{
setcolor(colour[3]);setfillstyle(1,colour[3]);
fillellipse(grid[40][key],grid[40][key+1],10,10);
}
else if(i>52)
{
setcolor(colour[0]);setfillstyle(1,colour[0]);
{
green.repaint(j);
red.repaint(j);
yellow.repaint(j);
blue.repaint(j);
}
}
void game()
{
for(int i=0;i<52;i++)
for(int j=0;j<2;j++)
ppos[i][j]=-1;
for(i=0;i<4;i++)
{
green.move(i,green.gpos[i]);
red.move(i,red.gpos[i]);

}
while((green.result+red.result+yellow.result+blue.result)!=3)
{
if(green.result!=1)
green.turn();
if(yellow.result!=1)
yellow.turn();
if(blue.result!=1)
blue.turn();
if(red.result!=1)
red.turn();
}
}
void main()
{
intro();
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, "");
board();game();
}

5. RESULTS (SNAPSHOTS)

6. CONCLUSION AND FUTURE SCOPE
We have successfully completed our mini project ‘PROFESSIONAL LUDO’ in Computer
Graphics. The game will have a total number of 4 players each player will have its own personal
home. There can be only one winner and 2
nd
and 3
rd
runner up the 4
th
player will lose the game.
To exit the game we have to press “q” key.
For future scope we are implementing an AI program which will automatically play against a real
player like a computer mind. Also different levels of difficulty could be set within.