package com.marko;
import java.util.Random;
public class Thinker extends Thread implements ChessDefine{
int BV1[]=new int[7];
int BV2[]=new int[7];
int BV3[]=new int[5];
// 卒在不同位置的价值
public final static int BA[][][]=
{
{
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 2, 2, 3, 4, 4, 4, 3, 2, 2, 0},
{ 0, 2, 2, 3, 4, 4, 4, 3, 2, 2, 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, 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, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{ 0, 1, 2, 3, 3, 3, 3, 3, 2, 1, 0},
{ 0, 2, 2, 3, 4, 4, 4, 3, 2, 2, 0},
{ 0, 2, 2, 3, 4, 4, 4, 3, 2, 2, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
}
};
private int m_nLevel;
boolean m_bThinking;
boolean m_bThinkOver;
private Move m_moveResult;
private Face m_FaceToThink;
// movelists:
int tman[][]=new int[6][125];
int ttox[][]=new int[6][125];
int ttoy[][]=new int[6][125];
int tcount[] =new int[6];
// face
int tmanx[]=new int[32] ;
int tmany[]=new int[32];
boolean tside;
// map
int tmap[][]=new int[11][12];
//
int tlevel,tdeep;
// 只在enumlist中调用
int lman,ltox,ltoy;
;
int v1[]=new int[32];
int v2[][]=new int[32][32];
int v3[]=new int[32];
int v4[]=new int[32];
public final boolean NORED(int i,int j) {
if(SideOfMan[tmap[i][j]]!=0){
return true;
}
else{
return false;
}
}
public final boolean NOBLACK(int i,int j) {
if(SideOfMan[tmap[i][j]]!=1){
return true;
}
else{
return false;
}
}
public final boolean NOMAN(int i,int j) {
if(tmap[i][j]==32){
return true;
}
else{
return false;
}
}
public Thinker(){
ResetBV();
m_nLevel = 1;
m_bThinking = FALSE;
m_bThinkOver = FALSE;
}
public void Think(Face face){
m_FaceToThink=new Face();
m_FaceToThink.copy(face);
m_bThinking = TRUE;
m_bThinkOver = FALSE;
}
void ResetBV()
{
//BV1记录了每个子的价值,BV2记录了每个子机动性的权值,BV3记录兵在不同位置的权值
BV1[0]=0; BV2[0]=0; //帅
BV1[1]=250; BV2[1]=1; //士
BV1[2]=250; BV2[2]=1; //相
BV1[3]=300; BV2[3]=12; //马
BV1[4]=400; BV2[4]=6; //车
BV1[5]=300; BV2[5]=6; //炮
BV1[6]=100; BV2[6]=15; //兵
BV3[0]=0;
BV3[1]=70;
BV3[2]=90;
BV3[3]=110;
BV3[4]=120;
}
//若返回为空说明思考还没有结束或者错误;
public Move getMove(Face facetothink)
{
//TRACE("Enter CThinker::GetMove()\n");
Move move=null;
if(!m_bThinkOver) {
//System.out.println("think is not over!");
return null;
}
if(facetothink!=m_FaceToThink)
{
move=m_moveResult;
m_bThinkOver=false;
return move;
}
System.out.println("getmove error!");
return null;
}
public void setLevel(int level)
{
m_nLevel=level;
}
public void run(){
int i,cur,curvalue; //curvalue为棋局评价值,cur为棋子代号
int maxvalue[]=new int[3];
Move maxmove[]=new Move[3];
for(int j=0;j<3;j++){
maxmove[j]=new Move();
}
while(true)
{
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(!m_bThinking)
{
continue;
}
curvalue=-10000;
maxvalue[0]=-10000;
maxvalue[1]=-10001;
maxvalue[2]=-10002;
tlevel = m_nLevel;
tdeep =0;
// bman=tman[0];
// btox=ttox[0];
// btoy=ttoy[0];
tcount[tdeep]=0;
for(i=0;i<32;i++)
{
tmanx[i]=m_FaceToThink.man[i].x;
tmany[i]=m_FaceToThink.man[i].y;
}
tside=m_FaceToThink.side;
m_FaceToThink=fixManMap(m_FaceToThink,tmap);
cur=0;
EnumList(); //列举双方现有局面所有子下一步可能的走法,将走法放入tman,ttox,ttoy中
//System.out.println("tcount[0]1="+tcount[0]);
while(cur<tcount[0]){
curvalue=SubThink(tman[0][cur],ttox[0][cur],ttoy[0][cur]);
//System.out.println("tcount[0]2="+cur);
//防止兑子过快:
if(tmap[ttox[0][cur]][ttox[0][cur]]!=32){
//System.out.println("cur=");
curvalue-=BV1[4]/18;
}
// System.out.println("man="+tman[0][cur]+",curvalue="+curvalue+",("+tmanx[tman[0][cur]]+","+tmany[tman[0][cur]]+
// ")--("+ttox[0][cur]+","+ttoy[0][cur]+")");
//找出前三个最大的分别放入maxvalu[0-2]中
if(curvalue >maxvalue[0])
{
maxmove[2].copy(maxmove[1]); maxvalue[2]=maxvalue[1];
maxmove[1].copy(maxmove[0]); maxvalue[1]=maxvalue[0];
maxmove[0].man=tman[0][cur];
maxmove[0].x=ttox[0][cur];
maxmove[0].y=ttoy[0][cur];
maxvalue[0]=curvalue;
}
else if(curvalue >maxvalue[1])
{
maxmove[2].copy(maxmove[1]); maxvalue[2]=maxvalue[1];
maxmove[1].man=tman[0][cur];
maxmove[1].x=ttox[0][cur];
maxmove[1].y=ttoy[0][cur];
maxvalue[1]=curvalue;
}
else if(curvalue >maxvalue[2])
{
maxmove[2].man=tman[0][cur];
maxmove[2].x=ttox[0][cur];
maxmove[2].y=ttoy[0][cur];
maxvalue[2]=curvalue;
}
cur ++;
}
// 结束一次计算:
//计算前3个最大的结果是否接近,要是接近就随即选择,若区别较大则选用最大的
//System.out.println(maxmove[0].man+" 1 "+maxmove[0].x+" "+maxmove[0].y);
//System.out.println(maxmove[1].man+" 2 "+maxmove[1].x+" "+maxmove[1].y);
// for(int p=0;p<3;p++){
// System.out.println(maxvalue[p]);
// }
//System.out.println("--------------------------------------------------------");
int f;
if((maxvalue[0]+maxvalue[1]+maxvalue[2])==0){
f=100;
}else{
f=(((maxvalue[0]-maxvalue[2])*100)/((maxvalue[0]+maxvalue[1]+maxvalue[2])/3));
}
if(f<10 && f>-10)
m_moveResult=maxmove[rnd(3)];
else
{
if((maxvalue[0]+maxvalue[1])==0){
f=100;
}else{
f=((maxvalue[0]-maxvalue[1])*100)/((maxvalue[0]+maxvalue[1])/2);
}
if(f<10 && f>-10){
m_moveResult=maxmove[rnd(2)];
}else{
//System.out.println("f="+maxvalue[0]);
m_moveResult=maxmove[0];
}
}
//System.out.println("Result:"+m_moveResult.man+" ("+m_moveResult.x+","+m_moveResult.y+")");
m_bThinking=false;
m_bThinkOver=TRUE;
// -------------------------
for(i=0;i<32;i++)
{
m_FaceToThink.man[i].x=tmanx[i];
m_FaceToThink.man[i].y=tmany[i];
}
m_FaceToThink.side=tside;
// -------------------------------
//System.out.println(m_moveResult.man+" "+m_moveResult.x+" "+m_moveResult.y);
}
}
private int boolToInt(boolean b){if(!b)return 0;return 1;}
private boolean intToBool(int i){if(i==0)return false;return true;}
// 将改子man能走的位置(tx,ty)加入队列
private boolean ADD(int man,int tx,int ty) {
tman[tdeep][lman]=man;
ttox[tdeep][ltox]=tx;
ttoy[tdeep][ltoy]=ty;
lman++;
ltox++;
ltoy++;
tcount[tdeep]++;
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Chess.rar (85个子文件)
Chess
.project 537B
bin
to_1.png 411B
red_k.png 4KB
backSmall.png 114KB
select_5.png 3KB
select_0.png 3KB
red_p.png 4KB
red_x.png 4KB
black_k.png 5KB
select_3.png 3KB
com
marko
MyTask.class 484B
Thinker.class 17KB
Move.class 610B
MyPoints.class 753B
GameShow.class 10KB
Face.class 2KB
SplashScreen.class 2KB
AppStart.class 1KB
ChessDefine.class 2KB
black_p.png 5KB
black_m.png 5KB
chessLoge.png 26KB
red_j.png 5KB
red_z.png 5KB
select_1.png 3KB
select_2.png 3KB
black_x.png 5KB
red_s.png 5KB
to_2.png 399B
to_0.png 404B
black_j.png 5KB
red_m.png 5KB
select_4.png 3KB
black_s.png 5KB
black_z.png 5KB
.settings
org.eclipse.jdt.core.prefs 208B
deployed
Chess.jar 246KB
Chess.jad 254B
.eclipseme.tmp
emulation
Chess.jar 246KB
Chess.jad 254B
verified
libs
classes
com
marko
MyTask.class 484B
Thinker.class 23KB
Move.class 610B
MyPoints.class 784B
GameShow.class 13KB
Face.class 2KB
SplashScreen.class 2KB
AppStart.class 1KB
ChessDefine.class 2KB
src
com
marko
AppStart.java 780B
ChessDefine.java 2KB
Thinker.java 32KB
Move.java 346B
MyPoints.java 349B
Face.java 2KB
GameShow.java 16KB
SplashScreen.java 2KB
Chess.jad 229B
.eclipseme 242B
res
to_1.png 411B
red_k.png 4KB
backSmall.png 114KB
select_5.png 3KB
select_0.png 3KB
red_p.png 4KB
red_x.png 4KB
black_k.png 5KB
select_3.png 3KB
black_p.png 5KB
black_m.png 5KB
chessLoge.png 26KB
red_j.png 5KB
red_z.png 5KB
select_1.png 3KB
select_2.png 3KB
black_x.png 5KB
red_s.png 5KB
to_2.png 399B
to_0.png 404B
black_j.png 5KB
red_m.png 5KB
select_4.png 3KB
black_s.png 5KB
black_z.png 5KB
.classpath 242B
共 85 条
- 1
资源评论
- weiming4535237822011-12-28绝对可以运行,测试过,只是界面简单了一点,不过主要的还在
- u0109962972013-06-12还是可以的,省了不少事情
marko39
- 粉丝: 81
- 资源: 35
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功