/* Developed by "akshay kumar srivastava

"*/
/* phone 09835457174
oct 2005*/
/* aks_mailin@rediffmail.com*/
/* dont press Esc key at start of game*/
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<math.h>
#include<stdlib.h>
/* MOUSE FUNCTIONS FOR LUDO GAME */
int DetectMouse(void);
void InitMouse(void);
void ShowMouse(void);
void HideMouse(void);
void WhereMouse(int*,int*);
int ButtClicked(void);
int ButtReleased(void);
int DetectMouse(void){
union REGS in,out;
in.x.ax=0;
int86(0x33,&in,&out);
if(out.x.ax==0)
return(0);
else
return(1);
}
void InitMouse(void)
{
union REGS in,out;
in.x.ax=33;
int86(0x33,&in,&out);
return;
}
void HideMouse(void)
{
union REGS in,out;
in.x.ax=2;
int86(0x33,&in,&out);
return;
}
void ShowMouse(void)

{
union REGS in,out;
in.x.ax=1;
int86(0x33,&in,&out);
return;
}
void WhereMouse(int *x,int *y)
{
union REGS in,out;
in.x.ax=3;
int86(0x33,&in,&out);
*x=(int)out.x.cx;
*y=(int)out.x.dx;
return;
}
int ButtClicked(void){
union REGS imouse,omouse;
int mc,mr;
imouse.x.ax = 3;
int86(0x33,&imouse,&omouse);
mc=omouse.x.bx;
return(mc);
}
int ButtReleased(void){
int br;
br=ButtClicked();
do{}while(ButtClicked()!=0);
return br;
}

