📄 activityvaluer.java
字号:
/* * ActivityValuer.java * * Created on 2007-10-9, 15:24:26 * * To change this template, choose Tools | Templates * and open the template in the editor. */package org.yangcq.logic.valuer;import org.yangcq.logic.step.Step;/** * * @author Administrator */public class ActivityValuer implements IValuer{ //行动力估值算法:同时计算潜在行动力 public long getValue(Step[][] steps, boolean side) { long value = 0; for (int x = 0; x < steps.length; x++) { for (int y = 0; y < steps[x].length; y++) { if (canChess(steps, x, y, side)) { value += 4; //一个行动力得5分 } if (steps[x][y] == null) { for (int i = x - 1; i < x + 2; i++) { for (int j = y - 1; j < y + 2; j++) { if (i >= 0 && j >= 0 && i < steps.length && j < steps.length && steps[i][j] != null && steps[i][j].getColor().booleanValue() == !side) { value++;//潜在行动力一分 } } } } } } return value; } private boolean canChess(Step[][] steps, int x, int y, boolean chessmanBlack) { int xx; int yy; boolean opSide; byte b; if (steps[x][y] != null) { return false; } opSide = !chessmanBlack; xx = x - 1; b = 0; while ((xx > 0) && (steps[xx][y] != null) && (steps[xx][y].getColor().booleanValue() == opSide)) { b = 1; --xx; } if (b > 0 && (xx >= 0) && (steps[xx][y] != null) && (steps[xx][y].getColor().booleanValue() == chessmanBlack)) { return true; } xx = x - 1; yy = y - 1; b = 0; while ((xx > 0) && (yy > 0) && (steps[xx][yy] != null) && (steps[xx][yy].getColor().booleanValue() == opSide)) { b = 1; --xx; --yy; } if ((b > 0) && (xx >= 0) && (yy >= 0) && (steps[xx][yy] != null) && (steps[xx][yy].getColor().booleanValue() == chessmanBlack)) { return true; } xx = x - 1; yy = y + 1; b = 0; while ((xx > 0) && (yy < steps[xx].length - 1) && (steps[xx][yy] != null) && (steps[xx][yy].getColor().booleanValue() == opSide)) { b = 1; --xx; ++yy; } if (b > 0 && (xx >= 0) && (yy < steps[xx].length) && (steps[xx][yy] != null) && (steps[xx][yy].getColor().booleanValue() == chessmanBlack)) { return true; } yy = y - 1; b = 0; while ((yy > 0) && (steps[x][yy] != null) && (steps[x][yy].getColor().booleanValue() == opSide)) { b = 1; --yy; } if (b > 0 && (yy >= 0) && (steps[x][yy] != null) && (steps[x][yy].getColor().booleanValue() == chessmanBlack)) { return true; } yy = y + 1; b = 0; while ((yy < steps.length - 1) && (steps[x][yy] != null) && (steps[x][yy].getColor().booleanValue() == opSide)) { b = 1; ++yy; } if (b > 0 && (yy < steps.length) && (steps[x][yy] != null) && (steps[x][yy].getColor().booleanValue() == chessmanBlack)) { return true; } xx = x + 1; yy = y - 1; b = 0; while ((xx < steps.length - 1) && (yy > 0) && (steps[xx][yy] != null) && (steps[xx][yy].getColor().booleanValue() == opSide)) { b = 1; ++xx; --yy; } if (b > 0 && (xx < steps.length) && (yy >= 0) && (steps[xx][yy] != null) && (steps[xx][yy].getColor().booleanValue() == chessmanBlack)) { return true; } xx = x + 1; b = 0; while ((xx < steps.length - 1) && (steps[xx][y] != null) && (steps[xx][y].getColor().booleanValue() == opSide)) { b = 1; ++xx; } if (b > 0 && (xx < steps.length) && (steps[xx][y] != null) && (steps[xx][y].getColor().booleanValue() == chessmanBlack)) { return true; } xx = x + 1; yy = y + 1; b = 0; while ((xx < steps.length - 1) && (yy < steps.length - 1) && (steps[xx][yy] != null) && (steps[xx][yy].getColor().booleanValue() == opSide)) { b = 1; ++xx; ++yy; } if (b > 0 && (xx < steps.length) && (yy < steps.length) && (steps[xx][yy] != null) && (steps[xx][yy].getColor().booleanValue() == chessmanBlack)) { return true; } return false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -