说明1:如果你用VS,可能会编译不过。建议改用codeblocks或者vc++。
说明2:你可以直接点击屏幕落子。
说明3:AI采用防守优先的方法。所以当你看到AI已经赢了却不这么走的情况,千万别惊讶~~它防守可是很不错的。。
说明4:这个游戏,我走了5盘只赢了3盘。。。。。
#include <iostream>
#include <windows.h>
#include <cstring>
#include <cstdlib>
using namespace std;
/*** 光标定位 ***/
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE),hin=GetStdHandle(STD_INPUT_HANDLE);
COORD coord,pos;
void locate(int x,int y)
{
coord.X=y;
coord.Y=x;
SetConsoleCursorPosition(hout,coord);
};
/*** 隐藏光标 ***/
void hide()
{
CONSOLE_CURSOR_INFO cursor_info={1,0};
SetConsoleCursorInfo(hout, &cursor_info);
}
INPUT_RECORD mouseRec;
DWORD res;
struct win_list
{
bool is_able;
int x[5],y[5];
bool is_used[5];
};
int len,sum;
int chess[20][20],scoreC[20][20],scoreP[20][20];
int last_x,last_y;
win_list computer[2000],person[2000];
/***** 数据初始化,将所有可能获胜的情况录入 ***/
void init()
{
int i,j,k;
sum=0;
memset(chess,0,sizeof(chess));
for (i=0;i<=len-1;i++)
{
for (j=0;j<=len-5;j++)
{
computer[sum+(len-4)*i+j].is_able=true;
for (k=0;k<=4;k++)
{
computer[sum+(len-4)*i+j].is_used[k]=false;
computer[sum+(len-4)*i+j].x[k]=i;
computer[sum+(len-4)*i+j].y[k]=j+k;
}
}
}
sum+=(len-4)*len;
for (i=0;i<=len-5;i++)
{
for (j=0;j<=len-1;j++)
{
computer[sum+len*i+j].is_able=true;
for (k=0;k<=4;k++)
{
computer[sum+len*i+j].is_used[k]=false;
computer[sum+len*i+j].x[k]=i+k;
computer[sum+len*i+j].y[k]=j;
}
}
}
sum+=(len-4)*len;
for (i=0;i<=len-5;i++)
{
for (j=0;j<=len-5;j++)
{
computer[sum+(len-4)*i+j].is_able=true;
for (k=0;k<=4;k++)
{
computer[sum+(len-4)*i+j].is_used[k]=false;