/* GLOBAL VARIABLES */
int background=0;
int colorfortext=WHITE;//color used to display text
int rec=MAGENTA;//color for border of rectangles
int flagturn;//players turn=0 computer=1
int for6=0;//for 6 to come at regular intervals
int dice_value_color[4];
/* USER DEFINED FUNCTIONS */
void draw_all(void);
int player_chooses_house_color(void);
void draw_house(int color_of_house,int top_left_x_coordinate,int

top_left_y_coordinate);
void draw_button_with_button_name(int top_left_x_coordinate,int
top_left_y_coordinate,char* button_name);
void show_mouse_click_on_button(int mouse_click_x_coordinate,int
mouse_click_y_coordinate);
int check_if_mouse_click_is_on_any_button (int
mouse_click_x_coordinate,int mouse_click_y_coordinate);
void throw1(int x_coordinate_for_dice ,int y_coordinate_for_dice,int
counter_for_wait_at_last ,char dice_value);
void throw2(int x_coordinate_for_dice ,int y_coordinate_for_dice,char
dice_value);
int throwdice(void);
void messageout(char *message,int refresh_message=1);
void messageclear(void);
void initialise_house_with_ludos(int color_of_house);
void load_path_information_in_ludos(int ludo_house_color);
void winner(void);
void about(void);
void howtoplay(void);
void redrawing(int );
int catchclickonludobutton(void) ;
int forcomputer1(int);
int forcomputer2(int);
int forcomputer3(int);
struct ludo{
int x[45];
int y[45];
int pos;
int color;
void (*ptr_ludo1)(int,int*,int*,ludo *);
int (*ptr_check_if_ludo_move_requested_is_valid)(int ,ludo*);
void (*ptr_move_ludo_to_new_position)( int ,ludo*);
};
struct ludo lp[4],lc1[4],lc2[4],lc3[4];
/* ludo1 initialises the ludo class objects */
void ludo1(int col,int *ax,int *ay,ludo *node)
{
int i;
for(i=0;i<=44;i++)
{

if( (node->pos<=44-dice && node->pos!=0) || (node->pos==0 && dice==6) ) return(1). ax++.i<=dice+opos. // ludo can move for(i=0.//choose the correct ludo that can move else return(3).e proceed to movetopos. } node->color=col. for(i=opos. if(node->pos==0 && dice==6)//taking out of house on dice givig 6 { messageclear(). node->pos=0.i++) { if( (lp[i].//i.i++) .i<=3.ay++.pos+dice<=44 && lp[i].e there is atleast one ludo which //can move with current dice value } if(j>0) return(2). node->y[i]=*(ay). opos=node->pos. int opos.0 if not valid 2 if player cannot move any ludo*/ int i.node->x[i]=*(ax).ludo *node) { HideMouse().//no ludo can move at current dice value //and player has to skip chance }//end of check_if_ludo_move_requested_is_valid void move_ludo_to_new_position( int dice .dice=1.ludo *node) { /*return 1 move valid i.pos!=0) || (lp[i].} dice=dice-1.pos==0 && dice==6) ) j=1.j=0. int i. }//end of ludo1 int check_if_ludo_move_requested_is_valid(int dice.

pos] && node->y[node->pos]==lc2[i].pos] && node->y[node->pos]==lp[i].y[lc3[i].x[lc1[i]. floodfill(node->x[i].8).pos=0.node->y[i].color) lc1[i]. } if(node->x[node->pos]==lc3[i].y[lc1[i]. . delay(50).pos] ) { if(node->color!=lc1[i].pos] && node->y[node->pos]==lc3[i].x[lc3[i].pos] ) { if(node->color!=lc2[i]. } /*changing pos to 0 if ludo has been cut before redrawing all ludos*/ for(i=0.node->y[i+1].pos=0.8). } if(node->x[node->pos]==lc2[i].{ setcolor(7).color).} setcolor(node->color).pos] ) { if(node->color!=lc3[i].7).y[lc2[i].pos=0.pos] ) { if(node->color!=lp[i].7). circle(node->x[i]. setfillstyle(1. setfillstyle(1.color) lp[i].i<=3. circle(node->x[i+1].node->color).i++) { if(node->x[node->pos]==lp[i]. } }// end of for /* redrawing new positions of all ludos */ redrawing(lp[0].x[lp[i]. redrawing(node->color).node->y[i]. {node->pos++. delay(50).node->color).y[lp[i].node->y[i+1]. } if(node->x[node->pos]==lc1[i].color) lc3[i].x[lc2[i].pos] && node->y[node->pos]==lc1[i].pos=0.color) lc2[i]. floodfill(node->x[i+1].

. ShowMouse().zx<4. redrawing(lc3[0]. /* to check who is the winner */ static int number_of_player_ludo_home=0.color). if(node->pos==44 && flagturn==2) number_of_computer2_ludo_home++.ptr_ludo1=ludo1.ptr_check_if_ludo_move_requested_is_valid=check_if_ludo_move_reques ted_is_valid. lc3[zx].lc1[4]. if(node->pos==44 && flagturn==1) number_of_computer1_ludo_home++. for( zx=0.ptr_ludo1=ludo1. static int number_of_computer3_ludo_home=0. int zx. redrawing(lc2[0].ptr_ludo1=ludo1. if(number_of_computer1_ludo_home==4) winner(). if(number_of_computer2_ludo_home==4) winner().color). lc2[zx].lc2[4]. void changingcpptoc(void) { //struct ludo lp[4]. lp[zx].lc3[4].lc1[4].lc2[4]. if(node->pos==44 && flagturn==3) number_of_computer3_ludo_home++. static int number_of_computer1_ludo_home=0.zx++) { lp[zx].redrawing(lc1[0]. if(number_of_player_ludo_home==4) winner().lc3[4].ptr_ludo1=ludo1. lc1[zx]. if(node->pos==44 && flagturn==0) number_of_player_ludo_home++.color). if(number_of_computer3_ludo_home==4) winner(). static int number_of_computer2_ludo_home=0. } //end of move_ludo_to_new_position //end of ludo class //struct ludo lp[4].

//gives life to correct color ludo as path depends on color /* this code helps in making the chance of throwing dice go in a clockwise mode what color may the player choose to play*/ i=3.lc1[zx]. while(i) { if(colors[i]==playercolor) break.ptr_check_if_ludo_move_requested_is_valid=check_if_ludo_move_reque sted_is_valid. lc2[zx]. flagturn=0.a.. lc3[zx]..ptr_move_ludo_to_new_position=move_ludo_to_new_position. lc1[zx].ptr_move_ludo_to_new_position=move_ludo_to_new_position.ptr_move_ludo_to_new_position=move_ludo_to_new_position. . load_path_information_in_ludos(playercolor). //void (*ptr_move_ludo_to_new_position)( int ). }//for zx loop ends } void main() { changingcpptoc(). i--. ShowMouse().GREEN}. int colors[4]={RED.ptr_check_if_ludo_move_requested_is_valid=check_if_ludo_move_reque sted_is_valid. dice_value_color[flagturn]=playercolor. //int (*ptr_check_if_ludo_move_requested_is_valid)(int ). lc3[zx].ptr_move_ludo_to_new_position=move_ludo_to_new_position..playercolor.YELLOW.BLUE. int i.b. lc2[zx]. playercolor=player_chooses_house_color()..dice=0. lp[zx]. draw_all(). InitMouse().ptr_check_if_ludo_move_requested_is_valid=check_if_ludo_move_reque sted_is_valid.

initialise_house_with_ludos(GREEN).break. if(flagturn==3) break. load_path_information_in_ludos(colors[loop]). while(1) { flagturn++. } initialise_house_with_ludos(RED).nomore}. switch(check) { case 1: {about(). delay(500). WhereMouse(&a. messageclear(). choose choose1=yes. initialise_house_with_ludos(BLUE). flagturn=0. dice_value_color[flagturn]=colors[loop].b). if(ButtReleased()) { check=check_if_mouse_click_is_on_any_button (a. while(ch!=27) { if(kbhit()) ch=getch().} . loop++. int check. enum choose {yes. setcolor(RED).} int loop=i.tmp2. initialise_house_with_ludos(YELLOW). if(loop>=4) loop=0. if(check>=1 && check<=4) show_mouse_click_on_button(a.tmp1=0. char ch.b).&b).

delay(1000). ".&lp[tmp1]). tmp1=catchclickonludobutton(). tmp2=lp[tmp1]. switch(tmp2) { case 1: { lp[tmp1]. break.break.} case 2: {dice=throwdice(). if(dice!=0) { if(dice==6) messageout("click on ludo button to take out of house or move"). messageout("proceeding").ptr_move_ludo_to_new_position(dice. delay(1000).ptr_check_if_ludo_move_requested_is_valid(dice. choose1=yes.best of luck.0). } case 2: { messageout("choose correct ludo to proceed"). else messageout("click on the ludo button to move"). break. while(choose1==yes) { choose1=nomore.case 4: {howtoplay(). break.} } //end of switch } //end of if(ButtRelease) /* players chance*/ if(flagturn==0) { messageout("PLAYER throwdice.} case 3: {exit(0).&lp[tmp1]). } case 3: { . break.

}// end of if(flagturn==0) /*computer1 chance*/ if(flagturn==1) { messageout("now the computer1 will throw dice")."). } flagturn=2.&lc1[tmp1]). choose1=yes. if(dice!=0) { tmp1=forcomputer1(dice).messageout("sorry. . delay(1000). dice=throwdice(). } /*computer2 chance*/ if(flagturn==2) { messageout("now the computer2 will throw dice"). if(tmp1!=5)//forcomputer(dice) returns 5 if no ludo can move lc2[tmp1]. dice=0. messageclear(). } }//switch ends }//end of while(choose1=yes) flagturn=1. else messageout("computer1 has to skip this time.&lc2[tmp1]). }//end of if(dice!=0) dice=0. if(tmp1!=5)//forcomputer(dice) returns 5 if no ludo can move lc1[tmp1]. break.ptr_move_ludo_to_new_position(dice. if(dice!=0) { tmp1=forcomputer2(dice). dice=throwdice().you will have to skip this time").ptr_move_ludo_to_new_position(dice."). } flagturn=3. else messageout("computer2 has to skip this time.

messageclear(). floodfill(x+10. } /*computer3 chance*/ if(flagturn==3) { messageout("now the computer3 will throw dice").y+70.y+30. } .rec). if(dice!=0) { tmp1=forcomputer3(dice).y+10. circle(x+90.y+30.messageclear(). else messageout("computer3 has to skip this time.WHITE). dice=throwdice().col).rec). }//end of while }//end of main void draw_house(int col.10). floodfill(x+90.10). floodfill(x+90. circle(x+30. setfillstyle(1.WHITE).rec). setfillstyle(1.").&lc3[tmp1]).rec). setfillstyle(1.10). rectangle(x.ptr_move_ludo_to_new_position(dice. dice=0.int x. floodfill(x+30.y+30. circle(x+30.y.y+120). floodfill(x+30. } flagturn=0.y+70.y+30. } dice=0. if(tmp1!=5)//forcomputer(dice) returns 5 if no ludo can move lc3[tmp1].y+70. setfillstyle(1.x+120.y+70.WHITE). dice=0.rec).WHITE). setfillstyle(1. circle(x+90.10).int y) { setcolor(rec).

draw_button_with_button_name(120.0). outtextxy(x+20. else if(a>0 && a<110 && b>90 && b<120) return 2.int b) { if(a>0 && a<110 && b>55 && b<85) return 1.y."exit").y+15. else if(a>519 && a<639 && b>0 && b<120 ) return 7. draw_button_with_button_name(0.55+35.7)."throw dice").y."how to play"). else if(a>120 && a< 230 && b>55 && b<85) return 3. else return 0. floodfill(x. draw_button_with_button_name(120. setfillstyle(1.x+110. } . setfillstyle(1. draw_button_with_button_name(0. setcolor(colorfortext). rectangle(x.rec).y."about"). floodfill(x. else if(a>239 && a<359 && b>280 && b<400 ) return 6. } int check_if_mouse_click_is_on_any_button (int a.rec). else if(a>519 && a<659 && b>280 && b<400 ) return 8.char *message) { setcolor(rec).int y) { HideMouse().55.55+35.void draw_button_with_button_name(int x. } void show_mouse_click_on_button(int x.y+30).55.int y. else if(a>120 && a< 230 && b>90 && b<120) return 4. ShowMouse(). delay(50). else if(a>239 && a<359 && b>0 && b<120 ) return 5.message).

x=x+10) { rn=random(6)+1. } else { count++.y.count=0.int y. return rn. randomize(). for6=0. num=rn+48. } // cout<<for6.0).num). } void throw1(int x.0.} if(for6>=5) { rn=6. flag=1. //if(y==320) // for6++.flag=0. } } settextstyle(0.count. int rn. /* using for6 to get a 6 on dice every 5th time to make the game a little faster*/ if(y==320) {for6++.num).y.y<=320. for(y=150.y.char num) .char num.int count. if(flag==0) { throw2(x. ShowMouse(). throw1(x.y=y+10. int x=0.int throwdice() { HideMouse(). flag=0.

y. setcolor(dice_value_color[flagturn]). setcolor(WHITE).y-10.x+50. setcolor(dice_value_color[flagturn]).y-25).y+25. } setcolor(0).&num).450.char num) { x=x-17. rectangle(x. rectangle(x.y+5.y+25. line(x+25. } void messageclear() { .x+25. line(x.y-10. outtextxy(x+5.{ settextstyle(0. settextstyle(0. //setcolor(RED).y).x+50. outtextxy(x+15.x+25.x+50.3).x+25.&num). setcolor(0).x+35. delay(140).y). line(x.message). outtextxy(x+15.x+35. line(x.x+50.int y.y.x+25.0.y-25.&num). delay(140).y. } void throw2(int x. //setcolor(RED).y=y+10.y). setcolor(colorfortext).&num). outtextxy(x+5.0. line(x. setcolor(WHITE). if(count==9) {delay(650).y. line(x+25. line(x+25. outtextxy(20. line(x+25.y+35).y-25).3).int refresh) { if(refresh) messageclear().y+5. } void messageout(char *message.y.y+35).y).y-25.y+25).y+25).y.

y+70.rec).} case BLUE: {x=519. } } void load_path_information_in_ludos(int plcol) .y+70. floodfill(20.y=0. setfillstyle(1.} case GREEN: {x=239. floodfill(x+30.y=280. { circle(x+30.y=280.rec).break.y+30. setfillstyle(1.y+30.x.y+30.y). ShowMouse().break.y+30. floodfill(x+90.color).rec).break. } { circle(x+30. switch(color) { case RED: {x=239.8).y+70. floodfill(x+30.HideMouse().rec).8). setcolor(rec).} case YELLOW: {x=639-120. } { circle(x+90.} } draw_house(color.break. } void initialise_house_with_ludos(int color) { int x.0).y=0.y+70.450.8).8).rec).y. } { circle(x+90. floodfill(x+90.

260.} case 3: {lc3[tmp].295.325.499.tmp++) { switch(tmp) { case 0: {arx[0]=269.254.200.379.break.} } switch(flagturn) { case 0: {lp[tmp].break.break.ptr_ludo1(RED. 385.75.arx.284.384.624.624.384.45.15.594.260.{ int arx[45].break.564.ary[0]=30.624.140.439.344.355.314.200.tmp<=3.200.439. 200}.&lp[tmp]).499.} } } break.} case 3: {arx[0]=269.534.385.379.385.} case 2: {arx[0]=329. for(int tmp=0.499.} case 1: {lc1[tmp].arx.} case 2: {lc2[tmp].ary. .ptr_ludo1(RED.564.534.499.&lc3[tmp]).ary.200.384.200.355.140.105.624.534.499. 254. 534.140.624.75.15. 499.260.384.ptr_ludo1(RED.594.ary[0]=70.295. switch(plcol) { case RED: { int arx[45]={269.284.140.344.499.499.624.ary[0]=30.260. 499.260.499.325.499.arx.314.499.379.105.arx.344.379.384.ptr_ludo1(RED.break.break. 140.140.260.384.ary.344.284.&lc1[tmp]).140.594.260.499.ary[0]=70.&lc2[tmp]).260.384.564.break.424}.499.260.314.15.499.384. int ary[45]={30.499.ary[45].break.} case 1: {arx[0]=329.594.499.45.384.140.ary.564.439.260.499.379.200.384.499.}//case RED ends case BLUE: { int arx[45]={549.140.384.

439.295.} case 1: {lc1[tmp].284.379.260.&lc1[tmp]).564.325.439.314.499.140.105.105.&lc2[tmp]).140.284.ptr_ludo1(BLUE.624.} } switch(flagturn) { case 0: {lp[tmp].105. 344.439.140.260.} case 1: {arx[0]=549.} case GREEN: { int arx[45]={269.140.75.} case 3: {lc3[tmp].15.140.45 .295.140.260.75.215}.ary[0]=70. 439.140.260.ary.379.314.344.385.379.385.499.} case 3: {arx[0]=609.200.355.} .} case 2: {arx[0]=609.break.260.15.499.624.260.355.384.284.45.439.314.140.140.140.75.140.499.379. 260.&lc3[tmp]).ary[0]=30.200.325.tmp++) { switch(tmp) { case 0: {arx[0]=269.200.105.break.140.379.ptr_ludo1(BLUE.break.254.&lp[tmp]).384.140.45.439.379.260.260.185}.534.45 .295. 260.499.140.260.140.ary[0]=30.ary.ary[0]=70.ary. for(int tmp=0.140.314.344.105.355.260.384.439.75.439. int ary[45]={30.379. 260. 564.140.325.594.284. for(int tmp=0.439.295.499.260.45.15.tmp<=3.254.arx.384.140.379.200.254.439.140.385.} case 2: {lc2[tmp].140.ptr_ludo1(BLUE.15. int ary[45]={30.624.arx.ptr_ludo1(BLUE.break.ary[0]=310.15.260.break.254.355.439 }.140.260.439 }.75.534.260.355.499.499.379.260.385.254.ary.tmp<=3.594.325.379.break.} } } break.499.arx.arx.325.385. 260.499.tmp++) { switch(tmp) { case 0: {arx[0]=549.break.260.260.254.439.break.break.295.

ptr_ludo1(YELLOW.} case YELLOW: { int arx[45]={549.200.ary.75.ary[0]=350.break.140.ary[0]=350.295.ary.ary[0]=310.&lp[tmp]).} case 2: {arx[0]=329.&lc1[tmp]).} case 1: {lc1[tmp].200.499.260.&lc1[tmp]).&lp[tmp]).ary[0]=350.295.ary[0]=310.arx.arx.ptr_ludo1(YELLOW. 384.} case 3: {arx[0]=269.ptr_ludo1(GREEN.499.439.arx. int ary[45]={310.624.} } switch(flagturn) { case 0: {lp[tmp].140.260.break.ary.379.499.439.384.140.499.385.75.594.499.} case 2: {lc2[tmp].break.} case 2: {lc2[tmp].140.499.499.} case 1: {lc1[tmp].} case 1: {arx[0]=549.&lc3[tmp]).ary.140.594.344.284.&lc2[tmp]).arx.564.200}. for(int tmp=0. 15.15.314.325.ptr_ludo1(GREEN.ary.355.} case 3: {arx[0]=609.200.} .break.260.325.} case 2: {arx[0]=609.499.379.ary[0]=310.ary.arx.arx.140.344.} case 3: {lc3[tmp].379.594.105.ary[0]=350.200.} } } break.355. 260.ptr_ludo1(YELLOW.499.564.564.454}.break.break.case 1: {arx[0]=329.&lc2[tmp]).break.534.200.284.314.break.break.260.384. 379.534.499.254.200.break.379.break.45.break.499.260.45.140. 624.385.385.260.140.254.15.break.140.tmp<=3.ptr_ludo1(GREEN.254.260.break.384.ptr_ludo1(GREEN.arx.534.260.} } switch(flagturn) { case 0: {lp[tmp].tmp++) { switch(tmp) { case 0: {arx[0]=549.105.ary.140.384.

pos].color) { setcolor(lc1[i].y[lp[i].pos].color) { setcolor(lp[i].i<=3.i<=3. } } } } void redrawing(int tmp) { int i. for(i=0.pos])) < 8) return i.color).i.lp[i]. if(ButtReleased()) { for(i=0.lp[i].&lc3[tmp]).x[lp[i].ptr_ludo1(YELLOW.} } } break.arx. } if(tmp==lc1[0].&b).pos]. .i++) { if(tmp==lp[0].pos])) < 8 && abs(b-(lp[i].b.x[lp[i].8).ary.} }//switch ends } int catchclickonludobutton() { int a.pos]. circle(lp[i].case 3: {lc3[tmp].break.y[lp[i].x[lp[i].color).color).lp[i].i++) { if( abs(a-(lp[i]. floodfill(lp[i].lp[i]. setfillstyle(1.color). while(1) { WhereMouse(&a.y[lp[i].

pos].y[j]==lp[i].color).0}.i++) { for(j=1.pos==0 && dice==6) ) cannotmove=0.y[lc1[i].lc1[i].color).8).pos]) . } }//for ends } /* deciding for computer1 which ludo to move */ int forcomputer1(int dice) { int i.lc2[i].pos] && lc1[0].j.0.pos].pos].x[lc1[i].color). } if(tmp==lc3[0].0.pos].lc2[i].i++) { if( (lc1[i]. floodfill(lc3[i].x[lc2[i].lc2[i].0.j++) { if( lc1[0].lc1[i].pos].i<=3.y[lc2[i].y[lc1[i].lc1[i].lc2[i]. /* checking if atleast one ludo can move at current dice value*/ for(i=0.y[lc2[i].poslpforlc[12]={0.lc3[i]. } if(tmp==lc2[0].color).lc3[i].pos].color) { setcolor(lc2[i].y[lp[i].color).0.tmp.pos].pos].lc1[i].8). setfillstyle(1.0. //position of players ludo in terms of computers1 ludo positions for(i=0. circle(lc2[i].0.cannotmove=5.x[lc1[i].0. setfillstyle(1.pos].x[lc3[i].x[lc3[i].color).color).x[lc2[i].color) { setcolor(lc3[i]. floodfill(lc1[i].0.0. setfillstyle(1.x[j]==lp[i].pos].color).8).j<=40.0.pos!=0) || (lc1[i]. circle(lc3[i].y[lc3[i].x[lp[i].//cannotmove=5 then no ludo can move } if(cannotmove==5) return 5.pos<=44-dice && lc1[i].pos]. floodfill(lc2[i].lc3[i].pos].i<=3.y[lc3[i].lc3[i].circle(lc1[i].

