#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#include<dos.h>
#include<windows.h>
using namespace std;
int x,y,Step=0;
bool flag=0;
int Flag=1;
char Switch;
char map[16][16][3]={
{"庚","房","房","房","房","房","房","房","房","房","房","房","房","房","房","庖"},
{"念","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","怕"},
{"念","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","怕"},
{"念","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","怕"},
{"念","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","怕"},
{"念","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","怕"},
{"念","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","怕"},
{"念","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","怕"},
{"念","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","怕"},
{"念","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","怕"},
{"念","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","怕"},
{"念","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","怕"},
{"念","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","怕"},
{"念","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","怕"},
{"念","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","拈","怕"},
{"弩","拂","拂","拂","拂","拂","拂","拂","拂","拂","拂","拂","拂","拂","拂","彼"}};
char copymap[16][16][3];
float Computer[16][16][4];
float Player[16][16][4];
int Table[16][16];
int Showboard(),Play(),Interface(),unitboard(),judgewin(),Per_Com(),ComPlay(),unitdata(),unitboard();
int deuce(),See(),Recoverboard();
bool legal(),Overflow();
int Interface()
{
char a;
cout << "\n\n CHESS 5 GAMES!\n \t\t岸岸岸岸岸岸岸岸岸岸\n 秶釬�芄熔枒Ж洷�200542095ㄘ\n\t\t岸岸岸岸岸岸岸岸岸岸岸岸岸岸岸岸 \n";
cout << " ‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵" << endl;
cout << " ~~ ~~" << endl;
cout << " ~~ 1ㄩTwo Person Games ~~" << endl;
cout << " ~~ ㄗ�侒侀婭膛� ~~" << endl;
cout << " ~~ ~~" << endl;
cout << " ~~ 2ㄩPerson Vs Computer ~~" << endl;
cout << " ~~ ㄗ�侄�湮桵ㄘ ~~" << endl;
cout << " ~~ ~~" << endl;
cout << " ~~ 3: To be Spectator ~~" << endl;
cout << " ~~ ㄗ夤笲耀宒ㄘ ~~" << endl;
cout << " ~~ ~~" << endl;
cout << " ~~ 4: Exit ~~" << endl;
cout << " ~~ ㄗ豖堤ㄘ ~~" << endl;
cout << " ~~ ~~" << endl;
cout << " ‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵‵" << endl;
cout << "\n Please select(③恁寁):";
cin >> a;
if(a=='1') Play();
else if(a=='3')
{
unitdata();
See();
}
else if(a=='4')
{
cout << "\n\nThank you for your using this soft!ㄗ郅郅妏蚚ㄐㄘ\n";
cout << "Please Enter anykeys to exit!";
getch();
return 0;
}
else
{
Step=0;
cout << "If you want to go first ,please enter 1. Or not enter any other key.";
cin >> a;
if(a!='1') Flag=1;
else Flag=0;
unitdata();
Per_Com();
}
}
int unitdata()
{
for(int i=0;i<16;i++)
for(int j=0;j<16;j++)
Table[i][j]=0;
for(int i=0;i<16;i++)
for(int j=0;j<16;j++)
for(int k=0;k<4;k++)
{
Computer[i][j][k]=0;
Player[i][j][k]=0;
}
}
int deuce()
{
for(int i=0;i<16;i++)
for(int j=0;j<16;j++)
if(Table[i][j]==0) return 0;
return 1;
}
int Recoverboard()
{
Step=0;
for(int i=0;i<16;i++)
for(int j=0;j<16;j++)
{
map[i][j][0]=copymap[i][j][0];
map[i][j][1]=copymap[i][j][1];
}
}
int CopyB()
{
for(int i=0;i<16;i++)
for(int j=0;j<16;j++)
{
copymap[i][j][0]=map[i][j][0];
copymap[i][j][1]=map[i][j][1];
}
}
int See()
{
char a;
cout << " \n\t蚕衾奀潔衄癹ㄐ\n\t淏婓膘扢笢......\n\t岆瘁殿隙翋賜醱ˋ(y/n):";
cin >> a;
if(a=='n') return 0;
else Interface();
}
int Per_Com()
{
unitboard();
//Step++;
Showboard();
ComPlay();
while(cin >> x >> y)
{
if(x==0&&y==0)
{
Recoverboard();
Interface();
break;
}
if(Overflow()) continue;
if(!legal())
{
cout << "森弇离眒衄赽ㄐ③笭陔怀�諴�";
continue;
}
x--;y--;
map[x][y][0]=-95;
map[x][y][1]=-15;
Step++;
Showboard();
flag=0;
if(judgewin())
{
cout << "You win! Again?(y/n)" ;
break;
}
if(deuce())
{
cout << "You are equal to Computer! Again?(y/n)";
break;
}
cout << endl;
Table[x][y]=1;
int result=ComPlay();
if(result==2)
{
cout << "You lose! Again?(y/n)";
break;
}
if(result==3)
{
cout << "You are equal to Computer! Again?(y/n)";
break;
}
}
cin >> Switch;
if(Switch!='n')
Interface();
return 1;
}
int ComPlay()
{//�佴少Ь嗛蒴�
int cx=7,cy=8;
if(Flag==1)
{//computer珂軗
cx=rand()%5+4;
cy=rand()%5+4;
map[cx][cy][0]=-95;
map[cx][cy][1]=-16;
Showboard();
cout << "Your turns(Good luck!):";
Table[cx][cy]=2;
Flag=7;
return 7;
}
if(Flag==0)
{ //�冾�軗
cout << "Your turns(Good luck!):";
Flag=8;
return 8;
}
float log=0;
if(Flag==7)
{
for(int i=0;i<16;i++)
for(int j=0;j<16;j++)
{
if(Table[i][j]==0)
{
int k,t;
log=0;
for(k=j+1;Table[i][k]==2&&k<16;k++)
log++;
if(k==16) log-=0.5;
else if(Table[i][k]==1) log-=0.5;
for(k=j-1;Table[i][k]==2&&k>=0;k--)
log++;
if(k==-1) log-=0.5;
else if(Table[i][k]==1) log-=0.5;
Computer[i][j][0]=log;
if(Computer[i][j][0]==2.5) log+=0.5;
for(k=i+1;Table[k][j]==2&&k<16;k++)
log++;
if(k==16) log-=0.5;
else if(Table[k][j]==1) log-=0.5;
for(k=i-1;Table[k][j]==2&&k>=0;k--)
log++;
if(k==16) log-=0.5;
else if(Table[k][j]==1) log-=0.5;
Computer[i][j][1]=log;
if(Computer[i][j][1]==2.5) log+=0.5;
log=0;
for(k=i-1,t=j-1;Table[k][t]==2&&k>=0&&t>=0;k--,t--)
log++;
if(k==-1||t==-1) log-=0.5;
else if(Table[k][t]==1) log-=0.5;
for(k=i+1,t=j+1;Table[k][t]==2&&k<16&&t<16;k++,t++)
log++;
if(k==16||t==16) log-=0.5;
else if(Table[k][t]==1) log-=0.5;
Computer[i][j][2]=log;
if(Computer[i][j][2]==2.5) log+=0.5;
log=0;
for(k=i-1,t=j+1;Table[k][t]==2&&k>=0&&t<16;k--,t++)
log++;
if(k==-1||t==16) log-=0.5;
else if(Table[k][t]==1) log-=0.5;
for(k=i+1,t=j-1;Table[k][t]==2&&t>=0&&k<16;k++,t--)
log++;
if(k==16||t==-1) log-=0.5;
else if(Table[k][t]==1) log-=0.5;
Computer[i][j][3]=log;
if(Computer[i][j][3]==2.5) log+=0.5;
log=0;
for(k=j+1;Table[i][k]==1&&k<16;k++)
log++;
if(k==16) log-=0.5;
else if(Table[i][k]==2) log-=0.5;
for(k=j-1;Table[i][k]==1&&k>=0;k--)
log++;
if(k==-1) log-=0.5;
else if(Table[i][k]==2) log-=0.5;
Player[i][j][0]=log;
log=0;
for(k=i+1;Table[k][j]==1&&k<16;k++)
log++;
if(k==16) log-=0.5;
else if(Table[k][j]==2) log-=0.5;
for(k=i-1;Table[k][j]==1&&k>=0;k--)
log++;
if(k==-1) log-=0.5;
else if(Table[k][j]==2) log-=0.5;
Player[i][j][1]=log;
log=0;
for(k=i-1,t=j-1;Table[k][t]==1&&k>=0&&t>=0;k--,t--)
log++;
if(k==-1||t==-1) log-=0.5;
else if(Table[k][t]==2) log-=0.5;
for(k=i+1,t=j+1;Table[k][t]==1&&k<16&&t<16;k++,t++)
log++;