电脑为什么会下象棋? 跟电脑玩象棋为什么电脑能长将而我不能躲

作者&投稿:荀刮 (若有异议请与网页底部的电邮联系)
我是学计算机的,呵呵,其实这个问题很有趣的呢^_^
中国的象棋我还不是很清楚,我目前所知道的最牛的机子名叫【深蓝】,战胜了国际象棋大师【卡斯帕罗夫】,详细资料如下
http://www.wst.net.cn/history/5.11/10.htm
其实,计算机本身是没有只能的,之所以他能够拥有下棋的能力,是因为我们预先教会了他,通过程序语言,实现了我们跟计算机之前的对话,就好像我们告诉他:
如果别人走马,你就走马,如果别人走象,你就走象一样……
在计算机中,是通过程序语言来实现的,格式是
if......then......
else if......then.......
就跟上面的如果怎么样就怎么样是一样的了,这样计算机就懂得在不同情况下如何处理了哦^_^
希望姐姐的解释还比较清晰^_^

【补充来了】^_^
思路1,平均每方每步可有35种走法。50回合。
思路2,棋盘上90个点,各点可走的点。如车可以走到任意一点。
按照思路一的算法 往多了算
一盘棋有50回合,也就是100步,每步有50种变化
一共的变化数就是50的100次方
就算少算一点
一盘棋有20回合,也就是40步,每步10种变化
一共的变化数是10的40次方
这个数也足够大了,就是1后面跟着40个0
【也就是说,别人走了一步以后,你有多少种可能的走法,计算机会去计算,然后择优录取】
给你个算法吧,我们实验课上经常做这些^_^
#include "StdAfx.h"
#include "Calculate.h"
#include "MantisChessThink.h"
#include "string.h"
#include "stdio.h"

/*************************************************************************
把Think重新包装一下,进行坐标变换,希望以后其他人的算法的接口都采用这个函数
这样的编译出来的DLL可以直接替换原来的CChessThinker.dll
timespan是思考的限定时间,以毫秒为单位,时间不同可能导致不同的思考策略。
本程序中的算法没有使用这一变量。
**************************************************************************/
BOOL Calculate(char* map,int timespan,int& x1,int& y1,int& x2,int& y2)
{
//BOOL Thinking(int tmap[11][12],POINT tmanposition[32],int &tside,int &resultman, POINT &resultpoint);
int tmap[11][12];
POINT manpoint[32];
int side=(int)map[0]-48;
int resultman=32;
POINT resultpoint={0,0};

for (int i = 0; i < 11; i++)
{
for (int j = 0; j < 12; j++)
{
tmap[i][j] = 32;
}
}
for (int i = 0; i < 32; i++)
{
manpoint[i].x=0;
manpoint[i].y=0;
}
int length=(int)strlen(map);
int index = 1;
while (index < length)
{
int x =1 + ((int)map[index + 0]-48);//thinking的x从1到9
int y = 10 - ((int)map[index + 1]-48);//thinking的y从10到1
int color = (int)map[index + 2]-48;//0-RED,1-BLAVK
int type = (int)map[index + 3]-48;//0-6

int manIndex=0;
if (color==0)
{
switch (type)
{
case 0:
manIndex=0;
break;
case 1:
if (manpoint[1].x==0) manIndex=1;
else manIndex=2;
break;
case 2:
if (manpoint[3].x==0) manIndex=3;
else manIndex=4;
break;
case 3:
if (manpoint[5].x==0) manIndex=5;
else manIndex=6;
break;
case 4:
if (manpoint[7].x==0) manIndex=7;
else manIndex=8;
break;
case 5:
if (manpoint[9].x==0) manIndex=9;
else manIndex=10;
break;
case 6:
if (manpoint[11].x==0) manIndex=11;
else if (manpoint[12].x==0) manIndex=12;
else if (manpoint[13].x==0) manIndex=13;
else if (manpoint[14].x==0) manIndex=14;
else manIndex=15;
break;
}

}
else
{
switch (type)
{
case 0:
manIndex=16;
break;
case 1:
if (manpoint[17].x==0) manIndex=17;
else manIndex=18;
break;
case 2:
if (manpoint[19].x==0) manIndex=19;
else manIndex=20;
break;
case 3:
if (manpoint[21].x==0) manIndex=21;
else manIndex=22;
break;
case 4:
if (manpoint[23].x==0) manIndex=23;
else manIndex=24;
break;
case 5:
if (manpoint[25].x==0) manIndex=25;
else manIndex=26;
break;
case 6:
if (manpoint[27].x==0) manIndex=27;
else if (manpoint[28].x==0) manIndex=28;
else if (manpoint[29].x==0) manIndex=29;
else if (manpoint[30].x==0) manIndex=30;
else manIndex=31;
break;
}
}

manpoint[manIndex].x=x;
manpoint[manIndex].y=y;
tmap[x][y]=manIndex;

index += 4;
}
//ShowInt(side);
//ShowInt(resultman);
//ShowInt(resultpoint.x);
//ShowInt(resultpoint.y);

BOOL b=Think( tmap,manpoint,side,resultman,resultpoint);

if (b)
{
x1=manpoint[resultman].x-1;
y1=10-manpoint[resultman].y;
x2=resultpoint.x-1;
y2=10-resultpoint.y;
}

return b;

//return FALSE;
}
BOOL test(char* x1)
{
return FALSE;
}
void ShowInt(int i)
{
char buf[256];
sprintf(buf,"%d",i);
MessageBox(NULL,buf,"test",0);
}
void ShowString(char * t)
{
MessageBox(NULL,t,"test",0);
}