i++) { for(j=1.j<=40.e position .pos) && lc1[i].x[j]==lc2[i-4].0}. } } } //position of computer2 ludo in terms of computer1 ludo positions for(i=4.i<=3.y[j]==lc2[i-4].pos]) { poslpforlc[i]=j.y[j]==lc3[i-8].i<=11. } } } //position of computer3 ludo in terms of computer1 ludo positions for(i=8.y[lc2[i-4].i<=7.j++) { if( dice==(poslpforlc[j] .pos] && lc1[0]. .y[lc3[i-8]. } } }//end of i /*to cut opponents ludo button*/ for(i=0.j++) { if( lc1[0].{ poslpforlc[i]=j. } } /* to move those ludos which are near the player ludos and have the gretest value of pos i.lc1[i].0.pos]) { poslpforlc[i]=j.pos!=0) return i.i++) { for(j=1.x[lc3[i-8].j<=40. it means saving the threatened ludo*/ int array[4]={0.i++) { for(j=0.pos] && lc1[0].j++) { if( lc1[0].x[j]==lc3[i-8].0.x[lc2[i-4].j<=11.

pos)<=6 && (-poslpforlc[j] + lc1[i].j<=11. } } /*if ludo buttons are outside and option for cutting opponent or taking out own ludo button are not valid .pos.i++) { for(j=0.pos==0 ) return i.i<=3.i<=3.j++) { if( (-poslpforlc[j] + lc1[i]./* a1 has the greatest pos value */ } if(a1!=0) //to see that at least one ludo is threatened */ { for(i=0.int a1=0.pos<=40 ) {array[i]=lc1[i]. } } //to take out ludo button from house for(i=0. using round robin for selecting ludo to move*/ static int ludolast=0. int firstround=0.i++) { if(firstround==0) { .i<=3. for(i=0.} } if(a1<=array[i]) a1=array[i].pos+dice<=44 && poslpforlc[j]!=0 && lc1[i].i<=3.pos)>=1 && lc1[i].i++) { if(dice==6) { if(lc1[i].i++) //getting the ludo with greatest pos value { if(a1==array[i]) return i.tmp1. for(i=0.

} } } //position of computer1 ludo in terms of computer2 ludo positions .0.i++) { if( (lc2[i].0. /* checking if atleast one ludo can move at current dice value*/ for(i=0.0. } return ludolast.//cannotmove=5 then no ludo can move } if(cannotmove==5) return 5.pos]) { poslpforlc[i]=j.pos!=0 && lc1[i].pos] && lc2[0].i<=3.0.y[lp[i].0.pos!=0) || (lc2[i].i<=3. } if(lc1[i].pos==0 && dice==6) ) cannotmove=0.tmp.j++) { if( lc2[0].0}.i++) { for(j=1.cannotmove=5.pos<=44-dice && lc2[i].if(ludolast!=3) {i=ludolast+1.0.j<=40.y[j]==lp[i].} firstround++.i=4.0.pos+dice<=44 ) {ludolast=i.0.poslpforlc[12]={0.x[lp[i].j. //if ludo button is } /* deciding for computer2 which ludo to move */ int forcomputer2(int dice) { int i.} if(i==3) i=-1.x[j]==lp[i].0. //position of players ludo in terms of computers2 ludo positions for(i=0.0.

