这是我和他合作的成果
虽说我只帮他做了判断程序,在优化下子
现在我把这程序公布在网站上,有兴趣的可以看看
有bug尽管提! 程序内很简单,一看就懂
#include <bits/stdc++.h>
using namespace std;
int a[25][25];
int dx[15] = {0, 1, -1, 0, 0, 1, -1, 1, -1};
int dy[15] = {0, 0, 0, 1, -1, -1, 1, 1, -1};
void chess()
{
system("cls");
cout << setw(33) << "Îå×ÓÆå";
cout << endl << " ";
for (int i = 1; i <= 19; i++)
cout << setw(2) << i << " ";
cout << " x×ø±ê" << endl;
for (int i = 1; i <= 19; i++)
{
cout << setw(2) << i;
for (int j = 1; j <= 19; j++)
{
if (a[i][j] == 0) cout << setw(3) << "+";
if (a[i][j] == 1) cout << setw(3) << "¡ö";
if (a[i][j] == 2) cout << setw(3) << "¡õ";
}
cout << endl;
}
cout <<"y"<< endl << "×ø" << endl << "±ê" << endl << endl;
}
bool check(int x, int y)
{
int t = a[x][y];
for (int i = 1; i <= 4; i++)
{
int tx = x, ty = y, ans = 1;
for(int k = 1; k <= 2; k++)
{
int ttx = tx;
int tty = ty;
for (int j = 1; j <= 4; j++)
{
ttx += dx[i * 2 - (2 - k)];
tty += dy[i * 2 - (2 - k)];
if(a[ttx][tty] == t) ans = ans + 1;
else break;
}
}
if(ans == 5) return 1;
}
return 0;
}
int main()
{
string now = "Black";
while (1)
{
int x, y;
chess();
do
{
cout << " Now:" << now << endl << "ÇëÊäÈëx£¬y×ø±ê£º" ;
cin >> y >> x;
}
while(x < 1 || y < 1|| x > 19 || y > 19 || a[x][y] != 0);
if (now == "Black")
{
a[x][y] = 1;
now = "White";
if (check(x, y) == 1)
{
chess();
cout << "Black Win!" << endl;
exit(0);
}
}
else
{
a[x][y] = 2;
now = "Black";
if(check(x, y) == 1)
{
chess();
cout << "White Win" << endl;
exit(0);
}
}
}
return 0;
}