/ CChessThink.cpp : 定义 DLL 应用程序的入口点。
//

#include "stdafx.h"

#ifdef _MANAGED
#pragma managed(push, off)
#endif

BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}

#ifdef _MANAGED
#pragma managed(pop)
#endif

Calculate.h
void ShowInt(int i);
void ShowString(char * t);
BOOL Calculate(char* map,int timespan,int& x1,int& y1,int& x2,int& y2);

MantisChessDef.h
const int MW=32,SW=1; //MW-棋子宽度;SW-棋子间隔的一半
const int BWA=MW+SW*2; //BWA-棋格宽度

const int XBW=BWA*9,YBW=BWA*10; //棋盘的长宽

const int MAN=0; //人
const int COM=1; //计算机

const int RED=0; //红方
const int BLACK=1; //黑方

const int RED_K=0; //红帅
const int RED_S=1; //仕
const int RED_X=2; //相
const int RED_M=3; //马
const int RED_J=4; //车
const int RED_P=5; //炮
const int RED_B=6; //兵

const int BLACK_K=7; //黑将
const int BLACK_S=8; //士
const int BLACK_X=9; //象
const int BLACK_M=10; //马
const int BLACK_J=11; //车
const int BLACK_P=12; //炮
const int BLACK_B=13; //卒

//以下是全局函数定义:

//把棋子序号转换为对应图标的序号
const int ManToIcon[33]= {0,1,1,2,2,3,3,4,4,5,5,6,6,6,6,6
,7,8,8,9,9,10,10,11,11,12,12,13,13,13,13,13,-1};

//棋子类型与图标的序号相同
#define ManToType ManToIcon

const int ManToType7[33]= {0,1,1,2,2,3,3,4,4,5,5,6,6,6,6,6
,0,1,1,2,2,3,3,4,4,5,5,6,6,6,6,6,-1};

//随即函数,返回小于n的随机整数
int rnd(const int& n);

//给出棋子序号!!,判断是红是黑
const int SideOfMan[33]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,-1};

