Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualcryo75

Posted 14 March 2013 - 05:24 AM

Ok, I think I will start small with using bitboards because I need to understand what the code is doing. So I read up on bitboards but all the resources I found relate to chess. However I didn't give up!!

As this game has just 24 positions I was thinking of using int. I will also have to handle signed because Java doesn't support unsigned. So I did the following:

int[] bb = {0, 0};

bb[0] = bb[0] | (1 << 0) | (1 << 1) | (1 << 2);
bb[1] = bb[1] | (1 << 9) | (1 << 21);

int free = ~(bb[0] | bb[1]) & 0xFFFFFF;

In the above code, I'm setting the positions' bits for each player, then I get the free spaces. This works fine because the result is:

110111111111110111111000

Now my question is: Do I have to loop through each bit in the result and check if the bit is set? If set, then it's free. If I use bitboards in this case what's the advantage over using a 1D array if I'm not going to get rid of the loops?

#2cryo75

Posted 14 March 2013 - 05:23 AM

Ok, I think I will start small with using bitboards because I need to understand what the code is doing. So I read up on bitboards but all the resources I found relate to chess. However I didn't give up!!

As this game has just 24 positions I was thinking of using int. I will also have to handle signed because Java doesn't support unsigned. So I did the following:

int[] bb = {0, 0};

bb[0] = bb[0] | (1 &lt;&lt; 0) | (1 &lt;&lt; 1) | (1 &lt;&lt; 2);
bb[1] = bb[1] | (1 &lt;&lt; 9) | (1 &lt;&lt; 21);

int free = ~(bb[0] | bb[1]) &amp; 0xFFFFFF;

In the above code, I'm setting the positions' bits for each player, then I get the free spaces. This works fine because the result is:

110111111111110111111000

Now my question is: Do I have to loop through each bit in the result and check if the bit is set? If set, then it's free. If I use bitboards in this case what's the advantage over using a 1D array if I'm not going to get rid of the loops?

#1cryo75

Posted 14 March 2013 - 05:22 AM

Ok, I think I will start small with using bitboards because as I need to understand what the code is doing. So I read up on bitboards but all the resources I found relate to chess. However I didn't give up!! As this game has just 24 positions I was thinking of using int. I will also have to handle signed because Java doesn't support unsigned. So I did the following: int[] bb = {0, 0}; bb[0] = bb[0] | (1 << 0) | (1 << 1) | (1 << 2); bb[1] = bb[1] | (1 << 9) | (1 << 21); int free = ~(bb[0] | bb[1]) & 0xFFFFFF; In the above code, I'm setting the positions' bits for each player, then I get the free spaces. This works fine because the result is: 110111111111110111111000 Now my question is: Do I have to loop through each bit in the result and check if the bit is set? If set, then it's free. If I use bitboards in this case what's the advantage over using a 1D array if I'm not going to get rid of the loops?

PARTNERS