|
-
November 30th, 2009, 02:49 PM
#5
Re: Ned to optimize the code
 Originally Posted by Mariusmssj
9 lower bits on an int?
so i would have int 1; and it would have some numbers which would be the directions on my 3 by 3 array grid?
Number the board like this:
Code:
0 1 2
-----|------|-----
3 | 4 | 5
-----|------|-----
6 7 8
Each position on the board represents a bit in an integer. So if you have X's in 0,1,2, then bits 0, 1, and 2 of the integer are "on" (set to 1). The bits are numbered from right to left most, where bit 0 is the rightmost bit
000000111 == top row has all X's == 7
So 7 is a winning set of bits.
Another one is 0, 4, and 8 (the diagonal).
0100010001 = 273
Do the same with the other combinations, and you now have a list of integers that represent winning combinations.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; November 30th, 2009 at 02:57 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|