const int _defaultmap[11][12]=
{
// [0][1][2][3][4][5][6][7][8][9][10][11]
{32,32,32,32,32,32,32,32,32,32,32,32},//[0]
{32,32,32,32,32,32,32,32,32,32,32,32},//[1]
{32,32,32,32,32,32,32,32,32,32,32,32},//[2]
{32,32,32,32,32,32,32,32,32,32,32,32},//[3]
{32,32,32,32,32,32,32,32,32,32,32,32},//[4]
{32,32,32,32,32,32,32,32,32,32,32,32},//[5]
{32,32,32,32,32,32,32,32,32,32,32,32},//[6]
{32,32,32,32,32,32,32,32,32,32,32,32},//[7]
{32,32,32,32,32,32,32,32,32,32,32,32},//[8]
{32,32,32,32,32,32,32,32,32,32,32,32},//[9]
{32,32,32,32,32,32,32,32,32,32,32,32}//[10]
};

const int FistOfSide[2]={0,16};
const int LastOfSide[2]={15,31};
const int MAXMOVE = 1000;

struct MOVEHISTORY
{
int count;
int man[MAXMOVE];
POINT from[MAXMOVE];
POINT to[MAXMOVE];
int betaken[MAXMOVE];
};

#include "StdAfx.h"
#include "MantisChessDef.h"
#include "MantisChessThink.h"
//-------------下面几项可以调试智能模块---------------------------
#define S_WIDTH 8
#define S_DEPTH 6

// 将 士 象 马 车 炮 兵
const int base[7]= {300,400,300,600, 1000,600,300}; //平均价值
const int range[7]= {0 , 0, 0, 20, 10, 0, 50}; //价值的变动范围

const int contactpercent1=20; //防守的重视程度
const int contactpercent2=25; //进攻的重视程度

/******************************************************************
例:把马设为平均价值200,变动范围±13%应设base[3]=200,range[3]=13
*******************************************************************/
//-----------------------------------------------------------------

const int BV1[7]=//基本价值
{
base[0]-base[0]*range[0]/100,
base[1]-base[1]*range[1]/100,
base[3]-base[2]*range[2]/100,
base[3]-base[3]*range[3]/100,
base[4]-base[4]*range[4]/100,
base[5]-base[5]*range[5]/100,
base[6]-base[6]*range[6]/100
};
const int BV2[7]=//活跃度
{
2*base[0]*range[0]/100/4,
2*base[1]*range[1]/100/4,
2*base[2]*range[2]/100/4,
2*base[3]*range[3]/100/8,
2*base[4]*range[4]/100/17,
2*base[5]*range[5]/100/17,
0,
};

const int BV3[5]=//兵在不同位置的价值附加
{
0*2*base[6]*range[6]/100/4,
1*2*base[6]*range[6]/100/4,
2*2*base[6]*range[6]/100/4,
3*2*base[6]*range[6]/100/4,
4*2*base[6]*range[6]/100/4,
};

#define NORED(i,j) (SideOfMan[tmap[i][j]]!=0)
#define NOBLACK(i,j) (SideOfMan[tmap[i][j]]!=1)
#define NOMAN(i,j) (tmap[i][j]==32)

//兵卒在不同位置的价值,数字越大价值越高
const int ManBPlus[2][12][11]=
{
{
{ 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, 3, 4, 4, 4, 3, 2, 1, 0},
{ 0, 1, 2, 3, 4, 4, 4, 3, 2, 1, 0},
{ 0, 1, 2, 3, 3, 3, 3, 3, 2, 1, 0},
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{ 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0},
{ 0, 0, 0, 0, 0, 2, 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, 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, 2, 0, 0, 0, 0, 0},
{ 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0},
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{ 0, 1, 2, 3, 3, 3, 3, 3, 2, 1, 0},
{ 0, 1, 2, 3, 4, 4, 4, 3, 2, 1, 0},
{ 0, 1, 2, 3, 4, 4, 4, 3, 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}
}
};

//-------------------------------------------
static void ContactV(int tmap[11][12],POINT tmanposition[32],int &tside,int activity[32],int contact[32][32]);