y[lc1[i-4].x[j]==lc1[i-4].i<=11.pos!=0) {return i.0.pos] && lc2[0].j<=40.y[j]==lc3[i-8].i<=3.i<=11.pos]) { poslpforlc[i]=j.i++) { for(j=1.i++) { .j++) { if( lc2[0].for(i=4.pos) && lc2[i].e position . int a1=0.i++) { for(j=1.x[lc1[i-4].x[lc3[i-8].lc2[i]. it means saving the threatened ludo*/ int array[4]={0. } } } //position of computer3 ludo in terms of computer2 ludo positions for(i=8.j<=40.y[lc3[i-8].0. } } }//end of i for(i=0. for(i=0.i<=3.j++) { if( lc2[0].x[j]==lc3[i-8].pos]) { poslpforlc[i]=j.i<=7.j++) { if( dice==(poslpforlc[j] .0}.tmp1.j<=11.} } } /* to move those ludos which are near the player ludos and have the gretest value of pos i.y[j]==lc1[i-4].pos] && lc2[0].i++) { } /*to cut opponents ludo button*/ for(i=0.i++) { for(j=0.

using round robin for selecting ludo to move*/ static int ludolast=0.} } if(a1<=array[i]) a1=array[i].pos==0 ) {return i.pos<=40 ) {array[i]=lc2[i]./* a1 has the greatest pos value */ } if(a1!=0) //to see that at least one ludo is threatened */ { for(i=0.} } } /*if ludo buttons are outside and option for cutting opponent or taking out own ludo button are not valid .pos)>=1 && lc2[i].i<=3.pos+dice<=44 && poslpforlc[j]!=0 && lc2[i].i<=3.pos.} firstround++.i<=3.j++) { if( (-poslpforlc[j] + lc2[i].i++) { if(firstround==0) { if(ludolast!=3) {i=ludolast+1. .i++) //getting the ludo with greatest pos value { if(a1==array[i]) {return i.i++) { if(dice==6) { if(lc2[i].j<=11. int firstround=0.} } } //to take out ludo button from house for(i=0.for(j=0.pos)<=6 && (-poslpforlc[j] + lc2[i]. for(i=0.

0.x[j]==lp[i].cannotmove=5.pos!=0) || (lc3[i].0.pos] && lc3[0].poslpforlc[12]={0.0.0.i++) { for(j=1.j<=40.j++) { .i++) { if( (lc3[i].pos<=44-dice && lc3[i].0.j.i++) { for(j=1.0.0.0.pos]) { poslpforlc[i]=j. } } } //position of computer2 ludo in terms of computer3 ludo positions for(i=4.0.tmp.0}. //if ludo button is } /* deciding for computer3 which ludo to move */ int forcomputer3(int dice) { int i.y[lp[i]. } return ludolast.y[j]==lp[i].pos+dice<=44 ) {ludolast=i.//cannotmove=5 then no ludo can move } if(cannotmove==5) return(5).x[lp[i].i<=3.pos!=0 && lc2[i]. //position of players ludo in terms of computers1 ludo positions for(i=0.} if(lc2[i].0.pos==0 && dice==6) ) cannotmove=0.j<=40.i<=3. /* checking if atleast one ludo can move at current dice value*/ for(i=0.j++) { if( lc3[0].i<=7.i=4.} if(i==3) i=-1.

int a1=0.i++) { for(j=0.e position .i<=3.pos)>=1 && lc3[i].0.pos<=40 && poslpforlc[j]!=0 ) .y[lc2[i-4].j++) { if( lc3[0].lc3[i]. } } } //position of computer1 ludo in terms of computer3 ludo positions for(i=8.j<=40.i++) { for(j=1.i<=11. } } }//end of i /*to cut opponents ludo button*/ for(i=0.0}.if( lc3[0].pos] && lc3[0].pos) && lc3[i]. } } /* to move those ludos which are near the player ludos and have the gretest value of pos i.tmp1. it means saving the threatened ludo*/ int array[4]={0.j<=11.x[j]==lc2[i-4].j++) { if( dice==(poslpforlc[j] .pos)<=6 && (-poslpforlc[j] + lc3[i].i<=3.x[lc2[i-4].pos] && lc3[0].j++) { if( (-poslpforlc[j] + lc3[i].i++) { for(j=0.j<=11.pos]) { poslpforlc[i]=j.y[j]==lc2[i-4].pos+dice<=44 && lc3[i].y[lc1[i-8].x[lc1[i-8]. for(i=0.y[j]==lc1[i-8].pos]) { poslpforlc[i]=j.pos!=0 ) return i.x[j]==lc1[i-8].0.

