//Game1: Odd & Even
//Game2: Account Crackers
//Game3: Tic Tac Toe
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
enum whoplays{human,machine};
enum cell{empty,full};
enum boolean{false,true};
int deep=0;
class position
{
private:
cell mcell[9];
cell hcell[9];
whoplays player;
public:
position();
boolean iswin();
boolean islegal(int);
void makemove(int);
void setplayer(whoplays);
static void initdisplay();
void display();
int evaluate(int&);
};
position::position()
{
for(int j=0;j<9;j++)
mcell[j]=hcell[j]=empty;
}
boolean position::iswin()
{
cell *ptr;
if(player==human)
ptr=hcell;
else
ptr=mcell;
if((ptr[0] && ptr[1] && ptr[2]) ||
(ptr[3] && ptr[4] && ptr[5]) ||
(ptr[6] && ptr[7] && ptr[8]) ||
(ptr[0] && ptr[3] && ptr[6]) ||
(ptr[1] && ptr[4] && ptr[7]) ||
(ptr[2] && ptr[5] && ptr[8]) ||
(ptr[2] && ptr[4] && ptr[8]) ||
(ptr[2] && ptr[4] && ptr[6]) )
return(true);
else
return(false);
}
boolean position::islegal(int move)
{
if(move>=0 && move<=8 && mcell[move]==empty && hcell[move]==empty)
return(true);
else
return(false);
}
void position::makemove(int move)
{
if(player==human)
hcell[move]=full;
else
mcell[move]=full;
}
void position::setplayer(whoplays p)
{
player=p;
}
void position::initdisplay()
{
const unsigned char block= '\xb2';
void insert(unsigned char,int,int);
int row,col;
clrscr();
for(row=0;row<11;row++)
{
insert(block,5,row);
insert(block,11,row);
}
for(col=0;col<17;col++)
{
insert(block,col,3);
insert(block,col,7);
}
for(int j=0;j<9;j++)
insert((char)(j+'0'),(j%3)*6+4,(j/3)*4);
}
void position::display()
{
void insert(unsigned char,int,int);
int row,col;
for(int j=0;j<9;j++)
{
if(hcell[j])
insert('x',(j%3)*6+2,(j/3)*4+1);
else if(mcell[j])
insert('o',(j%3)*6+2,(j/3)*4+1);
else
insert(' ',(j%3)*6+2,(j/3)*4+1);
}
gotoxy(1,23);
}
void insert(unsigned char ch,int col,int row)
{
gotoxy(col+50+1,row+5+1);
putch(ch);
}
int position::evaluate(int& score)
{
int const winscore=100;
int const drawscore=50;
int returnmove;
position *posptr;
int legalmoves=0;
int totalscore=0;
int highscore=0;
int avgscore;
int score2;
boolean waswin=false;
boolean wasother=false;
++deep;
for(int move=0;move<9;move++)
{
if(islegal(move))
{
if(legalmoves==0)
returnmove=move;
++legalmoves;
posptr=new position;
*posptr=*this;
posptr->makemove(move);
if(deep<3)
posptr->display();
if(posptr->iswin())
{
waswin=true;
highscore=winscore;
totalscore+=winscore;
returnmove=move;
}
else
{
whoplays newp=(player==machine)?human:machine;
posptr->setplayer(newp);
posptr->evaluate(score2);
if(score2==winscore)
waswin=true;
else
wasother=true;
totalscore+=score2;
if(score2>highscore)
{
highscore=score2;
returnmove=move;
}
}
delete posptr;
}
}
if(legalmoves==0)
{
score=drawscore;
--deep;
return(99);
}
else
{
avgscore=totalscore/legalmoves;
if(waswin && wasother)
score=winscore-(winscore-avgscore)/5;
else
score=100-score;
--deep;
return(returnmove);
}
}
void main()
{
int choice1;
choice:clrscr();
cout<<"\n\n\n\n\t\t\t YOU ARE WELCOME IN THIS";
cout<<"\n\n\n\t\t\t\t **************";
cout<<"\n\t\t\t\t <* GAMEPACK* >";
cout<<"\n\t\t\t\t **************";
cout<<"\n\n\n\n\n\n\n\t\t\tSelect yhe game you want to play:";
cout<<"\n\n\n\n\t\t\t\t1. Odds & Evens.";
cout<<"\n\n\t\t\t\t2. Accounts Crackers.";
cout<<"\n\n\t\t\t\t3. Tic Tac Toe.";
cout<<"\n\n\n\n\n\t\t\t ENTER YOUR CHOICE: ";
cin>>choice1;
if(choice1!=1 && choice1!=2 && choice1!=3)
{
cout<<"\n\n\n\t\t\t\t Wrong Choice!";
getch();
goto choice;
}
if(choice1==1)
{ int gd=DETECT,gm;
initgraph(&gd,&gm,"../bgi");
char str1[25],str2[25];
char z;
int c,s,p,choice,n,a,pl1,pl2;
void head1();
void pick(int);
void abc();
abc();
cleardevice();
settextstyle(12,0,0);
head1();
cout<<"\n\n\n\n\n\t\t\t\t\t";
outtextxy(89,134,"Enter your name<Player 1>:");
cin>>str1; cout<<"\n\t\t\t\t\t";
outtextxy(89,164,"Enter your name(Player 2):");
cin>>str2;
for(c=0;c<10;c++)
{
if(str1[c]>90)
str1[c]=str1[c]-32;
if(str2[c]>90)
str2[c]=str2[c]-32;
}
cleardevice();
do
{s=0,p=0;
head1();
cout<<"\n\n\n\n\n\n\n\t\t\t\t\t\t\t ";
outtextxy(140,164,"With how many sticks do u want to start: ");
cin>>choice;
if(choice>5 && choice%2==1)
{
n=choice;
cleardevice();
for(a=0;a<choice;a++)
{
head1();
pick(n);
cout<<"\n\t\t ";
for(c=1;c<=n;c++)
{
if(c%11==0)
cout<<"\n\t\t ";
cout<<" | ";
}
cout<<"\n\n\t"<<str1<<": ";
cin>>pl1;
if(pl1<1 || pl1>3 || pl1>n)
{
choice=0;
cout<<"\n\n\n\t\t\t "<<str1<<" Broke the Rule\n\n\n\n\t\t\t";
cout<<"*Congratulations "<<str2<<"*\n\n\n\t\t\t\t YOU WON!";
break;
}
n=n-pl1;
cleardevice();
cleardevice();
head1();
pick(n);
cout<<"\n\t\t ";
for(c=1;c<=n;c++)
{
if(c%11==0)
cout<<"\n\t\t ";
cout<<" | ";
}
cout<<"\n\n\t"<<str1<<": "<<pl1<<"\t\t";
s=s+pl1;
cout<<"\n\t\t ";
for(c=0;c<s;c++)
{
if(c%11==0)
cout<<"\n\t\t ";
cout<<" | ";
}
getch();
if(n==0)
break;
cout<<"\n\n\t"<<str2<<": ";
cin>>pl2;
if(pl2<1 || pl2>3 || pl2>n)
{
choice=0;
cout<<"\n\n\n\t\t\t "<<str2<<" Broke the Rule\n\n\n\n\t\t\t";
cout<<"*Congratulations "<<str1<<"*\n\n\n\t\t\t\t YOU WON!";
break;
}
n=n-pl2;
cleardevice();
cleardevice();
head1();
pick(n);
cout<<"\n\t\t ";
for(c=1;c<=n;c++)
{
if(c%11==0)
cout<<"\n\t\t ";
cout<<" | ";
}
cout<<"\n\n\t"<<str1<<": "<<pl1<<"\t\t";
cout<<"\n\t\t ";
for(c=0;c<s;c++)
{
if(c%11==0)
cout<<"\n\t\t ";
cout<<" | ";
}
cout<<"\n\n\t"<<str2<<": "<<pl2<<"\t\t";
p=p+pl2;
cout<<"\n\t\t ";
for(c=0;c<p;c++)
{
if(c%11==0)
cout<<"\n\t\t ";
cout<<" | ";
}
getch();
cleardevice();
cleardevice();
head1();
cout<<"\n\n\n\t\t";
if(n<=0)
break;
}
if(choice!=0)
{
cleardevice();
cleardevice();
head1();
cout<<"\n\n\n\t\t";
if(s%2==0)
cout<<"\n\n\n\t\t\t *Congratulations "<<str2<<"*\n\n\n\t\t\t\t YOU WON!";
else
cout<<"\n\n\n\t\t\t *Congratulations "<<str1<<"*\n\n\n\t\t\t\t YOU WON!";
getch();
}
}
else
{
cout<<"\n\n\n\t\t\t This no. is not allowed\n\n\n\t\t\t\t *GAME OVER*";
getch();
}
cleardevice();
cleardevice();
for(c=1;c==1;c++)
{
head1();
cout<<"\n\n\n\t\t";
cout<<"\n\n\n\t\t\tDo you want to play more (y/n):";
z=getche();
if(z!=121 && z!=110 && z!=78 && z!=89)
{
cout<<"\n\n\t\t\t\t Wrong Choice";
getch();
cleardevice();
c=0;
}
}
}
while(z!='n' && z!='N');
}
else if(choice1==2)
{
void ac1();
void ac2();
void ac3();
void head();
clrscr();
int b3,b1,b2,i,draw;
char c,pl1[10],pl2[10];
head();
cout<<"\n\n\n\t\t\t Hi, You are welcome in this GAME.\n\n\n\t\t\t";
cout<<"Rules of the game are given beliw:-\n\n\n\n\t ";
cout<<"1.First of all,You will choose the number of accounts(either 2 or 3)";
cout<<"\t\t with which you will start the game.";
cout<<"\n\n\n\t 2.Then both the players will draw money from the accounts one by one.";
cout<<"\n\n\t 3.Player can pick any amount if he choose ";
cout<<"to draw money from a single \t account.";
cout<<"\n\n\n\t 4.But Player has to draw equal sum of money if ";
cout<<"he choose to draw from \t all the accounts.";
cout<<"\n\n\n\t 5.Player has to draw some money each time his chance comes.";
cout<<"\n\n\n\t 6.That Player will be the WINNER on whose turn ";
cout<<"both the accounts will \t turn to balance zero.";
cout<<"\n\n\n\n\n\n\t\t\t\tPress any key to PLAY!";
getch();
wrong:clrscr();
playmore:head();
int win=0,rule=0,sw=1,z=2,p=0;
cout<<"\n\n\n\n\t\tWith How many accounts do you want to play(2/3):";
cin>>z;
if(z!=2 && z!=3)
{
cout<<"\n\n\n\t\t\t\t Wrong Choice";
getch();
goto wrong;
}
clrscr();
head();
cout<<"\n\n\n\t\t\tEnter Your Name(Player 1):";
cin>>pl1;
cout<<"\n\t\t\tEnter Your Name(Player 2):";
cin>>pl2;
for(i=0;i<10;i++)
{
if(pl1[i]>90)
pl1[i]=pl1[i]-32;
if(pl2[i]>90)
pl2[i]=pl2[i]-32;
}
cout<<"\n\n\n\n\n\n\t\t\t Enter money in account 1:";cin>>b1;
cout<<"\n\n\t\t\t Enter money in account 2:";cin>>b2;
if(z==3)
{
cout<<"\n\n\t\t\t Enter money in account 3:";cin>>b3;
if(b1>b2)
{
if(b1>b3)
p=b1;
else
p=b3;
}
else
{
if(b2>b3)
p=b2;
else
p=b3;
}
}
else
{
if(b1>b2)
p=b1;
else
p=b2;
}
for(int l=0;l<p;l++)
{
run:clrscr();
head();
ac1();
cout<<"\n\n\t\t\t\tAccount Balance->"<<b1<<"\n\n";
for(i=0;i<b1;i++)
{
if(i%20==0)
cout<<"\n\t\t ";
cout<<"$ ";
}
ac2();
cout<<"\n\n\t\t\t\tAccount Balance->"<<b2<<"\n\n";
for(i=0;i<b2;i++)
{
if(i%20==0)
cout<<"\n\t\t ";
cout<<"$ ";
}
if(z==3)
{
ac3();
cout<<"\n\n\t\t\t\tAccount Balance->"<<b3<<"\n\n";
for(i=0;i<b3;i++)
{
if(i%20==0)
cout<<"\n\t\t ";
cout<<"$ ";
}
}
if(sw==1)
cout<<"\n\n\n\n\t\t\t\t "<<pl1;
else
cout<<"\n\n\n\n\t\t\t\t "<<pl2;
cout<<"\n\n\n\t\t From where do you want to draw the money";
if(z==3)
cout<<"\n\n\n A. Account One. B. Account Two. C. Account Three. D. All Acoounts";
else
cout<<"\n\n\n\n\tA. Account One.\t\tB. Account Two.\t\tC. Both Accounts.";
cout<<"\n\n\n\t\t\t Enter Your Choice:";
c=getche();
if(c!='a' && c!='A' && c!='b' && c!='B' && c!='c' && c!='C')
{
if(z==3)
{
if(c=='d' || c=='D')
{
cout<<"\n\n\n\t\t How much money do you want to draw:";
cin>>draw;
if(draw>b1 || draw>b2 || draw>b3 || draw==0)
{
if(sw==1)
rule=1;
else
rule=2;
break;
}
b1=b1-draw;
b2=b2-draw;
b3=b3-draw;
goto choiced;
}
}
cout<<"\n\n\n\t\t\t\t Wrong Choice";
getch();
goto run;
}
if(c=='a' || c=='A')
{
cout<<"\n\n\n\t\t How much money do you want to draw:";
cin>>draw;
if(draw>b1 || draw==0)
{
if(sw==1)
rule=1;
else
rule=2;
break;
}
b1=b1-draw;
}
if(c=='b' || c=='B')
{
cout<<"\n\n\n\t\t How much money do you want to draw:";
cin>>draw;
if(draw>b2 || draw==0)
{
if(sw==1)
rule=1;
else
rule=2;
break;
}
b2=b2-draw;
}
if(c=='c' || c=='C')
{
cout<<"\n\n\n\t\t How much money do you want to draw:";
cin>>draw;
if(z==3)
{
if(draw>b3 || draw==0)
{
if(sw==1)
rule=1;
else
rule=2;
break;
}
b3=b3-draw;
}
else
{
if(draw>b1 || draw>b2)
{
if(sw==1)
rule=1;
else
rule=2;
break;
}
b1=b1-draw;
b2=b2-draw;
}
}
choiced:if(z==3)
{
if(b1==0 && b2==0 && b3==0)
{
if(sw==1)
win=1;
else
win=2;
break;
}
}
else if(b1==0 && b2==0)
{
if(sw==1)
win=1;
else
win=2;
break;
}
if(sw==1)
sw=2;
else
sw=1;
goto run;
}
clrscr();
head();
if(rule==1)
{
cout<<"\n\n\n\n\t\tSorry "<<pl1<<" Sum of money you want to draw is invalid";
cout<<"\n\n\n\t\t\t\t You Lost!";
cout<<"\n\n\n\t\t\t Congratulations "<<pl2<<"\n\n\t\t\t\t $********$\n\t\t\t\t *YOU WON!*\n\t\t\t\t $********$";
}
else if(rule==2)
{
cout<<"\n\n\n\n\t\tSorry "<<pl2<<" Sum of money you want to draw is invalid";
cout<<"\n\n\n\t\t\t\t You Lost!";
cout<<"\n\n\n\t\t\t Congratulations "<<pl1<<"\n\n\t\t\t\t $********$\n\t\t\t\t *YOU WON!*\n\t\t\t\t $********$";
}
else
{
ac1();
cout<<"\n\n\t\t\t\t *BALANCE NIL*";
ac2();
cout<<"\n\n\t\t\t\t *BALANCE NIL*";
if(z==3)
{
ac3();
cout<<"\n\n\t\t\t\t *BALANCE NIL*";
}
}
if(win==1)
{
cout<<"\n\n\n\n\n\t\tCongratulations "<<pl1<<" You cracked both the accounts!";
cout<<"\n\n\t\t\t\t $********$\n\t\t\t\t *YOU WON!*\n\t\t\t\t $********$\n\n\n\t\t\t\t Sorry "<<pl2;
cout<<"\n\n\n\t\t\t\t You Lost!";
}
if(win==2)
{
cout<<"\n\n\n\n\n\t\tCongratulations "<<pl2<<" You cracked both the accounts!";
cout<<"\n\n\t\t\t\t $********$\n\t\t\t\t *YOU WON!*\n\t\t\t\t $********$\n\n\n\t\t\t\t Sorry "<<pl1;
cout<<"\n\n\n\t\t\t\t You Lost!";
}
getch();
ifplay:clrscr();
head();
cout<<"\n\n\n\t\t\tDo you want to play more (y/n):";
c=getche();
if(c!='y' && c!='Y' && c!='n' && c!='N')
{
cout<<"\n\n\n\n\t\t\t\t Wrong Choice";
getch();
goto ifplay;
}
if(c=='y' || c=='Y')
{
clrscr();
goto playmore;
}
}
else if(choice1==3)
{
int move;
int sc;
int movecount=0;
position current;
int cursrow=0;
position::initdisplay();
while(1)
{
current.setplayer(human);
current.display();
gotoxy(1,++cursrow);
cout<<" Make your move (0 to 8): ";
cin>>move;
if(!current.islegal(move))
{
gotoxy(1,++cursrow);
cout<<"Illegal move";
continue;
}
current.makemove(move);
current.display();
if(current.iswin())
{
gotoxy(1,++cursrow);
cout<<"You Win";
getch();goto choose;
}
if(++movecount==5)
{
gotoxy(1,++cursrow);
cout<<"Its a Draw";
getch();goto choose;
}
current.setplayer(machine);
move=current.evaluate(sc);
gotoxy(1,++cursrow);
cout<<"I play at "<<move;
current.makemove(move);
current.display();
if(current.iswin())
{
gotoxy(1,++cursrow);
cout<<"I win ";
getch();goto choose;
}
}
}
choose:if(choice1==1)
cleardevice();
else
clrscr();
cout<<"\n\n\n\t\t\tWould You Like To Start Again: ";
char st=getche();
if(st=='y' || st=='Y')
goto choice;
else if(st=='n' || st=='N')
{ int gd=DETECT,gm;
initgraph(&gd,&gm,"../bgi");
void design(int,int,int);
cleardevice();
setbkcolor(RED);
settextstyle(3,0,3);
delay(1000);
setcolor(BLUE);
design(80,80,30);
delay(1000);outtextxy(155,100,"This GAMEPACK is developed by");
delay(1000);design(550,80,30);
settextstyle(1,0,3);
delay(1000);
setcolor(GREEN);
outtextxy(40,180,"Cpptute.blogspot.com");
int color;
for(int w=0;w<75;w++)
{
design(320,350,w);
delay(10);
setcolor(BLACK);
design(320,350,w);
if(color==15)
color=1;
if(w==74)
color=14;
setcolor(color);
if(w%3==0)
color++;
}
design(320,350,75);
delay(2000);
}
else
goto choose;
}
void ac1()
{
cout<<"\n\n\n\t\t\t\t<$> Account One <$>\n\t\t\t\t ***********";
}
void ac2()
{
cout<<"\n\n\n\n\t\t\t\t<$> Account Two <$>\n\t\t\t\t ***********";
}
void ac3()
{
cout<<"\n\n\n\n\t\t\t\t<$> Account Three <$>\n\t\t\t\t ************";
}
void head()
{
cout<<"\n\t\t\t <$>*******$$********<$>\n\t\t\t ";
cout<<"* ACCOUNT CRACKERS *\n\t\t\t <$>*******$$********<$>";
}
void head1()
{
clrscr();
cleardevice();
setcolor(RED);
outtextxy(245,58,"******************");
outtextxy(245,68,"* ODDS AND EVENS *");
outtextxy(245,78,"******************");
setcolor(YELLOW);
ellipse(319,70,0,360,100,30);
cout<<"\n\n\n\t\t";
}
void pick(int n)
{
cout<<"\n\n\n\n\n\t\t";
cout<<"Pick your Sticks from here. No. of sticks ->"<<n<<"\n";
}
void design(int a,int b,int c)
{
int x[10],y[10];
int x_center = a, y_center = b, rad = c;
int i,j;
for ( i = 0; i < 10; i++ )
{
x[i] = x_center + rad * cos(36*i*3.14159/180);
y[i] = y_center + rad * sin(36*i*3.14159/180);
}
for ( i = 0; i < 10; i++ )
for ( j = 0; j < 10; j++ )
line(x[i],y[i],x[j],y[j]);
}
void abc()
{
clrscr();
cleardevice();
for(int i=0,j=638,k=0;i<319;j>319,i++,j--)
{
setcolor(GREEN);
if(i%3==0)
k++;
sound(i+500);
ellipse(i,70,0,360,k,30);
ellipse(j,70,0,360,k,30);
delay(10);
setcolor(BLACK);
ellipse(i,70,0,360,k,30);
ellipse(j,70,0,360,k,30);
nosound();
}
setcolor(YELLOW);
ellipse(319,70,0,360,100,30);
setcolor(RED);
outtextxy(245,58,"******************");
outtextxy(245,68,"* ODDS AND EVENS *");
outtextxy(245,78,"******************");
setcolor(LIGHTMAGENTA);
design(90,50,25);design(550,50,25);
for(int q=0;q<180;q++,i--)
{
sound(i+500);
settextstyle(5,0,1);
outtextxy(q,108,"Hi, You are welcome in this GAME.");
delay(5);
setcolor(BLACK);
outtextxy(q,108,"Hi, You are welcome in this GAME.");
setcolor(MAGENTA);
nosound();
}
outtextxy(180,108,"Hi, You are welcome in this GAME.");
settextstyle(12,0,0); setcolor(LIGHTCYAN);
outtextxy(172,145,"Rules of the game are given below:-");
outtextxy(100,170,"1. First of all,You will choose with how many sticks do you want");
outtextxy(110,185," to start the game.");
outtextxy(100,205,"2. This no. must be an odd no. greater than 6.");
outtextxy(100,225,"3. Both the Players will pick the sticks one by one until all");
outtextxy(110,240," the sticks will finish.");
outtextxy(100,260,"4. Each Player have to pick at least 1 stick and at most");
outtextxy(110,275," 3 sticks.");
outtextxy(100,295,"5. The Player with odd no. of sticks in the end");
outtextxy(110,310," will be the winner.");
outtextxy(100,330,"6. The Game will be over if any of the above rule is");
outtextxy(110,345," broken by any of the player");
settextstyle(7,0,1);outtextxy(150,400,"Press any button to PLAY!");
getch();
}