/******************************************************************
Mantis_QuickSort:对走法列表进行快速排序

参数:
A: 关键值
chessman: 待排序的棋子列表
targetpoint: 待排序的目标点列表
low,high: QuickSort上下限

返回值: 无
******************************************************************/
void Mantis_QuickSort(int A[],int chessman[],POINT targetpoint[],int low,int high)
{
int pivot;
int pivot_man;
POINT pivot_point;
int scanUp,scanDown;
int mid,k;
POINT point;
if(high-low<=0)
{
return;
}
else
{
if(high-low==1)
{
if(A[high]>A[low])
{
k=A[high];
A[high]=A[low];
A[low]=k;
k=chessman[high];
chessman[high]=chessman[low];
chessman[low]=k;
point=targetpoint[high];
targetpoint[high]=targetpoint[low];
targetpoint[low]=point;
return;
}
}
}
mid=(low +high)/2;
pivot=A[mid];
pivot_man=chessman[mid];
pivot_point=targetpoint[mid];
k=A[mid];
A[mid]=A[low];
A[low]=k;
k=chessman[mid];
chessman[mid]=chessman[low];
chessman[low]=k;
point=targetpoint[mid];
targetpoint[mid]=targetpoint[low];
targetpoint[low]=point;
scanUp =low+1;
scanDown = high;
do{
while(scanUp<=scanDown && A[scanUp]>=pivot)
scanUp++;
while(pivot>A[scanDown])
scanDown--;
if(scanUp<scanDown)
{
k=A[scanUp];
A[scanUp]=A[scanDown];
A[scanDown]=k;
k=chessman[scanUp];
chessman[scanUp]=chessman[scanDown];
chessman[scanDown]=k;
point=targetpoint[scanUp];
targetpoint[scanUp]=targetpoint[scanDown];
targetpoint[scanDown]=point;
}
}while(scanUp<scanDown);
A[low]=A[scanDown];
A[scanDown]=pivot;
chessman[low]=chessman[scanDown];
chessman[scanDown]=pivot_man;
targetpoint[low]=targetpoint[scanDown];
targetpoint[scanDown]=pivot_point;

if(low<scanDown-1)
Mantis_QuickSort(A,chessman,targetpoint,low,scanDown-1);
if(scanDown+1<high)
Mantis_QuickSort(A,chessman,targetpoint,scanDown+1,high);
}

/******************************************************************
Value: 估值函数

参数:
tmap: 各棋位状态
tmanposition: 32棋子的坐标
tside: 轮到哪一放走

返回值: 局面的价值
******************************************************************/
int Value(int tmap[11][12],POINT tmanposition[32],int &tside)
{
static int k;
static int ManExtValue[32];
static int ManBaseValue[32];
static int ManContact[32][32];
static int BeAteCount[32];
static BOOL OwnSee[32];
ZeroMemory(ManContact,sizeof(int)*32*32);
ZeroMemory(ManBaseValue,sizeof(int)*32);
ZeroMemory(ManExtValue,sizeof(int)*32);
ZeroMemory(BeAteCount,sizeof(int)*32);
ZeroMemory(OwnSee,sizeof(int)*32);
int maxvalue=0;
int i,j;
ContactV(tmap,tmanposition,tside,ManBaseValue,ManContact);
//己方将军
for(i=FistOfSide[tside];i<=LastOfSide[tside];i++)
{
if(ManContact[i][FistOfSide[!tside]])
{
maxvalue=9700;
return maxvalue;
}
}
for(i=0;i<32;i++)
{
k=ManToType7[i];
ManBaseValue[i]=BV1[k]+ManBaseValue[i]*BV2[k];
switch(k)
{
case 6: ManBaseValue[i]+=BV3[ ManBPlus[SideOfMan[i]][tmanposition[i].y][tmanposition[i].x] ];
break;
}
}
for(i=0;i<32;i++)
{
for(j=0;j<32;j++)
{
if(ManContact[i][j])
{
if(SideOfMan[i]==SideOfMan[j])
{
BeAteCount[j]++;
if(!OwnSee[j])
{
ManExtValue[i]+=ManBaseValue[j]*contactpercent1/100;//己方
OwnSee[j]=TRUE;
}
}
else
{
ManExtValue[i]+=ManBaseValue[j]*contactpercent2/100;//对方
BeAteCount[j]--;
}
}
}
}
for(i=FistOfSide[tside];i<=LastOfSide[tside];i++)
{
if(tmanposition[i].x)maxvalue+=ManBaseValue[i]+ManExtValue[i];
}
static BOOL flag;
flag=FALSE;k=32;
for(i=FistOfSide[!tside];i<=LastOfSide[!tside];i++)
{
if(tmanposition[i].x)maxvalue-=ManBaseValue[i]+ManExtValue[i];
//对方将军
if(ManContact[i][FistOfSide[tside]])
{
flag=TRUE;
k=i;
break;
}
}
if(flag&&BeAteCount[k]>=0)//被将,所将军的棋子不能被吃掉
{
j=0;
for(i=FistOfSide[tside];i<=LastOfSide[tside];i++)
{
if(BeAteCount[i]<0 && ManBaseValue[i]>j)
j=ManBaseValue[i];
}
maxvalue -=j;
}
else
{
j=0;
for(i=FistOfSide[!tside];i<=LastOfSide[!tside];i++)
{
if(BeAteCount[i]<0 && ManBaseValue[i]>j)
j=ManBaseValue[i];
}
maxvalue +=j;
}
return maxvalue;
}