i++) //getting the ludo with greatest pos value { if(a1==array[i]) {return i.} } if(a1<=array[i]) a1=array[i]. } .i<=3.i++) { if(dice==6) { if(lc3[i].} } } //to take out ludo button from house for(i=0.i++) { if(firstround==0) { if(ludolast!=3) {i=ludolast+1.i<=3./* a1 has the greatest pos value */ } if(a1!=0) //to see that at least one ludo is threatened */ { for(i=0. for(i=0.pos==0 ) return i. int firstround=0. using round robin for selecting ludo to move*/ static int ludolast=0. } if(lc3[i].i=4.} if(i==3) i=-1.pos+dice<=44 ) {ludolast=i.i<=3.pos.{array[i]=lc3[i].} firstround++. } } /*if ludo buttons are outside and option for cutting opponent or taking out own ludo button are not valid .pos!=0 && lc3[i].

639. floodfill(310.40. draw_house(BLUE.410.10.479).30. setcolor (colorfortext).0). draw_button_with_button_name(120. draw_button_with_button_name(0.0).239. //if ludo button is } void draw_all() { //registerbgidriver(EGAVGA_driver). &gmode."GAME"). /* writing text */ setcolor(background)."(aks_mailin@rediffmail. rectangle(0."how to play").639.50). rectangle(239.10. draw_house(YELLOW.400).55+35."COMPUTER LUDO"). outtextxy(5.639-120. setcolor(rec). outtextxy(5.0. gmode. int gdriver = DETECT. draw_house(GREEN. /* request auto detection */ /* initialize graphics mode */ initgraph(&gdriver. draw_house(RED.com)"). outtextxy(5.280). . /* drawing rectangles */ setcolor(rec). settextstyle(0.0.return ludolast. setfillstyle(1. /*drawing sectors*/ setcolor(0).55+35."about")."throw dice").280).55.7). draw_button_with_button_name(0. "")."exit"). rectangle(0.0.0).239.rec).55. //registerbgifont(sansserif_font). draw_button_with_button_name(120.20. outtextxy(5.639-120.230."akshay presents").

30. messageout("PLAYER.playercolor=0.160 ).519. int a. line(269+90.190.280.269+210.519.400 ).280 ).269+280.120.160. outtextxy(420.400 ).240. line(269+340.line(359.120.200.120.background). } int player_chooses_house_color(void) { char ch. line(269+280.60 ).639.120 ).0. line(359.120.120. line(269+60. line(359.90 ). line(269+250.280 ).269+340. line(269+130. line(359.280 ). setcolor(RED).//come out of while if(kbhit()) ch=getch().340 ). return . if(ButtReleased()) .519.269+90.0.370 ).click YOUR lucky COLOR on the board ").120.120.280). line(359. line(239.519.280 ).WHITE).&b).120.30 ).519. setcolor(RED).280 ).b. setfillstyle(1.310).639. floodfill(439. line(239.280 ).519."HOME").269+310.90.519.120.280).60.269+30. while(ch!=27) { if(playercolor!=0) break. WhereMouse(&a. line(359.370.269+60. int check.269. line(269.240 ). line(269+210.340.519.269+250. line(359. line(269+30.269+130.310. line(359.280 ). line(269+310.

390)."by").160.break. break. switch(check) { case 1: {show_mouse_click_on_button(a. break.b). } void about(void) { HideMouse().} case 5: { messageout( "you have choosen red"). outtextxy(5.} } //end of switch }//end of if(ButtRelease) }//end of while delay(500).} case 6: { messageout( "you have choosen green").{ check=check_if_mouse_click_is_on_any_button (a.about(). setcolor(colorfortext). return playercolor.} case 8: { messageout( "you have choosen yellow").b).150.} case 3: {show_mouse_click_on_button(a."WELCOME to ComputerLudo"). playercolor=YELLOW. outtextxy(5. outtextxy(5. break.170. playercolor=GREEN. playercolor=BLUE. . rectangle(0.break. break.howtoplay().135.230."This software is developed").} case 7: { messageout( "you have choosen blue").} case 4: {show_mouse_click_on_button(a. playercolor=RED. setcolor(rec).b).exit(0). break.b).

} void winner() { HideMouse(). outtextxy(5.")."thanks again. ShowMouse(). setfillstyle(1.180. setcolor(colorfortext).250.310."OF")."PRESS ANY KEY TO PROCEED .190.""). outtextxy(5.210. if(flagturn==0) { outtextxy(5.390). outtextxy(5.} case 2: {outtextxy(5."thanks").230. outtextxy(5.300."COMPUTER1 WON THIS").390).240.260. } else { switch(flagturn) { case 1: {outtextxy(5."you for trying this")."game.")."CONGRATULATIONS").0)."welcome to ComputerLudo").break.com"). floodfill(5."COMPUTER2 WON THIS")."Akshay ").190.210."). getch(). outtextxy(5.break.230.230.135.""). outtextxy(5. outtextxy(5.rec).} ."akshay thanks "). rectangle(0.150. return . rectangle(0.. outtextxy(5.230. outtextxy(5.135. outtextxy(5. outtextxy(5. setcolor(0).240."YOU WON THIS ROUND "). setcolor(rec).310..220. setcolor(rec).160. outtextxy(5. outtextxy(5. outtextxy(5. outtextxy(5.outtextxy(5..160."PRESS ANY KEY TO EXIT.160. outtextxy(5."aks_mailin@rediffmail.").180."U can send suggestions at")."my Email:").170."ComputerLudo").

setcolor(colorfortext).case 3: {outtextxy(5."you for trying this")."COMPUTER3 WON THIS").0)."). outtextxy(5.200.200."game.."BETTER LUCK NEXT TIME"). outtextxy(5."GIVEN AT BOTTOM")."PRESS ANY KEY TO EXIT."Akshay.} } outtextxy(5.break.")."). rectangle(0."thanks again.160.250.")."HOME wins thE Game. outtextxy(5. outtextxy(5."ComputerLudo")."akshay thanks ").350.260.170. setcolor(rec). outtextxy(5. outtextxy(5. outtextxy(5.").320.240."). outtextxy(5.310.180."FOLLOW THE MESSAGE BOX").150."CUT(send to house) computers").210.230..270. outtextxy(5."PRESS ANY KEY TO PROCEED . } getch(). outtextxy(5.160."your fovourite color.").220."thanks").390).170. outtextxy(5. outtextxy(2. outtextxy(5."Choose HOUSE by "). outtextxy(5. . outtextxy(5.290. outtextxy(5.")."). setfillstyle(1. outtextxy(5.240."This is a game between")."Get 6 on Dice to take a ludo"). outtextxy(5.190.180.300.230.220."clicking over the HOUSE of").250.To make a ludo")."One who gets all the ludos")."). outtextxy(5."COMPUTER and the PLAYER.."out of HOUSE. outtextxy(5. outtextxy(5. outtextxy(5."over its ludos."ludos by placing your ludos "). getch(). outtextxy(5.330. exit(0)."ROUND OF"). outtextxy(5. outtextxy(5.230.135."MOVE click on it. } void howtoplay() { HideMouse().

} .390). rectangle(0.135. setcolor(0).300. ShowMouse().floodfill(5. setcolor(rec).230.rec). return .