Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
top13001 committed May 1, 2016
2 parents 65a8631 + ef64023 commit b50dbfd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/controller/GameConstants.java
Expand Up @@ -15,6 +15,7 @@ public class GameConstants {
public static final boolean APEX = true;
public static final boolean BACK = true;
public static final boolean CENT = true;
public static final boolean KCENT = true;
public static final boolean MOB = true;
public static final boolean PIECE_DIFFERENTIAL = true;

Expand Down
35 changes: 27 additions & 8 deletions src/model/Board.java
Expand Up @@ -449,15 +449,13 @@ public class Board {

noKings = (color == Color.BLACK && this.blackKings == 0) ||
(color == Color.WHITE && this.whiteKings == 0);
if (piece7.getColor() == color) {
eitherSquaresOccupiedByActiveMan |= active7;
if (piece7 != null && piece7.getColor() == color) {
eitherSquaresOccupiedByActiveMan |= (active7 && piece7.getType() == Type.NORMAL);
neitherSquaresOccupiedByPassiveMan &= (active7 && piece7.getType() == Type.NORMAL);
}
if (piece26.getColor() == color) {
eitherSquaresOccupiedByActiveMan |= active26;
}

if (piece7.getColor() == color && piece26.getColor() == color) {
if ()
if (piece26 != null && piece26.getColor() == color) {
eitherSquaresOccupiedByActiveMan |= (active26 && piece26.getType() == Type.NORMAL);
neitherSquaresOccupiedByPassiveMan &= (active26 && piece26.getType() == Type.NORMAL);
}

if (noKings && eitherSquaresOccupiedByActiveMan && neitherSquaresOccupiedByPassiveMan)
Expand Down Expand Up @@ -499,6 +497,24 @@ public class Board {
return 0;
}

/**
* The parameter is credited with 1 for each of the
* following squares: 11, 12, 15, 16, 20, 21, 24, and 25
* which is occupied by a passive king.
* @param color
* @return
*/
public int kcentHeuristic(Color color) {
int sum = 0;
int[] locations = {11, 12, 15, 16, 20, 21, 24, 25};
for (int k : locations) {
Piece p = this.getPiece(this.samuelMapping(k));
if (p != null && p.getType() == Type.KING && !isActive(p))
++sum;
}
return sum;
}

public int getHeuristic(Color color) {
/* Kings are weighted more, so we count for them twice */
int heuristic = 0;
Expand All @@ -516,6 +532,9 @@ public class Board {
}
if (GameConstants.MOB) {
heuristic += mobHeuristic(color);
}
if (GameConstants.KCENT) {
heuristic += kcentHeuristic(color);
}

return heuristic;
Expand Down

0 comments on commit b50dbfd

Please sign in to comment.