Java Bitset

Hi Guys,

I tried to use Bitset Boards to play UTTT, but I didn’t had a good experience.
My code runs slow with Bitset than with byte vector.

Below is how i did my Bitset code:

private BitSet board = new BitSet(9*9*2);
public byte getCell(byte i) {
		if(!board.get(i*2+1)) {
			return 0;
		}
		if(board.get(i*2)) {
			return 1;
		}
		return 2;
	}	
	public void setCell(byte i, boolean myPlay) {
		if(myPlay) {
			board.set(i*2+1);
			board.set(i*2);
		} else {
			board.set(i*2+1);
			board.clear(i*2);
		}
	}

I’m doing it correct? There is a better way to do it?

Obviously, Bitset is a good candidate to save memory, but what makes you think it will be faster, especially considering it involves additional operations to access values?

In addition, when you said “byte vector”, did you mean Vector, the Java-class-you-should-not-use-since-it is-synchronized-and-instead-prefer-a class-such-as-ArrayList-which-isn’t ? :scream_cat: