TryStar game
#include <graphics.h>
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<dos.h>
#include<process.h>
#include"mouse.h"
#define UP 0
#define DOWN 1
#define RIGHT 2
#define LEFT 3
#define RIGHT_UP 4
#define RIGHT_DOWN 5
#define LEFT_UP 6
#define LEFT_DOWN 7
#define PLAYER 0
#define COMPUTER 1
#define YES 1
#define NO 0
void Welcome();
void Screen();
void Marker(int);
void Check(int,int,int);
int Ask_Mouse(int,int);
void Draw_Allowed_Dots(int);
void Convertor(int,int);
void Scorer();
void Press_Exit_Button();
int Computer_Move();
void Write_Status_Game(int);
void Result_Declaration();
void Reset();
int Play();
void Who_Play_First();
void Color_Allotment();
union REGS ii,oo;
int Board[256]=
{ 9, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9,
9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9,
9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9,
9, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9 };
int x,y;
int allowed_square[150],source_square[150],movement_type[150];
int Counter;
int Computer_Color=0;
int Player_Color=0;
int button,mousex,mousey,mousetrap=0;
int reply=1,Whoplays_first=0;
int turn=0,flag_allowed_square_selected=0,flag_no_chance=0;
void main() // creator- S u ne et sin gh 99 / cse/123 C RS CE M urthal// this is to protect from thiefs ;-)
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
x=getmaxx()/2;
y=getmaxy()/2;
int i;
for(i=0;i<150;i++)
{
allowed_square[i]=0;
source_square[i]=0;
movement_type[i]=0;
}
if(initmouse()==0)
{
closegraph();
restorecrtmode();
cout<<"\nMouse driver not loaded";
exit(1);
}
restrictmouseptr(1,1,getmaxx()-1,getmaxy()-1);
showmouseptr();
hidemouseptr();
Welcome();
Play();
closegraph();
}
int Play()
{
int o;
int if_over=NO;
int skip=NO;
Who_Play_First();
Screen();
showmouseptr();
Marker(2);
Draw_Allowed_Dots(2);
Marker(1);
Draw_Allowed_Dots(1);
Color_Allotment();
reply=1;
mousetrap=0;
if(Computer_Color!=turn) {
Marker(Player_Color);
Draw_Allowed_Dots(Player_Color);
}
else if(Computer_Color==turn) {
Marker(Computer_Color);
Draw_Allowed_Dots(Computer_Color);
}
Write_Status_Game(Computer_Color);
settextstyle(3,0,1);
setcolor(4);
outtextxy(x-260,y+190,"Reset");
showmouseptr();
while(1)
{
getmousepos(&button,&mousex,&mousey);
if(Computer_Color==turn)
{
hidemouseptr();
reply=Computer_Move();
mousetrap=1;
flag_allowed_square_selected=0;
flag_no_chance=1;
for(o=0;o<150;o++)
{
if(allowed_square[o]==reply)
flag_allowed_square_selected=1;
if(allowed_square[o]!=0)
flag_no_chance=0;
}
if(flag_no_chance==1)
{
if(turn==1)
turn=2;
else if(turn==2)
turn=1;
Draw_Allowed_Dots(0);
Marker(turn);
Screen();
Draw_Allowed_Dots(turn);
mousetrap=0;
showmouseptr();
}
if(flag_allowed_square_selected==0)
{
mousetrap=0;
showmouseptr();
}
showmouseptr();
}
if((button&1)==1)
{
hidemouseptr();
while((button&1)==1)
{
getmousepos(&button,&mousex,&mousey);
mousetrap=1;
}
getmousepos(&button,&mousex,&mousey);
if(Computer_Color!=turn)
reply=Ask_Mouse(mousex,mousey);
else
{
mousetrap=0;
skip=YES;
}
if(skip==NO)
{
if(reply==555)
{
hidemouseptr();
Press_Exit_Button();
exit(0);
}
if(reply==333)
{
hidemouseptr();
Reset();
showmouseptr();
Play();
}
flag_allowed_square_selected=0;
flag_no_chance=1;
for(o=0;o<150;o++)
{
if(allowed_square[o]==reply)
flag_allowed_square_selected=1;
if(allowed_square[o]!=0)
flag_no_chance=0;
}
if(flag_no_chance==1)
{
if(turn==1)
turn=2;
else if(turn==2)
turn=1;
Draw_Allowed_Dots(0);
Marker(turn);
Screen();
Draw_Allowed_Dots(turn);
mousetrap=0;
showmouseptr();
}
if(flag_allowed_square_selected==0)
{
mousetrap=0;
showmouseptr();
}
}
showmouseptr();
}
if(mousetrap==1)
{
hidemouseptr();
Draw_Allowed_Dots(0);
mousetrap=0;
Convertor(reply,turn);
if(turn==1)
turn=2;
else if(turn==2)
turn=1;
Marker(turn);
if(Counter==0)
if_over++;
else
if_over=0;
Screen();
Draw_Allowed_Dots(turn);
Scorer();
int cc=0;
for(o=0;o<256;o++)
{
if(Board[o]!=0)
cc++;
}
if(cc==256||if_over>=3)
Result_Declaration();
showmouseptr();
}
}
}
int Computer_Move()
{
int store_c=Counter;
int store_sqr;
int flag=1;
int stage=0;
for(int o=0;o<256;o++)
if(Board[o]==0)
stage++;
Marker(Computer_Color);
for(o=0;o
{
if(allowed_square[o]==3||allowed_square[o]==48||allowed_square[o]==63||allowed_square[o]==12)
{ return(allowed_square[o]); }
if(allowed_square[o]==192||allowed_square[o]==243||allowed_square[o]==207||allowed_square[o]==252)
{ return(allowed_square[o]); }
}
for(o=0;o
{
if(allowed_square[o]==18 && Board[3]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==33 && Board[48]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==29 && Board[12]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==46 && Board[63]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==209 && Board[192]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==226 && Board[243]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==222 && Board[207]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==237 && Board[252]!=0)
{ return(allowed_square[o]);}
}
for(o=0;o
{
if(allowed_square[o]%8==0)
{
if(allowed_square[o]!=64 && allowed_square[o]!=176)
{ return(allowed_square[o]);}
else if(allowed_square[o]==64 && Board[48]!=0)
{ return(allowed_square[o]);}
else if(allowed_square[o]==176 && Board[192]!=0)
{ return(allowed_square[o]);}
}
}
for(o=0;o
{
if(allowed_square[o]%8==7)
{
if(allowed_square[o]!=79 && allowed_square[o]!=191)
{ return(allowed_square[o]);}
else if(allowed_square[o]==79 && Board[63]!=0)
{ return(allowed_square[o]);}
else if(allowed_square[o]==191 && Board[207]!=0)
{ return(allowed_square[o]);}
}
}
for(o=0;o
{
if(allowed_square[o]<16)
{
if(allowed_square[o]!=4 && allowed_square[o]!=11)
{ return(allowed_square[o]);}
else if(allowed_square[o]==4 && Board[3]!=0)
{ return(allowed_square[o]);}
else if(allowed_square[o]==11 && Board[12]!=0)
{ return(allowed_square[o]);}
}
}
for(o=0;o
{
if(allowed_square[o]>240)
{
if(allowed_square[o]!=244 && allowed_square[o]!=251)
{ return(allowed_square[o]);}
else if(allowed_square[o]==244 && Board[243]!=0)
{ return(allowed_square[o]);}
else if(allowed_square[o]==251 && Board[252]!=0)
{ return(allowed_square[o]);}
}
}
if(stage<25)
for(o=0;o
{
if(allowed_square[o]==18)
{ return(allowed_square[o]);}
if(allowed_square[o]==33)
{ return(allowed_square[o]);}
if(allowed_square[o]==29)
{ return(allowed_square[o]);}
if(allowed_square[o]==46)
{ return(allowed_square[o]);}
if(allowed_square[o]==209)
{ return(allowed_square[o]);}
if(allowed_square[o]==226)
{ return(allowed_square[o]);}
if(allowed_square[o]==222)
{ return(allowed_square[o]);}
if(allowed_square[o]==237)
{ return(allowed_square[o]);}
}
for(o=0;o
{
if(allowed_square[o]==19 && Board[3]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==49 && Board[48]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==28 && Board[12]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==62 && Board[63]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==193 && Board[192]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==227 && Board[243]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==206 && Board[207]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==236 && Board[252]!=0)
{ return(allowed_square[o]);}
}
for(o=0;o
{
if(allowed_square[o]==34||allowed_square[o]==45||allowed_square[o]==210||allowed_square[o]==221)
{ return(allowed_square[o]);}
}
for(o=0;o
{
if(allowed_square[o]==18 && Board[3]==0 && Board[33]!=Player_Color)
{ return(allowed_square[o]);}
if(allowed_square[o]==33 && Board[48]==0 && Board[18]!=Player_Color)
{ return(allowed_square[o]);}
if(allowed_square[o]==29 && Board[12]==0 && Board[46]!=Player_Color)
{ return(allowed_square[o]);}
if(allowed_square[o]==46 && Board[63]==0 && Board[29]!=Player_Color)
{ return(allowed_square[o]);}
if(allowed_square[o]==209 && Board[192]==0 && Board[226]!=Player_Color)
{ return(allowed_square[o]);}
if(allowed_square[o]==226 && Board[243]==0 && Board[209]!=Player_Color)
{ return(allowed_square[o]);}
if(allowed_square[o]==222 && Board[207]==0 && Board[237]!=Player_Color)
{ return(allowed_square[o]);}
if(allowed_square[o]==237 && Board[252]==0 && Board[222]!=Player_Color)
{ return(allowed_square[o]);}
}
for(o=0;o
{
store_sqr=allowed_square[o];
if(allowed_square[o]==18 && Board[3]==0) ;
else if(allowed_square[o]==33 && Board[48]==0) ;
else if(allowed_square[o]==29 && Board[12]==0) ;
else if(allowed_square[o]==46 && Board[63]==0) ;
else if(allowed_square[o]==209 && Board[192]==0) ;
else if(allowed_square[o]==226 && Board[243]==0) ;
else if(allowed_square[o]==222 && Board[207]==0) ;
else if(allowed_square[o]==237 && Board[252]==0) ;
else if(allowed_square[o]==64 || allowed_square[o]==176) ;
else if(allowed_square[o]==79 || allowed_square[o]==191) ;
else if(allowed_square[o]==4 || allowed_square[o]==11) ;
else if(allowed_square[o]==244 || allowed_square[o]==251) ;
else if(allowed_square[o]==19 && Board[3]==0) ;
else if(allowed_square[o]==49 && Board[48]==0) ;
else if(allowed_square[o]==28 && Board[12]==0) ;
else if(allowed_square[o]==62 && Board[63]==0) ;
else if(allowed_square[o]==193 && Board[192]==0) ;
else if(allowed_square[o]==227 && Board[243]==0) ;
else if(allowed_square[o]==206 && Board[207]==0) ;
else if(allowed_square[o]==236 && Board[252]==0) ;
else if(allowed_square[o]!=0)
{
Board[allowed_square[o]]=Computer_Color;
Marker(Player_Color);
flag=1;
for(int i=0;i<150;i++)
{
if(allowed_square[i]==3||allowed_square[i]==12||allowed_square[i]==48||allowed_square[i]=
=63||allowed_square[i]==192||allowed_square[i]==207||allowed_square[i]==243||allowed_square[i]==252)
flag=0;
}
allowed_square[o]=store_sqr;
Board[allowed_square[o]]=0;
Marker(Computer_Color);
Counter=store_c;
if(flag==1){
return(allowed_square[o]);}
}
}
for(o=0;o
{
store_sqr=allowed_square[o];
if(allowed_square[o]==18 && Board[3]==0) ;
else if(allowed_square[o]==33 && Board[48]==0) ;
else if(allowed_square[o]==29 && Board[12]==0) ;
else if(allowed_square[o]==46 && Board[63]==0) ;
else if(allowed_square[o]==209 && Board[192]==0) ;
else if(allowed_square[o]==226 && Board[243]==0) ;
else if(allowed_square[o]==222 && Board[207]==0) ;
else if(allowed_square[o]==237 && Board[252]==0) ;
else if(allowed_square[o]==64 || allowed_square[o]==176) ;
else if(allowed_square[o]==79 || allowed_square[o]==191) ;
else if(allowed_square[o]==4 || allowed_square[o]==11) ;
else if(allowed_square[o]==244 || allowed_square[o]==251) ;
else if(allowed_square[o]==19 && Board[3]==0) ;
else if(allowed_square[o]==49 && Board[48]==0) ;
else if(allowed_square[o]==28 && Board[12]==0) ;
else if(allowed_square[o]==62 && Board[63]==0) ;
else if(allowed_square[o]==193 && Board[192]==0) ;
else if(allowed_square[o]==227 && Board[243]==0) ;
else if(allowed_square[o]==206 && Board[207]==0) ;
else if(allowed_square[o]==236 && Board[252]==0) ;
else if(allowed_square[o]!=0)
{
return(allowed_square[o]);
}
}
randomize();
int mix=random(Counter);
for(o=0;o
{
if(o==mix)
if(allowed_square[o]!=0)
{
return(allowed_square[o]);
}
}
}
void Result_Declaration()
{
setcolor(6);
settextstyle(DEFAULT_FONT,0,1);
int c=0,p=0;
for(int o=0;o<256;o++)
{
if(Board[o]==Computer_Color)
c++;
if(Board[o]==Player_Color)
p++;
}
if(c>p)
outtextxy(x+200,y+0,"Computer Wins");
else if(p>c)
outtextxy(x+200,y+0,"Player Wins");
else if(c==p)
outtextxy(x+200,y+0,"Game Drawn");
}
void Write_Status_Game(int col)
{
setcolor(6);
settextstyle(DEFAULT_FONT,0,1);
outtextxy(x+190,y+180,"Computer");
outtextxy(x+190,y+200,"Player");
if(col==1)
{
setcolor(7);
outtextxy(x+260,y+180,"Black");
setcolor(2);
outtextxy(x+260,y+200,"Green");
}
else
{
setcolor(7);
outtextxy(x+260,y+200,"Black");
setcolor(2);
outtextxy(x+260,y+180,"Green");
}
}
void Marker(int turn)
{
int i;
for(i=0;i<150;i++)
{
allowed_square[i]=0;
source_square[i]=0;
movement_type[i]=0;
}
Counter=0;
if(turn==1)
for(i=0;i<256;i++)
{
if(Board[i]==1)
Check(i,1,2);
}
else if(turn==2)
for(i=0;i<256;i++)
{
if(Board[i]==2)
Check(i,2,1);
}
}
void Scorer()
{
int i;
int count_black=0,count_green=0;
for(i=0;i<256;i++)
{
if(Board[i]==1)
count_black++;
if(Board[i]==2)
count_green++;
}
gotoxy(74,7);
if(count_green<10)
cout<<" "<
else if(count_green<100)
cout<<" "<
else
cout<<""<
gotoxy(74,5);
if(count_black<10)
cout<<" "<
else if(count_black<100)
cout<<" "<
else
cout<<""<
}
void Draw_Allowed_Dots(int turn)
{
x=getmaxx()/2;
y=getmaxy()/2;
if(turn==1)
setcolor(0);
else if(turn==2)
setcolor(10);
else if(turn==0)//delete
setcolor(7);
for(int o=0;o<150;o++)
{
if(allowed_square[o]!=0)
{
circle(x-160+10+20*(allowed_square[o]%16),y-160+10+20*(allowed_square[o]/16),2);
circle(x-160+10+20*(allowed_square[o]%16),y-160+10+20*(allowed_square[o]/16),1);
}
}
}
void Convertor(int sqr,int turn)
{
int o,i;
for(o=0;o<150;o++)
{
if(allowed_square[o]==sqr)
{
i=source_square[o];
source_square[o]=allowed_square[o];
allowed_square[o]=i;
switch(movement_type[o])
{
case UP:
for(i=0;i<16;i++)
{
if( (allowed_square[o]-16*i)!=source_square[o])
{
Board[allowed_square[o]-16*i]=turn;
}
else
{
Board[allowed_square[o]-16*i]=turn;
break;
}
}
break;
case DOWN:
for(i=0;i<16;i++)
{
if( (allowed_square[o]+16*i)!=source_square[o])
{
Board[allowed_square[o]+16*i]=turn;
}
else
{
Board[allowed_square[o]+16*i]=turn;
break;
}
}
break;
case RIGHT:
for(i=0;i<16;i++)
{
if( (allowed_square[o]+1*i)!=source_square[o])
{
Board[allowed_square[o]+1*i]=turn;
}
else
{
Board[allowed_square[o]+1*i]=turn;
break;
}
}
break;
case LEFT:
for(i=0;i<16;i++)
{
if( (allowed_square[o]-1*i)!=source_square[o])
{
Board[allowed_square[o]-1*i]=turn;
}
else
{
Board[allowed_square[o]-1*i]=turn;
break;
}
}
break;
case RIGHT_UP:
for(i=0;i<16;i++)
{
if( (allowed_square[o]-15*i)!=source_square[o])
{
Board[allowed_square[o]-15*i]=turn;
}
else
{
Board[allowed_square[o]-15*i]=turn;
break;
}
}
break;
case RIGHT_DOWN:
for(i=0;i<16;i++)
{
if( (allowed_square[o]+17*i)!=source_square[o])
{
Board[allowed_square[o]+17*i]=turn;
}
else
{
Board[allowed_square[o]+17*i]=turn;
break;
}
}
break;
case LEFT_UP:
for(i=0;i<16;i++)
{
if( (allowed_square[o]-17*i)!=source_square[o])
{
Board[allowed_square[o]-17*i]=turn;
}
else
{
Board[allowed_square[o]-17*i]=turn;
break;
}
}
break;
case LEFT_DOWN:
for(i=0;i<16;i++)
{
if( (allowed_square[o]+15*i)!=source_square[o])
{
Board[allowed_square[o]+15*i]=turn;
}
else
{
Board[allowed_square[o]+15*i]=turn;
break;
}
}
break;
}
}
}
Board[119]=7;
Board[120]=7;
Board[135]=7;
Board[136]=7;
}
void Check(int sqr,int col1,int col2)
{
int i;
int qr=sqr;
int count_up=0,count_down=0,count_right=0,count_left=0;
int count_right_up=0,count_right_down=0,count_left_up=0,count_left_down=0;
for(i=0;i<16;i++)
{
if(qr==48||qr==63||qr==29||qr==46||qr==33||qr==18||(qr<13&&qr>2))
{ break; }
qr-=16; count_up++;
}
qr=sqr;
for(i=0;i<16;i++)
{
if(qr==207||qr==192||qr==222||qr==209||qr==226||qr==237||(qr<253&&qr>242))
{ break; }
qr+=16; count_down++;
}
qr=sqr;
for(i=0;i<16;i++)
{
if(qr==12||qr==29||qr==46||qr==222||qr==252||qr==237||(qr+1)%16==0)
{ break; }
qr+=1; count_right++;
}
qr=sqr;
for(i=0;i<16;i++)
{
if(qr==3||qr==18||qr==33||qr==209||qr==226||qr==243||(qr)%16==0)
{ break; }
qr-=1; count_left++;
}
qr=sqr;
for(i=0;i<16;i++)
{
if(qr==49||qr==33||qr==18||qr==34||qr==19||(qr)%16==0||(qr<13&&qr>2))
{ break; }
qr-=17; count_left_up++;
}
qr=sqr;
for(i=0;i<16;i++)
{
if(qr==29||qr==28||qr==46||qr==45||qr==62||(qr+1)%16==0||(qr<13&&qr>2))
{ break; }
qr-=15; count_right_up++;
}
qr=sqr;
for(i=0;i<16;i++)
{
if(qr==206||qr==222||qr==221||qr==236||qr==237||(qr+1)%16==0||(qr<253&&qr>242))
{ break; }
qr+=17; count_right_down++;
}
qr=sqr;
for(i=0;i<16;i++)
{
if(qr==209||qr==210||qr==226||qr==227||qr==193||(qr)%16==0||(qr<253&&qr>242))
{ break; }
qr+=15; count_left_down++;
}
int up_move=0;
qr=sqr;
for(i=0;i
{
qr-=16;
if(Board[qr]==col2)
{up_move=1;}
else if(Board[qr]==7)
{}
else if(Board[qr]==col1)
{break; }
else if(Board[qr]==0)
{
if(up_move==1)
{
up_move=qr;
allowed_square[Counter]=qr;
source_square[Counter]=sqr;
movement_type[Counter]=UP;
Counter++;
}
break; }
if(qr==48||qr==63||qr==29||qr==46||qr==33||qr==18||(qr<13&&qr>2))
{ break; }
}
int down_move=0;
qr=sqr;
for(i=0;i
{
qr+=16;
if(Board[qr]==col2)
{down_move=1;}
else if(Board[qr]==7)
{}
else if(Board[qr]==col1)
{break; }
else if(Board[qr]==0)
{
if(down_move==1)
{
down_move=qr;
allowed_square[Counter]=qr;
source_square[Counter]=sqr;
movement_type[Counter]=DOWN;
Counter++;
}
break; }
if(qr==207||qr==192||qr==222||qr==209||qr==226||qr==237||(qr<253&&qr>242))
{ break; }
}
int right_move=0;
qr=sqr;
for(i=0;i
{
qr+=1;
if(Board[qr]==col2)
{right_move=1;}
else if(Board[qr]==7)
{}
else if(Board[qr]==col1)
{break; }
else if(Board[qr]==0)
{
if(right_move==1)
{
right_move=qr;
allowed_square[Counter]=qr;
source_square[Counter]=sqr;
movement_type[Counter]=RIGHT;
Counter++;
}
break; }
if(qr==12||qr==29||qr==46||qr==222||qr==252||qr==237||(qr+1)%16==0)
{ break; }
}
int left_move=0;
qr=sqr;
for(i=0;i
{
qr-=1;
if(Board[qr]==col2)
{left_move=1;}
else if(Board[qr]==7)
{}
else if(Board[qr]==col1)
{break; }
else if(Board[qr]==0)
{
if(left_move==1)
{
left_move=qr;
allowed_square[Counter]=qr;
source_square[Counter]=sqr;
movement_type[Counter]=LEFT;
Counter++;
}
break; }
if(qr==3||qr==18||qr==33||qr==209||qr==226||qr==243||(qr)%16==0)
{ break; }
}
int left_up_move=0;
qr=sqr;
for(i=0;i
{
qr-=17;
if(Board[qr]==col2)
{left_up_move=1;}
else if(Board[qr]==7)
{}
else if(Board[qr]==col1)
{break; }
else if(Board[qr]==0)
{
if(left_up_move==1)
{
left_up_move=qr;
allowed_square[Counter]=qr;
source_square[Counter]=sqr;
movement_type[Counter]=LEFT_UP;
Counter++;
}
break; }
if(qr==49||qr==33||qr==18||qr==34||qr==19||(qr)%16==0||(qr<13&&qr>2))
{ break; }
}
int left_down_move=0;
qr=sqr;
for(i=0;i
{
qr+=15;
if(Board[qr]==col2)
{left_down_move=1;}
else if(Board[qr]==7)
{}
else if(Board[qr]==col1)
{break; }
else if(Board[qr]==0)
{
if(left_down_move==1)
{
left_down_move=qr;
allowed_square[Counter]=qr;
source_square[Counter]=sqr;
movement_type[Counter]=LEFT_DOWN;
Counter++;
}
break; }
if(qr==209||qr==210||qr==226||qr==227||qr==193||(qr)%16==0||(qr<253&&qr>242))
{ break; }
}
int right_down_move=0;
qr=sqr;
for(i=0;i
{
qr+=17;
if(Board[qr]==col2)
{right_down_move=1;}
else if(Board[qr]==7)
{}
else if(Board[qr]==col1)
{break; }
else if(Board[qr]==0)
{
if(right_down_move==1)
{
right_down_move=qr;
allowed_square[Counter]=qr;
source_square[Counter]=sqr;
movement_type[Counter]=RIGHT_DOWN;
Counter++;
}
break; }
if(qr==206||qr==222||qr==221||qr==236||qr==237||(qr+1)%16==0||(qr<253&&qr>242))
{ break; }
}
int right_up_move=0;
qr=sqr;
for(i=0;i
{
qr-=15;
if(Board[qr]==col2)
{right_up_move=1;}
else if(Board[qr]==7)
{}
else if(Board[qr]==col1)
{break; }
else if(Board[qr]==0)
{
if(right_up_move==1)
{
right_up_move=qr;
allowed_square[Counter]=qr;
source_square[Counter]=sqr;
movement_type[Counter]=RIGHT_UP;
Counter++;
}
break; }
if(qr==29||qr==28||qr==46||qr==45||qr==62||(qr+1)%16==0||(qr<13&&qr>2))
{ break; }
}
}
void Screen()
{
x=getmaxx()/2;
y=getmaxy()/2;
int i,o;
setlinestyle(SOLID_LINE,0,2);
setcolor(8);
for(i=0;i<17;i++)
{
line(x-160,y-160+i*20,x+160,y-160+i*20);
line(x-160+i*20,y+160,x-160+i*20,y-160);
}
setlinestyle(SOLID_LINE,0,1);
for(o=0;o<256;o++)
{
if(Board[o]==9)
{
setfillstyle(SOLID_FILL,8);
floodfill(x-160+10+20*(o%16),y-160+10+20*(o/16),8);
}
if(Board[o]==7)
{
setfillstyle(SOLID_FILL,4);
floodfill(x-160+10+20*(o%16),y-160+10+20*(o/16),8);
}
if(Board[o]==1)
{
setfillstyle(SOLID_FILL,0);
floodfill(x-160+10+20*(o%16),y-160+10+20*(o/16),8);
}
if(Board[o]==2)
{
setfillstyle(SOLID_FILL,10);
floodfill(x-160+10+20*(o%16),y-160+10+20*(o/16),8);
}
}
setcolor(6);
circle(x,y+200,10);
setfillstyle(SOLID_FILL,6);
floodfill(x,y+200,6);
setcolor(14);
line(x-4,y-4+200,x+4,y+4+200);
line(x+4,y-4+200,x-4,y+4+200);
setcolor(8);
rectangle(x-180,y-180,x+180,y+180);
setfillstyle(SOLID_FILL,8);
floodfill(x-170,y,8);
setcolor(0);
line(x-180,y-120,x-120,y-180);
line(x+180,y-120,x+120,y-180);
line(x-180,y+120,x-120,y+180);
line(x+180,y+120,x+120,y+180);
setfillstyle(SOLID_FILL,0);
floodfill(x-175,y-175,0);
floodfill(x+175,y-175,0);
floodfill(x+175,y+175,0);
floodfill(x-175,y+175,0);
settextstyle(3,0,1);
setcolor(1);
outtextxy(x+200,y-182,"BLACK");
setcolor(2);
outtextxy(x+200,y-151,"GREEN");
}
void Press_Exit_Button()
{
setcolor(14);
circle(x,y+200,10);
setfillstyle(SOLID_FILL,14);
floodfill(x,y+202,14);
setcolor(6);
line(x-4,y-4+200,x+4,y+4+200);
line(x+4,y-4+200,x-4,y+4+200);
delay(500);
setcolor(6);
circle(x,y+200,10);
setfillstyle(SOLID_FILL,6);
floodfill(x,y+205,6);
setcolor(14);
line(x-4,y-4+200,x+4,y+4+200);
line(x+4,y-4+200,x-4,y+4+200);
delay(500);
}
int Ask_Mouse(int mx,int my)
{
int Square=1000;
int xx=50,yy=50;
if(mx>=x-160&&mx else if(mx>=x-140&&mx else if(mx>=x-120&&mx else if(mx>=x-100&&mx else if(mx>=x-80&&mx else if(mx>=x-60&&mx else if(mx>=x-40&&mx else if(mx>=x-20&&mx else if(mx>=x &&mx else if(mx>=x+20&&mx else if(mx>=x+40&&mx else if(mx>=x+60&&mx else if(mx>=x+80&&mx else if(mx>=x+100&&mx else if(mx>=x+120&&mx else if(mx>=x+140&&mx
if(my>=y-160&&my else if(my>=y-140&&my else if(my>=y-120&&my else if(my>=y-100&&my else if(my>=y-80&&my else if(my>=y-60&&my else if(my>=y-40&&my else if(my>=y-20&&my else if(my>=y &&my else if(my>=y+20&&my else if(my>=y+40&&my else if(my>=y+60&&my else if(my>=y+80&&my else if(my>=y+100&&my else if(my>=y+120&&my else if(my>=y+140&&my
if(xx!=50&&yy!=50)
{
Square=16*yy+xx;
return Square;
}
if(mx>=x-10&&mx=y+190&&my
return 555;
if(mx>=x-260&&mx=y+195&&my
return 333;
return 1;
}
void Reset()
{
int i;
for(i=0;i<256;i++) Board[i]=0;
for(i=0;i<3;i++) Board[i]=9;
for(i=13;i<18;i++) Board[i]=9;
for(i=30;i<33;i++) Board[i]=9;
Board[47]=9; Board[208]=9;
for(i=223;i<226;i++) Board[i]=9;
for(i=238;i<243;i++) Board[i]=9;
for(i=253;i<256;i++) Board[i]=9;
Board[103]=1; Board[104]=2;
Board[119]=7; Board[120]=7;
Board[135]=7; Board[136]=7;
Board[151]=2; Board[152]=1;
for(i=0;i<150;i++)
{
allowed_square[i]=0;
source_square[i]=0;
movement_type[i]=0;
}
cleardevice();
}
void Welcome()
{
setcolor(LIGHTBLUE);
settextstyle(GOTHIC_FONT,HORIZ_DIR,5);
outtextxy(x-100,y-210,"TRYSTER");
setcolor(BLUE);
settextstyle(3,HORIZ_DIR,3);
setcolor(YELLOW);
outtextxy(x-40,y+130,"Creator");
setcolor(RED);
outtextxy(x-255,y+180," Suneet Singh 99/CSE/123 CRSCE Murthal");
setcolor(6);
outtextxy(x-105,y-60,"'First Prize Winner'");
outtextxy(x-225,y-10,"N-CODE Predefined Software Competition.");
outtextxy(x-125,y+50,"TRYST 2002, IIT-Delhi");
setcolor(GREEN);
outtextxy(x-255,y+180," - - ");
sleep(1);
getch();
cleardevice();
}
void Who_Play_First()
{
setcolor(4);
settextstyle(DEFAULT_FONT,0,2);
outtextxy(x-115,y-20,"Who plays first ");
outtextxy(x-135,y+20,"Player Computer");
setcolor(14);
outtextxy(x-135,y+20,"P C");
settextstyle(4,0,4);
setcolor(6);
outtextxy(x-70,y-232,"TRYSTER");
settextstyle(DEFAULT_FONT,0,2);
while(1)
{
if(kbhit())
{
ii.h.ah=0;
int86(22,&ii,&oo);
if(oo.h.ah==25)
{
Whoplays_first=PLAYER;
setcolor(4);
outtextxy(x-135,y+20,"P");
delay(400);
setcolor(14);
outtextxy(x-135,y+20,"P");
delay(400);
break;
}
if(oo.h.ah==46)
{
Whoplays_first=COMPUTER;
setcolor(4);
outtextxy(x-135,y+20," C");
delay(400);
setcolor(14);
outtextxy(x-135,y+20," C");
delay(400);
break;
}
}
}
setfillstyle(SOLID_FILL,7);
bar(x-180,y-180,x+180,y+180);
}
void Color_Allotment()
{
if(Whoplays_first==PLAYER)
{
settextstyle(DEFAULT_FONT,0,1);
setcolor(4);
outtextxy(x+190,y+20,"Choose Color...");
outtextxy(x+190,y+50,"Click on the DOT");
while(1)
{
getmousepos(&button,&mousex,&mousey);
if((button&1)==1)
{
hidemouseptr();
while((button&1)==1)
{
getmousepos(&button,&mousex,&mousey);
mousetrap=1;
}
getmousepos(&button,&mousex,&mousey);
reply=Ask_Mouse(mousex,mousey);
if(reply==87||reply==102||reply==153||reply==168)
{
Marker(2);
Draw_Allowed_Dots(0);
Marker(1);
Draw_Allowed_Dots(0);
turn =2;
Computer_Color=1;
Player_Color=2;
break;
}
else if(reply==88||reply==105||reply==150||reply==167)
{
Marker(2);
Draw_Allowed_Dots(0);
Marker(1);
Draw_Allowed_Dots(0);
turn =1;
Computer_Color=2;
Player_Color=1;
break;
}
mousetrap=0;
showmouseptr();
}
}
settextstyle(DEFAULT_FONT,0,1);
setcolor(0);
outtextxy(x+190,y+20,"Choose Color...");
outtextxy(x+190,y+50,"Click on the DOT");
}
else if(Whoplays_first==COMPUTER)
{
settextstyle(DEFAULT_FONT,0,1);
setcolor(4);
outtextxy(x+190,y+20,"Computer'S Color");
outtextxy(x+190,y+50,"Green Black");
setcolor(14);
outtextxy(x+190,y+50,"G B");
while(1){
if(kbhit())
{
ii.h.ah=0;
int86(22,&ii,&oo);
if(oo.h.ah==34)
{
setcolor(4);
outtextxy(x+190,y+50,"G");
delay(400);
setcolor(14);
outtextxy(x+190,y+50,"G");
delay(400);
turn=2;
Computer_Color=2;
Player_Color=1;
break;
}
if(oo.h.ah==48)
{
setcolor(4);
outtextxy(x+278,y+50,"B");
delay(400);
setcolor(14);
outtextxy(x+278,y+50,"B");
delay(400);
turn=1;
Computer_Color=1;
Player_Color=2;
break;
}
}
}
settextstyle(DEFAULT_FONT,0,1);
setcolor(0);
outtextxy(x+190,y+20,"Computer'S Color");
outtextxy(x+190,y+50,"Green Black");
Marker(2);
Draw_Allowed_Dots(0);
Marker(1);
Draw_Allowed_Dots(0);
}
}
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<dos.h>
#include<process.h>
#include"mouse.h"
#define UP 0
#define DOWN 1
#define RIGHT 2
#define LEFT 3
#define RIGHT_UP 4
#define RIGHT_DOWN 5
#define LEFT_UP 6
#define LEFT_DOWN 7
#define PLAYER 0
#define COMPUTER 1
#define YES 1
#define NO 0
void Welcome();
void Screen();
void Marker(int);
void Check(int,int,int);
int Ask_Mouse(int,int);
void Draw_Allowed_Dots(int);
void Convertor(int,int);
void Scorer();
void Press_Exit_Button();
int Computer_Move();
void Write_Status_Game(int);
void Result_Declaration();
void Reset();
int Play();
void Who_Play_First();
void Color_Allotment();
union REGS ii,oo;
int Board[256]=
{ 9, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9,
9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9,
9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9,
9, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 9 };
int x,y;
int allowed_square[150],source_square[150],movement_type[150];
int Counter;
int Computer_Color=0;
int Player_Color=0;
int button,mousex,mousey,mousetrap=0;
int reply=1,Whoplays_first=0;
int turn=0,flag_allowed_square_selected=0,flag_no_chance=0;
void main() // creator- S u ne et sin gh 99 / cse/123 C RS CE M urthal// this is to protect from thiefs ;-)
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
x=getmaxx()/2;
y=getmaxy()/2;
int i;
for(i=0;i<150;i++)
{
allowed_square[i]=0;
source_square[i]=0;
movement_type[i]=0;
}
if(initmouse()==0)
{
closegraph();
restorecrtmode();
cout<<"\nMouse driver not loaded";
exit(1);
}
restrictmouseptr(1,1,getmaxx()-1,getmaxy()-1);
showmouseptr();
hidemouseptr();
Welcome();
Play();
closegraph();
}
int Play()
{
int o;
int if_over=NO;
int skip=NO;
Who_Play_First();
Screen();
showmouseptr();
Marker(2);
Draw_Allowed_Dots(2);
Marker(1);
Draw_Allowed_Dots(1);
Color_Allotment();
reply=1;
mousetrap=0;
if(Computer_Color!=turn) {
Marker(Player_Color);
Draw_Allowed_Dots(Player_Color);
}
else if(Computer_Color==turn) {
Marker(Computer_Color);
Draw_Allowed_Dots(Computer_Color);
}
Write_Status_Game(Computer_Color);
settextstyle(3,0,1);
setcolor(4);
outtextxy(x-260,y+190,"Reset");
showmouseptr();
while(1)
{
getmousepos(&button,&mousex,&mousey);
if(Computer_Color==turn)
{
hidemouseptr();
reply=Computer_Move();
mousetrap=1;
flag_allowed_square_selected=0;
flag_no_chance=1;
for(o=0;o<150;o++)
{
if(allowed_square[o]==reply)
flag_allowed_square_selected=1;
if(allowed_square[o]!=0)
flag_no_chance=0;
}
if(flag_no_chance==1)
{
if(turn==1)
turn=2;
else if(turn==2)
turn=1;
Draw_Allowed_Dots(0);
Marker(turn);
Screen();
Draw_Allowed_Dots(turn);
mousetrap=0;
showmouseptr();
}
if(flag_allowed_square_selected==0)
{
mousetrap=0;
showmouseptr();
}
showmouseptr();
}
if((button&1)==1)
{
hidemouseptr();
while((button&1)==1)
{
getmousepos(&button,&mousex,&mousey);
mousetrap=1;
}
getmousepos(&button,&mousex,&mousey);
if(Computer_Color!=turn)
reply=Ask_Mouse(mousex,mousey);
else
{
mousetrap=0;
skip=YES;
}
if(skip==NO)
{
if(reply==555)
{
hidemouseptr();
Press_Exit_Button();
exit(0);
}
if(reply==333)
{
hidemouseptr();
Reset();
showmouseptr();
Play();
}
flag_allowed_square_selected=0;
flag_no_chance=1;
for(o=0;o<150;o++)
{
if(allowed_square[o]==reply)
flag_allowed_square_selected=1;
if(allowed_square[o]!=0)
flag_no_chance=0;
}
if(flag_no_chance==1)
{
if(turn==1)
turn=2;
else if(turn==2)
turn=1;
Draw_Allowed_Dots(0);
Marker(turn);
Screen();
Draw_Allowed_Dots(turn);
mousetrap=0;
showmouseptr();
}
if(flag_allowed_square_selected==0)
{
mousetrap=0;
showmouseptr();
}
}
showmouseptr();
}
if(mousetrap==1)
{
hidemouseptr();
Draw_Allowed_Dots(0);
mousetrap=0;
Convertor(reply,turn);
if(turn==1)
turn=2;
else if(turn==2)
turn=1;
Marker(turn);
if(Counter==0)
if_over++;
else
if_over=0;
Screen();
Draw_Allowed_Dots(turn);
Scorer();
int cc=0;
for(o=0;o<256;o++)
{
if(Board[o]!=0)
cc++;
}
if(cc==256||if_over>=3)
Result_Declaration();
showmouseptr();
}
}
}
int Computer_Move()
{
int store_c=Counter;
int store_sqr;
int flag=1;
int stage=0;
for(int o=0;o<256;o++)
if(Board[o]==0)
stage++;
Marker(Computer_Color);
for(o=0;o
{
if(allowed_square[o]==3||allowed_square[o]==48||allowed_square[o]==63||allowed_square[o]==12)
{ return(allowed_square[o]); }
if(allowed_square[o]==192||allowed_square[o]==243||allowed_square[o]==207||allowed_square[o]==252)
{ return(allowed_square[o]); }
}
for(o=0;o
{
if(allowed_square[o]==18 && Board[3]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==33 && Board[48]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==29 && Board[12]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==46 && Board[63]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==209 && Board[192]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==226 && Board[243]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==222 && Board[207]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==237 && Board[252]!=0)
{ return(allowed_square[o]);}
}
for(o=0;o
{
if(allowed_square[o]%8==0)
{
if(allowed_square[o]!=64 && allowed_square[o]!=176)
{ return(allowed_square[o]);}
else if(allowed_square[o]==64 && Board[48]!=0)
{ return(allowed_square[o]);}
else if(allowed_square[o]==176 && Board[192]!=0)
{ return(allowed_square[o]);}
}
}
for(o=0;o
{
if(allowed_square[o]%8==7)
{
if(allowed_square[o]!=79 && allowed_square[o]!=191)
{ return(allowed_square[o]);}
else if(allowed_square[o]==79 && Board[63]!=0)
{ return(allowed_square[o]);}
else if(allowed_square[o]==191 && Board[207]!=0)
{ return(allowed_square[o]);}
}
}
for(o=0;o
{
if(allowed_square[o]<16)
{
if(allowed_square[o]!=4 && allowed_square[o]!=11)
{ return(allowed_square[o]);}
else if(allowed_square[o]==4 && Board[3]!=0)
{ return(allowed_square[o]);}
else if(allowed_square[o]==11 && Board[12]!=0)
{ return(allowed_square[o]);}
}
}
for(o=0;o
{
if(allowed_square[o]>240)
{
if(allowed_square[o]!=244 && allowed_square[o]!=251)
{ return(allowed_square[o]);}
else if(allowed_square[o]==244 && Board[243]!=0)
{ return(allowed_square[o]);}
else if(allowed_square[o]==251 && Board[252]!=0)
{ return(allowed_square[o]);}
}
}
if(stage<25)
for(o=0;o
{
if(allowed_square[o]==18)
{ return(allowed_square[o]);}
if(allowed_square[o]==33)
{ return(allowed_square[o]);}
if(allowed_square[o]==29)
{ return(allowed_square[o]);}
if(allowed_square[o]==46)
{ return(allowed_square[o]);}
if(allowed_square[o]==209)
{ return(allowed_square[o]);}
if(allowed_square[o]==226)
{ return(allowed_square[o]);}
if(allowed_square[o]==222)
{ return(allowed_square[o]);}
if(allowed_square[o]==237)
{ return(allowed_square[o]);}
}
for(o=0;o
{
if(allowed_square[o]==19 && Board[3]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==49 && Board[48]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==28 && Board[12]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==62 && Board[63]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==193 && Board[192]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==227 && Board[243]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==206 && Board[207]!=0)
{ return(allowed_square[o]);}
if(allowed_square[o]==236 && Board[252]!=0)
{ return(allowed_square[o]);}
}
for(o=0;o
{
if(allowed_square[o]==34||allowed_square[o]==45||allowed_square[o]==210||allowed_square[o]==221)
{ return(allowed_square[o]);}
}
for(o=0;o
{
if(allowed_square[o]==18 && Board[3]==0 && Board[33]!=Player_Color)
{ return(allowed_square[o]);}
if(allowed_square[o]==33 && Board[48]==0 && Board[18]!=Player_Color)
{ return(allowed_square[o]);}
if(allowed_square[o]==29 && Board[12]==0 && Board[46]!=Player_Color)
{ return(allowed_square[o]);}
if(allowed_square[o]==46 && Board[63]==0 && Board[29]!=Player_Color)
{ return(allowed_square[o]);}
if(allowed_square[o]==209 && Board[192]==0 && Board[226]!=Player_Color)
{ return(allowed_square[o]);}
if(allowed_square[o]==226 && Board[243]==0 && Board[209]!=Player_Color)
{ return(allowed_square[o]);}
if(allowed_square[o]==222 && Board[207]==0 && Board[237]!=Player_Color)
{ return(allowed_square[o]);}
if(allowed_square[o]==237 && Board[252]==0 && Board[222]!=Player_Color)
{ return(allowed_square[o]);}
}
for(o=0;o
{
store_sqr=allowed_square[o];
if(allowed_square[o]==18 && Board[3]==0) ;
else if(allowed_square[o]==33 && Board[48]==0) ;
else if(allowed_square[o]==29 && Board[12]==0) ;
else if(allowed_square[o]==46 && Board[63]==0) ;
else if(allowed_square[o]==209 && Board[192]==0) ;
else if(allowed_square[o]==226 && Board[243]==0) ;
else if(allowed_square[o]==222 && Board[207]==0) ;
else if(allowed_square[o]==237 && Board[252]==0) ;
else if(allowed_square[o]==64 || allowed_square[o]==176) ;
else if(allowed_square[o]==79 || allowed_square[o]==191) ;
else if(allowed_square[o]==4 || allowed_square[o]==11) ;
else if(allowed_square[o]==244 || allowed_square[o]==251) ;
else if(allowed_square[o]==19 && Board[3]==0) ;
else if(allowed_square[o]==49 && Board[48]==0) ;
else if(allowed_square[o]==28 && Board[12]==0) ;
else if(allowed_square[o]==62 && Board[63]==0) ;
else if(allowed_square[o]==193 && Board[192]==0) ;
else if(allowed_square[o]==227 && Board[243]==0) ;
else if(allowed_square[o]==206 && Board[207]==0) ;
else if(allowed_square[o]==236 && Board[252]==0) ;
else if(allowed_square[o]!=0)
{
Board[allowed_square[o]]=Computer_Color;
Marker(Player_Color);
flag=1;
for(int i=0;i<150;i++)
{
if(allowed_square[i]==3||allowed_square[i]==12||allowed_square[i]==48||allowed_square[i]=
flag=0;
}
allowed_square[o]=store_sqr;
Board[allowed_square[o]]=0;
Marker(Computer_Color);
Counter=store_c;
if(flag==1){
return(allowed_square[o]);}
}
}
for(o=0;o
{
store_sqr=allowed_square[o];
if(allowed_square[o]==18 && Board[3]==0) ;
else if(allowed_square[o]==33 && Board[48]==0) ;
else if(allowed_square[o]==29 && Board[12]==0) ;
else if(allowed_square[o]==46 && Board[63]==0) ;
else if(allowed_square[o]==209 && Board[192]==0) ;
else if(allowed_square[o]==226 && Board[243]==0) ;
else if(allowed_square[o]==222 && Board[207]==0) ;
else if(allowed_square[o]==237 && Board[252]==0) ;
else if(allowed_square[o]==64 || allowed_square[o]==176) ;
else if(allowed_square[o]==79 || allowed_square[o]==191) ;
else if(allowed_square[o]==4 || allowed_square[o]==11) ;
else if(allowed_square[o]==244 || allowed_square[o]==251) ;
else if(allowed_square[o]==19 && Board[3]==0) ;
else if(allowed_square[o]==49 && Board[48]==0) ;
else if(allowed_square[o]==28 && Board[12]==0) ;
else if(allowed_square[o]==62 && Board[63]==0) ;
else if(allowed_square[o]==193 && Board[192]==0) ;
else if(allowed_square[o]==227 && Board[243]==0) ;
else if(allowed_square[o]==206 && Board[207]==0) ;
else if(allowed_square[o]==236 && Board[252]==0) ;
else if(allowed_square[o]!=0)
{
return(allowed_square[o]);
}
}
randomize();
int mix=random(Counter);
for(o=0;o
{
if(o==mix)
if(allowed_square[o]!=0)
{
return(allowed_square[o]);
}
}
}
void Result_Declaration()
{
setcolor(6);
settextstyle(DEFAULT_FONT,0,1);
int c=0,p=0;
for(int o=0;o<256;o++)
{
if(Board[o]==Computer_Color)
c++;
if(Board[o]==Player_Color)
p++;
}
if(c>p)
outtextxy(x+200,y+0,"Computer Wins");
else if(p>c)
outtextxy(x+200,y+0,"Player Wins");
else if(c==p)
outtextxy(x+200,y+0,"Game Drawn");
}
void Write_Status_Game(int col)
{
setcolor(6);
settextstyle(DEFAULT_FONT,0,1);
outtextxy(x+190,y+180,"Computer");
outtextxy(x+190,y+200,"Player");
if(col==1)
{
setcolor(7);
outtextxy(x+260,y+180,"Black");
setcolor(2);
outtextxy(x+260,y+200,"Green");
}
else
{
setcolor(7);
outtextxy(x+260,y+200,"Black");
setcolor(2);
outtextxy(x+260,y+180,"Green");
}
}
void Marker(int turn)
{
int i;
for(i=0;i<150;i++)
{
allowed_square[i]=0;
source_square[i]=0;
movement_type[i]=0;
}
Counter=0;
if(turn==1)
for(i=0;i<256;i++)
{
if(Board[i]==1)
Check(i,1,2);
}
else if(turn==2)
for(i=0;i<256;i++)
{
if(Board[i]==2)
Check(i,2,1);
}
}
void Scorer()
{
int i;
int count_black=0,count_green=0;
for(i=0;i<256;i++)
{
if(Board[i]==1)
count_black++;
if(Board[i]==2)
count_green++;
}
gotoxy(74,7);
if(count_green<10)
cout<<" "<
else if(count_green<100)
cout<<" "<
else
cout<<""<
gotoxy(74,5);
if(count_black<10)
cout<<" "<
else if(count_black<100)
cout<<" "<
else
cout<<""<
}
void Draw_Allowed_Dots(int turn)
{
x=getmaxx()/2;
y=getmaxy()/2;
if(turn==1)
setcolor(0);
else if(turn==2)
setcolor(10);
else if(turn==0)//delete
setcolor(7);
for(int o=0;o<150;o++)
{
if(allowed_square[o]!=0)
{
circle(x-160+10+20*(allowed_square[o]%16),y-160+10+20*(allowed_square[o]/16),2);
circle(x-160+10+20*(allowed_square[o]%16),y-160+10+20*(allowed_square[o]/16),1);
}
}
}
void Convertor(int sqr,int turn)
{
int o,i;
for(o=0;o<150;o++)
{
if(allowed_square[o]==sqr)
{
i=source_square[o];
source_square[o]=allowed_square[o];
allowed_square[o]=i;
switch(movement_type[o])
{
case UP:
for(i=0;i<16;i++)
{
if( (allowed_square[o]-16*i)!=source_square[o])
{
Board[allowed_square[o]-16*i]=turn;
}
else
{
Board[allowed_square[o]-16*i]=turn;
break;
}
}
break;
case DOWN:
for(i=0;i<16;i++)
{
if( (allowed_square[o]+16*i)!=source_square[o])
{
Board[allowed_square[o]+16*i]=turn;
}
else
{
Board[allowed_square[o]+16*i]=turn;
break;
}
}
break;
case RIGHT:
for(i=0;i<16;i++)
{
if( (allowed_square[o]+1*i)!=source_square[o])
{
Board[allowed_square[o]+1*i]=turn;
}
else
{
Board[allowed_square[o]+1*i]=turn;
break;
}
}
break;
case LEFT:
for(i=0;i<16;i++)
{
if( (allowed_square[o]-1*i)!=source_square[o])
{
Board[allowed_square[o]-1*i]=turn;
}
else
{
Board[allowed_square[o]-1*i]=turn;
break;
}
}
break;
case RIGHT_UP:
for(i=0;i<16;i++)
{
if( (allowed_square[o]-15*i)!=source_square[o])
{
Board[allowed_square[o]-15*i]=turn;
}
else
{
Board[allowed_square[o]-15*i]=turn;
break;
}
}
break;
case RIGHT_DOWN:
for(i=0;i<16;i++)
{
if( (allowed_square[o]+17*i)!=source_square[o])
{
Board[allowed_square[o]+17*i]=turn;
}
else
{
Board[allowed_square[o]+17*i]=turn;
break;
}
}
break;
case LEFT_UP:
for(i=0;i<16;i++)
{
if( (allowed_square[o]-17*i)!=source_square[o])
{
Board[allowed_square[o]-17*i]=turn;
}
else
{
Board[allowed_square[o]-17*i]=turn;
break;
}
}
break;
case LEFT_DOWN:
for(i=0;i<16;i++)
{
if( (allowed_square[o]+15*i)!=source_square[o])
{
Board[allowed_square[o]+15*i]=turn;
}
else
{
Board[allowed_square[o]+15*i]=turn;
break;
}
}
break;
}
}
}
Board[119]=7;
Board[120]=7;
Board[135]=7;
Board[136]=7;
}
void Check(int sqr,int col1,int col2)
{
int i;
int qr=sqr;
int count_up=0,count_down=0,count_right=0,count_left=0;
int count_right_up=0,count_right_down=0,count_left_up=0,count_left_down=0;
for(i=0;i<16;i++)
{
if(qr==48||qr==63||qr==29||qr==46||qr==33||qr==18||(qr<13&&qr>2))
{ break; }
qr-=16; count_up++;
}
qr=sqr;
for(i=0;i<16;i++)
{
if(qr==207||qr==192||qr==222||qr==209||qr==226||qr==237||(qr<253&&qr>242))
{ break; }
qr+=16; count_down++;
}
qr=sqr;
for(i=0;i<16;i++)
{
if(qr==12||qr==29||qr==46||qr==222||qr==252||qr==237||(qr+1)%16==0)
{ break; }
qr+=1; count_right++;
}
qr=sqr;
for(i=0;i<16;i++)
{
if(qr==3||qr==18||qr==33||qr==209||qr==226||qr==243||(qr)%16==0)
{ break; }
qr-=1; count_left++;
}
qr=sqr;
for(i=0;i<16;i++)
{
if(qr==49||qr==33||qr==18||qr==34||qr==19||(qr)%16==0||(qr<13&&qr>2))
{ break; }
qr-=17; count_left_up++;
}
qr=sqr;
for(i=0;i<16;i++)
{
if(qr==29||qr==28||qr==46||qr==45||qr==62||(qr+1)%16==0||(qr<13&&qr>2))
{ break; }
qr-=15; count_right_up++;
}
qr=sqr;
for(i=0;i<16;i++)
{
if(qr==206||qr==222||qr==221||qr==236||qr==237||(qr+1)%16==0||(qr<253&&qr>242))
{ break; }
qr+=17; count_right_down++;
}
qr=sqr;
for(i=0;i<16;i++)
{
if(qr==209||qr==210||qr==226||qr==227||qr==193||(qr)%16==0||(qr<253&&qr>242))
{ break; }
qr+=15; count_left_down++;
}
int up_move=0;
qr=sqr;
for(i=0;i
{
qr-=16;
if(Board[qr]==col2)
{up_move=1;}
else if(Board[qr]==7)
{}
else if(Board[qr]==col1)
{break; }
else if(Board[qr]==0)
{
if(up_move==1)
{
up_move=qr;
allowed_square[Counter]=qr;
source_square[Counter]=sqr;
movement_type[Counter]=UP;
Counter++;
}
break; }
if(qr==48||qr==63||qr==29||qr==46||qr==33||qr==18||(qr<13&&qr>2))
{ break; }
}
int down_move=0;
qr=sqr;
for(i=0;i
{
qr+=16;
if(Board[qr]==col2)
{down_move=1;}
else if(Board[qr]==7)
{}
else if(Board[qr]==col1)
{break; }
else if(Board[qr]==0)
{
if(down_move==1)
{
down_move=qr;
allowed_square[Counter]=qr;
source_square[Counter]=sqr;
movement_type[Counter]=DOWN;
Counter++;
}
break; }
if(qr==207||qr==192||qr==222||qr==209||qr==226||qr==237||(qr<253&&qr>242))
{ break; }
}
int right_move=0;
qr=sqr;
for(i=0;i
{
qr+=1;
if(Board[qr]==col2)
{right_move=1;}
else if(Board[qr]==7)
{}
else if(Board[qr]==col1)
{break; }
else if(Board[qr]==0)
{
if(right_move==1)
{
right_move=qr;
allowed_square[Counter]=qr;
source_square[Counter]=sqr;
movement_type[Counter]=RIGHT;
Counter++;
}
break; }
if(qr==12||qr==29||qr==46||qr==222||qr==252||qr==237||(qr+1)%16==0)
{ break; }
}
int left_move=0;
qr=sqr;
for(i=0;i
{
qr-=1;
if(Board[qr]==col2)
{left_move=1;}
else if(Board[qr]==7)
{}
else if(Board[qr]==col1)
{break; }
else if(Board[qr]==0)
{
if(left_move==1)
{
left_move=qr;
allowed_square[Counter]=qr;
source_square[Counter]=sqr;
movement_type[Counter]=LEFT;
Counter++;
}
break; }
if(qr==3||qr==18||qr==33||qr==209||qr==226||qr==243||(qr)%16==0)
{ break; }
}
int left_up_move=0;
qr=sqr;
for(i=0;i
{
qr-=17;
if(Board[qr]==col2)
{left_up_move=1;}
else if(Board[qr]==7)
{}
else if(Board[qr]==col1)
{break; }
else if(Board[qr]==0)
{
if(left_up_move==1)
{
left_up_move=qr;
allowed_square[Counter]=qr;
source_square[Counter]=sqr;
movement_type[Counter]=LEFT_UP;
Counter++;
}
break; }
if(qr==49||qr==33||qr==18||qr==34||qr==19||(qr)%16==0||(qr<13&&qr>2))
{ break; }
}
int left_down_move=0;
qr=sqr;
for(i=0;i
{
qr+=15;
if(Board[qr]==col2)
{left_down_move=1;}
else if(Board[qr]==7)
{}
else if(Board[qr]==col1)
{break; }
else if(Board[qr]==0)
{
if(left_down_move==1)
{
left_down_move=qr;
allowed_square[Counter]=qr;
source_square[Counter]=sqr;
movement_type[Counter]=LEFT_DOWN;
Counter++;
}
break; }
if(qr==209||qr==210||qr==226||qr==227||qr==193||(qr)%16==0||(qr<253&&qr>242))
{ break; }
}
int right_down_move=0;
qr=sqr;
for(i=0;i
{
qr+=17;
if(Board[qr]==col2)
{right_down_move=1;}
else if(Board[qr]==7)
{}
else if(Board[qr]==col1)
{break; }
else if(Board[qr]==0)
{
if(right_down_move==1)
{
right_down_move=qr;
allowed_square[Counter]=qr;
source_square[Counter]=sqr;
movement_type[Counter]=RIGHT_DOWN;
Counter++;
}
break; }
if(qr==206||qr==222||qr==221||qr==236||qr==237||(qr+1)%16==0||(qr<253&&qr>242))
{ break; }
}
int right_up_move=0;
qr=sqr;
for(i=0;i
{
qr-=15;
if(Board[qr]==col2)
{right_up_move=1;}
else if(Board[qr]==7)
{}
else if(Board[qr]==col1)
{break; }
else if(Board[qr]==0)
{
if(right_up_move==1)
{
right_up_move=qr;
allowed_square[Counter]=qr;
source_square[Counter]=sqr;
movement_type[Counter]=RIGHT_UP;
Counter++;
}
break; }
if(qr==29||qr==28||qr==46||qr==45||qr==62||(qr+1)%16==0||(qr<13&&qr>2))
{ break; }
}
}
void Screen()
{
x=getmaxx()/2;
y=getmaxy()/2;
int i,o;
setlinestyle(SOLID_LINE,0,2);
setcolor(8);
for(i=0;i<17;i++)
{
line(x-160,y-160+i*20,x+160,y-160+i*20);
line(x-160+i*20,y+160,x-160+i*20,y-160);
}
setlinestyle(SOLID_LINE,0,1);
for(o=0;o<256;o++)
{
if(Board[o]==9)
{
setfillstyle(SOLID_FILL,8);
floodfill(x-160+10+20*(o%16),y-160+10+20*(o/16),8);
}
if(Board[o]==7)
{
setfillstyle(SOLID_FILL,4);
floodfill(x-160+10+20*(o%16),y-160+10+20*(o/16),8);
}
if(Board[o]==1)
{
setfillstyle(SOLID_FILL,0);
floodfill(x-160+10+20*(o%16),y-160+10+20*(o/16),8);
}
if(Board[o]==2)
{
setfillstyle(SOLID_FILL,10);
floodfill(x-160+10+20*(o%16),y-160+10+20*(o/16),8);
}
}
setcolor(6);
circle(x,y+200,10);
setfillstyle(SOLID_FILL,6);
floodfill(x,y+200,6);
setcolor(14);
line(x-4,y-4+200,x+4,y+4+200);
line(x+4,y-4+200,x-4,y+4+200);
setcolor(8);
rectangle(x-180,y-180,x+180,y+180);
setfillstyle(SOLID_FILL,8);
floodfill(x-170,y,8);
setcolor(0);
line(x-180,y-120,x-120,y-180);
line(x+180,y-120,x+120,y-180);
line(x-180,y+120,x-120,y+180);
line(x+180,y+120,x+120,y+180);
setfillstyle(SOLID_FILL,0);
floodfill(x-175,y-175,0);
floodfill(x+175,y-175,0);
floodfill(x+175,y+175,0);
floodfill(x-175,y+175,0);
settextstyle(3,0,1);
setcolor(1);
outtextxy(x+200,y-182,"BLACK");
setcolor(2);
outtextxy(x+200,y-151,"GREEN");
}
void Press_Exit_Button()
{
setcolor(14);
circle(x,y+200,10);
setfillstyle(SOLID_FILL,14);
floodfill(x,y+202,14);
setcolor(6);
line(x-4,y-4+200,x+4,y+4+200);
line(x+4,y-4+200,x-4,y+4+200);
delay(500);
setcolor(6);
circle(x,y+200,10);
setfillstyle(SOLID_FILL,6);
floodfill(x,y+205,6);
setcolor(14);
line(x-4,y-4+200,x+4,y+4+200);
line(x+4,y-4+200,x-4,y+4+200);
delay(500);
}
int Ask_Mouse(int mx,int my)
{
int Square=1000;
int xx=50,yy=50;
if(mx>=x-160&&mx
if(my>=y-160&&my
if(xx!=50&&yy!=50)
{
Square=16*yy+xx;
return Square;
}
if(mx>=x-10&&mx
return 555;
if(mx>=x-260&&mx
return 333;
return 1;
}
void Reset()
{
int i;
for(i=0;i<256;i++) Board[i]=0;
for(i=0;i<3;i++) Board[i]=9;
for(i=13;i<18;i++) Board[i]=9;
for(i=30;i<33;i++) Board[i]=9;
Board[47]=9; Board[208]=9;
for(i=223;i<226;i++) Board[i]=9;
for(i=238;i<243;i++) Board[i]=9;
for(i=253;i<256;i++) Board[i]=9;
Board[103]=1; Board[104]=2;
Board[119]=7; Board[120]=7;
Board[135]=7; Board[136]=7;
Board[151]=2; Board[152]=1;
for(i=0;i<150;i++)
{
allowed_square[i]=0;
source_square[i]=0;
movement_type[i]=0;
}
cleardevice();
}
void Welcome()
{
setcolor(LIGHTBLUE);
settextstyle(GOTHIC_FONT,HORIZ_DIR,5);
outtextxy(x-100,y-210,"TRYSTER");
setcolor(BLUE);
settextstyle(3,HORIZ_DIR,3);
setcolor(YELLOW);
outtextxy(x-40,y+130,"Creator");
setcolor(RED);
outtextxy(x-255,y+180," Suneet Singh 99/CSE/123 CRSCE Murthal");
setcolor(6);
outtextxy(x-105,y-60,"'First Prize Winner'");
outtextxy(x-225,y-10,"N-CODE Predefined Software Competition.");
outtextxy(x-125,y+50,"TRYST 2002, IIT-Delhi");
setcolor(GREEN);
outtextxy(x-255,y+180," - - ");
sleep(1);
getch();
cleardevice();
}
void Who_Play_First()
{
setcolor(4);
settextstyle(DEFAULT_FONT,0,2);
outtextxy(x-115,y-20,"Who plays first ");
outtextxy(x-135,y+20,"Player Computer");
setcolor(14);
outtextxy(x-135,y+20,"P C");
settextstyle(4,0,4);
setcolor(6);
outtextxy(x-70,y-232,"TRYSTER");
settextstyle(DEFAULT_FONT,0,2);
while(1)
{
if(kbhit())
{
ii.h.ah=0;
int86(22,&ii,&oo);
if(oo.h.ah==25)
{
Whoplays_first=PLAYER;
setcolor(4);
outtextxy(x-135,y+20,"P");
delay(400);
setcolor(14);
outtextxy(x-135,y+20,"P");
delay(400);
break;
}
if(oo.h.ah==46)
{
Whoplays_first=COMPUTER;
setcolor(4);
outtextxy(x-135,y+20," C");
delay(400);
setcolor(14);
outtextxy(x-135,y+20," C");
delay(400);
break;
}
}
}
setfillstyle(SOLID_FILL,7);
bar(x-180,y-180,x+180,y+180);
}
void Color_Allotment()
{
if(Whoplays_first==PLAYER)
{
settextstyle(DEFAULT_FONT,0,1);
setcolor(4);
outtextxy(x+190,y+20,"Choose Color...");
outtextxy(x+190,y+50,"Click on the DOT");
while(1)
{
getmousepos(&button,&mousex,&mousey);
if((button&1)==1)
{
hidemouseptr();
while((button&1)==1)
{
getmousepos(&button,&mousex,&mousey);
mousetrap=1;
}
getmousepos(&button,&mousex,&mousey);
reply=Ask_Mouse(mousex,mousey);
if(reply==87||reply==102||reply==153||reply==168)
{
Marker(2);
Draw_Allowed_Dots(0);
Marker(1);
Draw_Allowed_Dots(0);
turn =2;
Computer_Color=1;
Player_Color=2;
break;
}
else if(reply==88||reply==105||reply==150||reply==167)
{
Marker(2);
Draw_Allowed_Dots(0);
Marker(1);
Draw_Allowed_Dots(0);
turn =1;
Computer_Color=2;
Player_Color=1;
break;
}
mousetrap=0;
showmouseptr();
}
}
settextstyle(DEFAULT_FONT,0,1);
setcolor(0);
outtextxy(x+190,y+20,"Choose Color...");
outtextxy(x+190,y+50,"Click on the DOT");
}
else if(Whoplays_first==COMPUTER)
{
settextstyle(DEFAULT_FONT,0,1);
setcolor(4);
outtextxy(x+190,y+20,"Computer'S Color");
outtextxy(x+190,y+50,"Green Black");
setcolor(14);
outtextxy(x+190,y+50,"G B");
while(1){
if(kbhit())
{
ii.h.ah=0;
int86(22,&ii,&oo);
if(oo.h.ah==34)
{
setcolor(4);
outtextxy(x+190,y+50,"G");
delay(400);
setcolor(14);
outtextxy(x+190,y+50,"G");
delay(400);
turn=2;
Computer_Color=2;
Player_Color=1;
break;
}
if(oo.h.ah==48)
{
setcolor(4);
outtextxy(x+278,y+50,"B");
delay(400);
setcolor(14);
outtextxy(x+278,y+50,"B");
delay(400);
turn=1;
Computer_Color=1;
Player_Color=2;
break;
}
}
}
settextstyle(DEFAULT_FONT,0,1);
setcolor(0);
outtextxy(x+190,y+20,"Computer'S Color");
outtextxy(x+190,y+50,"Green Black");
Marker(2);
Draw_Allowed_Dots(0);
Marker(1);
Draw_Allowed_Dots(0);
}
}
Comments