/******************************************************************
EnumList: 列出所有走法

参数:
tmap: 各棋位状态
tmanposition: 32棋子的坐标
tside: 轮到哪一放走
chessman: 指向棋子列表的指针(存放结果)
move: 指向棋子所走到位置的指针,与chessman一起组成走法列表
(存放结果)
count: 走法的总数(存放结果)

返回值: “照相”返回TRUE,否则返回FALSE
******************************************************************/
BOOL EnumList(int tmap[11][12],POINT tmanposition[32],int &tside,int *chessman,POINT *move,int &count)
{
#define ADD(man,tx,ty) {chessman[count]=man;move[count].x=tx;move[count].y=ty;count++;if(tmap[tx][ty]==FistOfSide[!tside])goto _NOKING;}
static int i,j,n,x,y;
static BOOL flag;
count=0;
for(n=FistOfSide[tside];n<=LastOfSide[tside];n++)
{
x=tmanposition[n].x;
if(!x)continue;
y=tmanposition[n].y;
switch(n)
{
case 0:
if(tmanposition[0].x==tmanposition[16].x) //将帅在同一列
{
flag=FALSE;
for(j=tmanposition[16].y+1;j<tmanposition[0].y;j++)
{
if(tmap[x][j]!=32)
{
flag=TRUE;
break;
}
}
if (!flag)
{
ADD(0,x,tmanposition[16].y);
}
}
j=y+1;if(j<=10 && NORED(x,j)) ADD(0,x,j)
j=y-1;if(j>=8 && NORED(x,j)) ADD(0,x,j)
i=x+1;if(i<=6 && NORED(i,y)) ADD(0,i,y)
i=x-1;if(i>=4 && NORED(i,y)) ADD(0,i,y)
break;
case 16:
if(tmanposition[0].x==tmanposition[16].x) //将帅在同一列
{
flag=FALSE;
for(j=tmanposition[16].y+1;j<tmanposition[0].y;j++)
{
if(tmap[x][j]!=32)
{
flag=TRUE;
break;
}
}
if (!flag)
{
ADD(16,x,tmanposition[0].y);
}
}
j=y+1;if(j<=3 && NOBLACK(x,j)) ADD(16,x,j)
j=y-1;if(j>=1 && NOBLACK(x,j)) ADD(16,x,j)
i=x+1;if(i<=6 && NOBLACK(i,y)) ADD(16,i,y)
i=x-1;if(i>=4 && NOBLACK(i,y)) ADD(16,i,y)
break;
case 1:
case 2:
i=x+1;j=y+1;if(i<=6 && j<=10 && NORED(i,j)) ADD(n,i,j)
i=x+1;j=y-1;if(i<=6 && j>=8 && NORED(i,j)) ADD(n,i,j)
i=x-1;j=y+1;if(i>=4 && j<=10 && NORED(i,j)) ADD(n,i,j)
i=x-1;j=y-1;if(i>=4 && j>=8 && NORED(i,j)) ADD(n,i,j)
break;
case 17:
case 18:
i=x+1;j=y+1;if(i<=6 && j<=3 && NOBLACK(i,j)) ADD(n,i,j)
i=x+1;j=y-1;if(i<=6 && j>=1 && NOBLACK(i,j)) ADD(n,i,j)
i=x-1;j=y+1;if(i>=4 && j<=3 && NOBLACK(i,j)) ADD(n,i,j)
i=x-1;j=y-1;if(i>=4 && j>=1 && NOBLACK(i,j)) ADD(n,i,j)
break;
case 3:
case 4:
i=x+2;j=y+2;if(i<=9 && j<=10 && NORED(i,j)) if(NOMAN(x+1,y+1)) ADD(n,i,j)
i=x+2;j=y-2;if(i<=9 && j>=6 && NORED(i,j)) if(NOMAN(x+1,y-1)) ADD(n,i,j)
i=x-2;j=y+2;if(i>=1 && j<=10 && NORED(i,j)) if(NOMAN(x-1,y+1)) ADD(n,i,j)
i=x-2;j=y-2;if(i>=1 && j>=6 && NORED(i,j)) if(NOMAN(x-1,y-1)) ADD(n,i,j)
break;
case 19:
case 20:
i=x+2;j=y+2;if(i<=9 && j<=5 && NOBLACK(i,j)) if(NOMAN(x+1,y+1)) ADD(n,i,j)
i=x+2;j=y-2;if(i<=9 && j>=1 && NOBLACK(i,j)) if(NOMAN(x+1,y-1)) ADD(n,i,j)
i=x-2;j=y+2;if(i>=1 && j<=5 && NOBLACK(i,j)) if(NOMAN(x-1,y+1)) ADD(n,i,j)
i=x-2;j=y-2;if(i>=1 && j>=1 && NOBLACK(i,j)) if(NOMAN(x-1,y-1)) ADD(n,i,j)
break;
case 5:
case 6:
i=x+1;
if(NOMAN(i,y))
{
i=x+2;j=y+1;if(i<=9 && j<=10 && NORED(i,j)) ADD(n,i,j)
i=x+2;j=y-1;if(i<=9 && j>=1 && NORED(i,j)) ADD(n,i,j)
}
i=x-1;
if(NOMAN(i,y))
{
i=x-2;j=y+1;if(i>=1 && j<=10 && NORED(i,j)) ADD(n,i,j)
i=x-2;j=y-1;if(i>=1 && j>=1 && NORED(i,j)) ADD(n,i,j)
}
j=y+1;
if(NOMAN(x,j))
{
i=x+1;j=y+2;if(i<=9 && j<=10 && NORED(i,j)) ADD(n,i,j)
i=x-1;j=y+2;if(i>=1 && j<=10 && NORED(i,j)) ADD(n,i,j)
}
j=y-1;
if(NOMAN(x,j))
{
i=x+1;j=y-2;if(i<=9 && j>=1 && NORED(i,j)) ADD(n,i,j)
i=x-1;j=y-2;if(i>=1 && j>=1 && NORED(i,j)) ADD(n,i,j)
}
break;
case 21:
case 22:
i=x+1;
if(NOMAN(i,y))
{
i=x+2;j=y+1;if(i<=9 && j<=10 && NOBLACK(i,j)) ADD(n,i,j)
i=x+2;j=y-1;if(i<=9 && j>=1 && NOBLACK(i,j)) ADD(n,i,j)
}
i=x-1;
if(NOMAN(i,y))
{
i=x-2;j=y+1;if(i>=1 && j<=10 && NOBLACK(i,j)) ADD(n,i,j)
i=x-2;j=y-1;if(i>=1 && j>=1 && NOBLACK(i,j)) ADD(n,i,j)
}
j=y+1;
if(NOMAN(x,j))
{
i=x+1;j=y+2;if(i<=9 && j<=10 && NOBLACK(i,j)) ADD(n,i,j)
i=x-1;j=y+2;if(i>=1 && j<=10 && NOBLACK(i,j)) ADD(n,i,j)
}
j=y-1;
if(NOMAN(x,j))
{
i=x+1;j=y-2;if(i<=9 && j>=1 && NOBLACK(i,j)) ADD(n,i,j)
i=x-1;j=y-2;if(i>=1 && j>=1 && NOBLACK(i,j)) ADD(n,i,j)
}
break;

case 7:
case 8:
i=x+1;
while(i<=9)
{
if (NOMAN(i,y)) ADD(n,i,y)
else
{
if(NORED(i,y)) ADD(n,i,y)
break;
}
i++;
}
i=x-1;
while(i>=1)
{
if (NOMAN(i,y)) ADD(n,i,y)
else
{
if(NORED(i,y)) ADD(n,i,y)
break;
}
i--;
}
j=y+1;
while(j<=10)
{
if (NOMAN(x,j)) ADD(n,x,j)
else
{
if(NORED(x,j)) ADD(n,x,j)
break;
}
j++;
}
j=y-1;
while(j>=1)
{
if (NOMAN(x,j)) ADD(n,x,j)
else
{
if(NORED(x,j)) ADD(n,x,j)
break;
}
j--;
}
break;
case 23:
case 24:
i=x+1;
while(i<=9)
{
if (NOMAN(i,y)) ADD(n,i,y)
else
{
if(NOBLACK(i,y)) ADD(n,i,y)
break;
}
i++;
}
i=x-1;
while(i>=1)
{
if (NOMAN(i,y)) ADD(n,i,y)
else
{
if(NOBLACK(i,y)) ADD(n,i,y)
break;
}
i--;
}
j=y+1;
while(j<=10)
{
if (NOMAN(x,j)) ADD(n,x,j)
else
{
if(NOBLACK(x,j)) ADD(n,x,j)
break;
}
j++;
}
j=y-1;
while(j>=1)
{
if (NOMAN(x,j)) ADD(n,x,j)
else
{
if(NOBLACK(x,j)) ADD(n,x,j)
break;
}
j--;
}
break;
case 9:
case 10:
i=x+1;flag=FALSE;
while(i<=9)
{
if(NOMAN(i,y))
{
if(!flag) ADD(n,i,y)
}
else
{
if(!flag)flag=TRUE;
else
{
if(NORED(i,y)) ADD(n,i,y)
break;
}
}
i++;
}

i=x-1;flag=FALSE;
while(i>=1)
{
if(NOMAN(i,y))
{
if(!flag) ADD(n,i,y)
}
else
{
if(!flag)flag=TRUE;
else
{
if(NORED(i,y)) ADD(n,i,y)
break;
}
}
i--;
}

j=y+1;flag=FALSE;
while(j<=10)
{
if(NOMAN(x,j))
{
if(!flag) ADD(n,x,j)
【我是学c++的】呵呵,加了注释,你应该能明白一点^_^

把一写套路输入进去了 电脑就按套路下棋

所以电脑很容易 只要赢一次 电脑的路线就很明了

电脑下棋其实很简单,就是不断的计算路数,从这些路数中选择对自己最有利的路数。总之,电脑只会做人们已经能解决的问题。它的强项就是能重复做事情而不会感到烦。

这是因为程序里面保存有棋谱
棋谱里面记录有象棋的走法,举个例子,只要你走车,可能它就会走马,
有多个棋谱,交替使用的

我感觉就是编程的自己搞的
凭电脑超强的记忆集百家之长
所以对付他们最好的办法就是出其不意

电脑是人做的为什么电脑下象棋比人历害?~

这个是集合了多人的智慧,并且基本上保证不犯错误。
电脑的计算速度人脑也比不上。

一般大部分人下棋都是按规矩下,和电脑差不多,和人下应该也不能,总要有人退一步,下棋就是娱乐,开心就好。

下象棋能同时开发左右脑吗??
答:左右脑的分工,使左脑抽象思维的功能较发达,而右脑形象思维功能较发达,右脑在大脑思维中起着独特的作用。下棋是锻炼右脑类型识别能力的好办法。孩子在下围棋或象棋时,其侧重点不是思谋招数,而是要记住棋盘上那星罗棋布、犬...

象棋竟是属于体育项目,下象棋对身体有什么好处吗?
答:主要流行于华人及汉字文化圈的国家,象棋是中国正式开展的78个体育运动项目之一,2014年成为首届世界智力运动会的正式比赛项目之一。对阵双方完全是在平等的情况下调兵遣将、逐鹿沙场的,最后胜利的归属偶然性较小。在玩棋牌能...

长期下象棋对大脑的影响是什么?
答:长时间下棋头会晕。下象棋能提高少儿的智力和耐力,我们所说的智力和耐力是指学生能自我提出问题,发现问题,分析问题,直到最终解决问题的能力。而下象棋正好适应了这个过程。因此可以说象棋是智慧的体操。下象棋能提高少年儿童...

长期下象棋对大脑的影响是什么?
答:长期下象棋对大脑的影响是有助于培养智力,培养思考能力,但是大脑和人体的其他器官一样,同样需要休息。所以建议下棋后多做体能锻炼,是全身的血液循环。这就是脑力劳动和体力劳动相结合,最为科学的锻炼。下象棋的好处 1、...

下象棋有什么好处?
答:通过对弈,学会正确面对失败,增强承受挫折的能力。七、培养良好的心态 可以培养胜不骄、败不馁的良好心态,让人学会自控。八、培养竞争意识 通过对弈,尤其是比赛,可以培养竞争意识。参考资料来源:百度百科-象棋 ...

是不是会走象棋的人智力都很好
答:棋友,你好!对于你的问题,可以作如下解释:俗话说:“聪明棋子顺畅牌”。下棋是斗智力的游戏,打牌则靠手气的成份比较大。会走象棋的人智力都很好,这种说法并不成立。因为学会下象棋是很容易的事情,但要把棋下好,要...

经常下象棋对大脑有没有好处?
答:经常下象棋对大脑有好处。由于人的右脑主管创造,毫无疑问,多用右脑有助开发创造能力。尤其是国际象棋还有助加强独特性。一项对7到9年级学生为期4年的研究表明,让学生们一周一次使用电脑或从事其他活动,经过32周以后,看...

下象棋水平和智力有关吗?象棋高手很聪明吗?
答:很多人不清楚“聪明”的概念,我们一般认为的“聪明”,就是IQ比较高。其实真“聪明”,是IQ+大量知识积累,少了知识积累,IQ再高也不聪明。象棋高手不一定就很有知识,任何人玩棋玩的多了自然水平不差。想要百尺竿头再...

现在的象棋软件怎么都是给电脑下棋?
答:现在的象棋软件都是给电脑下棋的原因如下。1、象棋软件中选的是人机对战,对方就都会是电脑自动操作。2、象棋软件中只有人机对战,没有好友对战选项,就只能和电脑对战。3、在象棋软件中匹配时线上人数少,会匹配到电脑。

不会下象棋的人是不是很傻?
答:不会下棋的人就是不傻,也是小算盘,有的人不会下棋,但精于计算。还处处不吃一点亏,其实这是灵中见傻。而会下棋的人,是大算盘。局部可以吃亏,却整体上赢得胜利。计算和算计的关系是计算为细,算计为粗,计算为急功...