人机博弈之(六)------代码实现(1)常量数据
来源:互联网 发布:w10ipv6无网络访问权限 编辑:程序博客网 时间:2024/06/16 08:37
package constdata;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//数据表示
//
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
public class ConstData
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
...{
public final static byte NOCHESS = 0; //无子
//黑方
public final static byte B_KING = 1; //黑帅
public final static byte B_CAR = 2; //黑车
public final static byte B_HORSE = 3; //黑马
public final static byte B_CANON = 4; //黑炮
public final static byte B_BISHOP = 5; //黑士
public final static byte B_ELEPHANT = 6; //黑象
public final static byte B_PAWN = 7; //黑兵
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public final static byte B_BEGIN = 1;
public final static byte B_END = 7;
//红方
public final static byte R_KING = 8; //红将
public final static byte R_CAR = 9; //红车
public final static byte R_HORSE = 10; //红马
public final static byte R_CANON = 11; //红炮
public final static byte R_BISHOP = 12; //红仕
public final static byte R_ELEPHANT = 13; //红相
public final static byte R_PAWN = 14; //红卒
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public final static byte R_BEGIN = 8;
public final static byte R_END = 14;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//定义每种棋的价值
//兵100,士250,象250,马350,炮350车500
public final static int BASEVALUE_PAWN = 100;
public final static int BASEVALUE_BISHOP = 250;
public final static int BASEVALUE_ELEPHANT = 250;
public final static int BASEVALUE_HORSE = 350;
public final static int BASEVALUE_CANON = 350;
public final static int BASEVALUE_CAR = 500;
public final static int BASEVALUE_KING = 10000;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//定义各种棋子的灵活性
//也就是每多一个可走位置应加上的值
//兵15,士1,象1,车6,马12,炮6,王0
public final static int FLEXIBLE_PAWN = 15;
public final static int FLEXIBLE_BISHOP = 1;
public final static int FLEXIBLE_ELEPHANT = 1;
public final static int FLEXIBLE_HORSE = 12;
public final static int FLEXIBLE_CANON = 6;
public final static int FLEXIBLE_CAR = 6;
public final static int FLEXIBLE_KING = 0;
//初始棋盘
public final static byte INITCHESSBOARD[][]=
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{2, 3, 6, 5, 1, 5, 6, 3, 2},
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{0, 0, 0, 0, 0, 0, 0, 0, 0},
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{0, 4, 0, 0, 0, 0, 0, 4, 0},
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{7, 0, 7, 0, 7, 0, 7, 0, 7},
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{0, 0, 0, 0, 0, 0, 0, 0, 0},
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{0, 0, 0, 0, 0, 0, 0, 0, 0},
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{14, 0, 14, 0, 14, 0, 14, 0, 14},
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{0, 11, 0, 0, 0, 0, 0, 11, 0},
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{0, 0, 0, 0, 0, 0, 0, 0, 0},
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{9, 10, 13, 12, 8, 12, 13, 10,9}
};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//判断chessID是否是黑棋
public static boolean isBlack(byte chessID)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
return (chessID >= B_BEGIN && chessID <= B_END);
}
//判断chessID是否是红棋
public static boolean isRed(byte chessID)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
return (chessID >= R_BEGIN && chessID <= R_END);
}
//判断chessID1和chessID2是否是同色
public static boolean isSameSide(byte chessID1, byte chessID2)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
return ( (isBlack(chessID1)&&isBlack(chessID2))||(isRed(chessID1) && isRed(chessID2)));
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}