Bitboard based array generation problems in Java -


i making advanced chess engine fun. use bit boards monitor positions of pieces, however, thing isn't working. have written method convert string of binary digits numerical representation can stored in long. have verified that part of program works. problem array method, returns array missing rook instead of filled array.

this result expect when call method:

[ r, n, b, q, k, b, n, r] [ p, p, p, p, p, p, p, p] [  ,  ,  ,  ,  ,  ,  ,  ] [  ,  ,  ,  ,  ,  ,  ,  ] [  ,  ,  ,  ,  ,  ,  ,  ] [  ,  ,  ,  ,  ,  ,  ,  ] [ p, p, p, p, p, p, p, p] [ r, n, b, q, k, b, n, r] 

this get:

[r, n, b, q, k, b, n, r] [p, p, p, p, p, p, p, p] [ ,  ,  ,  ,  ,  ,  ,  ] [ ,  ,  ,  ,  ,  ,  ,  ] [ ,  ,  ,  ,  ,  ,  ,  ] [ ,  ,  ,  ,  ,  ,  ,  ] [p, p, p, p, p, p, p, p] [ , n, b, q, k, b, n, r]  

here source code of chess class:

package chess2; import com.google.common.base.*; import java.util.*;  public class chess {     private static long wr = 0l;     private static long wn = 0l;     private static long wb = 0l;     private static long wq = 0l;     private static long wk = 0l;     private static long wp = 0l;     private static long br = 0l;     private static long bn = 0l;     private static long bb = 0l;     private static long bq = 0l;     private static long bk = 0l;     private static long bp = 0l;     private static double time;     private static scanner read;     //private static long ep = 0l;      public chess(int id) {         string wr = "1000000100000000000000000000000000000000000000000000000000000000";         string wn = "0100001000000000000000000000000000000000000000000000000000000000";         string wb = "0010010000000000000000000000000000000000000000000000000000000000";         string wq = "0000100000000000000000000000000000000000000000000000000000000000";         string wk = "0001000000000000000000000000000000000000000000000000000000000000";         string wp = "0000000011111111000000000000000000000000000000000000000000000000";         string br = "0000000000000000000000000000000000000000000000000000000010000001";         string bn = "0000000000000000000000000000000000000000000000000000000001000010";         string bb = "0000000000000000000000000000000000000000000000000000000000100100";         string bq = "0000000000000000000000000000000000000000000000000000000000001000";         string bk = "0000000000000000000000000000000000000000000000000000000000010000";         string bp = "0000000000000000000000000000000000000000000000001111111100000000";         string time1 = stringtolong(wr, wn, wb, wq, wk, wp, br, bn, bb, bk, bq, bp);         read = new scanner(time1);         time = read.nextdouble();     }      public static string stringtolong(string wr2, string wn2, string wb2,             string wq2, string wk2, string wp2, string br2, string bn2,             string bb2, string bk2, string bq2, string bp2) {         stopwatch timer = stopwatch.createunstarted();         timer.start();         wr = stringtolong(wr2);         wn = stringtolong(wn2);         wb = stringtolong(wb2);         wq = stringtolong(wq2);         wk = stringtolong(wk2);         wp = stringtolong(wp2);         br = stringtolong(br2);         bn = stringtolong(bn2);         bb = stringtolong(bb2);         bq = stringtolong(bq2);         bk = stringtolong(bk2);         bp = stringtolong(bp2);         string time = timer.stop().tostring();         return time;     }      public static long stringtolong(string binary) {         if (binary.charat(0) =='0') { //not going negative number             return long.parselong(binary, 2);         }          else { //is negative             return long.parselong("1" + binary.substring(2), 2) * 2;         }     }      public double gettime() {         return time;     }      public string tostring() {         return ("" + wr + " \n" + wn + " \n" + wb + " \n" + wq + " \n" + wk + " \n" + wp + " \n"+                    + br + " \n" + bn + " \n" + bb + " \n" + bq + " \n" + bk + " \n" + bp + " \n");     }      public string[][] toarray() {         string chessboard[][] = new string[8][8];         (int = 0; < 64; i++) {             chessboard[i / 8][i % 8] = " ";         }         (int i=0;i<64;i++) {             if (((wp >> i) & 1) == 1) {                 chessboard[i/8][i%8]="p";             }             else if (((wn >> i) & 1) == 1) {                 chessboard[i/8][i%8]="n";             }             else if (((wb >> i) & 1) == 1) {                 chessboard[i/8][i%8]="b";             }             else if (((wr >> i) & 1) == 1) {                 chessboard[i/8][i%8]="r";             }             else if (((wq >> i) & 1) == 1) {                 chessboard[i/8][i%8]="q";             }             else if (((wk >> i) & 1) == 1) {                 chessboard[i/8][i%8]="k";             }             else if (((bp >> i) & 1) == 1) {                 chessboard[i/8][i%8]="p";             }             else if (((bn >> i) & 1) == 1) {                 chessboard[i/8][i%8]="n";             }             else if (((bb >> i) & 1) == 1) {                 chessboard[i/8][i%8]="b";             }             else if (((br >> i) & 1) == 1) {                 chessboard[i/8][i%8]="r";             }             else if (((bq >> i) & 1) == 1) {                 chessboard[i/8][i%8]="q";             }             else if (((bk >> i) & 1) == 1) {                 chessboard[i/8][i%8]="k";             }         }         return chessboard;     } } 

any , appreciated!

edit*

sorry, put wrong code!

don't pass in long variables wp, wn, wb etc arraytobitboards function, because if values set inside function parameter variables , not member variables in class.

public static void arraytobitboards(string[][] chessboard) {     ... } 

call:

arraytobitboards(chessboard); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -