Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Putting a move in the PNNode

  • Loading branch information...
commit 0d3e4482b728f1a26d856ea1bf2094110f55d41a 1 parent 35bd58e
unknown authored
View
16 src/net/aluink/chess/board/Piece.java
@@ -20,6 +20,18 @@ private Type(int i){
index = i;
}
+ public static Type fromIndex(int i){
+ switch(i){
+ case 0:return KING;
+ case 1:return QUEEN;
+ case 2:return BISHOP;
+ case 3:return KNIGHT;
+ case 4:return ROOK;
+ case 5:return PAWN;
+ }
+ return null;
+ }
+
public int getIndex(){
return index;
}
@@ -107,4 +119,8 @@ public static Piece fromFen(char c){
public byte getByte() {
return (byte) ((1 << 4) | (getColor() == Color.WHITE ? (1 << 3) : 0) | (getType().getIndex()));
}
+
+ public static Piece fromCompressed(int i) {
+ return new Piece((i >> 3 & 1) == 1 ? Color.WHITE : Color.BLACK, Type.fromIndex(i & 0x7));
+ }
}
View
8 src/net/aluink/chess/suicide/ai/pn/PNSearch.java
@@ -139,16 +139,12 @@ int findMostProvingNode(int index) {
return index;
}
- Stack<Move> moves = lmg.getLegalMoves(board);
-
int n = node.firstChild;
- Move m = moves.get(0);
if(board.getTurn() == rootColor){
for(int i = 0;n >= 0;n = NODES[n].sibling, i++){
PNNode tmp = NODES[n];
if(tmp.proof == node.proof){
- m = moves.get(i);
break;
}
}
@@ -156,12 +152,12 @@ int findMostProvingNode(int index) {
for(int i = 0;n >= 0;n = NODES[n].sibling, i++){
PNNode tmp = NODES[n];
if(tmp.disproof == node.disproof){
- m = moves.get(i);
break;
}
}
}
- board.makeMove(new Move(NODES[n].move));
+ PNNode t = NODES[n];
+ board.makeMove(new Move(t.move));
return findMostProvingNode(n);
}
}
View
2  src/net/aluink/chess/suicide/game/Board.java
@@ -390,7 +390,7 @@ public void setFen(String fen) throws Exception {
}
public static void main(String[] args) {
- Board.printBitboard(4755801206503243776L);
+ Board.printBitboard(9115426935197958144L);
}
public long[][] getBitBoards() {
View
15 src/net/aluink/chess/suicide/game/Move.java
@@ -39,7 +39,8 @@ public Move(Move m) {
public Move(short move) {
this.start = move >> 11 & 0x7F;
this.end = move >> 6 & 0x7F;
- promo = null;
+ this.ep = (move >> 5 & 1) == 1;
+ promo = Piece.fromCompressed(move & 0x7F);
}
public int getStart() {
@@ -56,7 +57,7 @@ public void setEnd(int end) {
}
public String toString(){
- return "" + (char)((start%8) + 'a') + (start/8 + 1) + (char)((end%8)+'a') + (end/8+1) + (promo != null ? Character.toUpperCase(promo.getFen()) : "");
+ return "" + (char)((start%8) + 'a') + (start/8 + 1) + (char)((end%8)+'a') + (end/8+1) + (promo != null ? (promo.getColor() == Color.WHITE ? Character.toUpperCase(promo.getFen()) + "" : promo.getFen() + "") : "");
}
public static Move [] promoSet(int start, int end, Color c){
@@ -86,15 +87,13 @@ public boolean equals(Object rhs){
}
public short getCompressed() {
- return (short) ((start << 11) | (end << 6) | (promo == null ? 0 : promo.getByte()));
+ return (short) ((start << 11) | (end << 6) | ((ep?1:0) << 5) | (promo == null ? 0 : promo.getByte()));
}
public static void main(String[] args) {
- int start = 12;
- int end = 20;
- Move promo = null;
- short x = (short) ((start << 11) | (end << 6) | (promo == null ? 0 : promo.getCompressed()));
- System.out.println(x);
+ short x = -30208;
+ Move m = new Move(x);
+ System.out.println(m);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.