I currently have following code:
int[][] legalForBlack = {{0,1},{1,0},{2,3},{3,2}}; for (int x=0;x<boardSize;x++) { for (int y=0;y<boardSize;y++) { if (x,y) in legalForBlack methodA() else methodB() } } Of course this code won't compile. I am looking for a fancy and compact way to check when (x,y) are in the given list. I can do this with 4 if-statements or a loop, but this is not a proper way imo. I am looking for something that does this in constant time.
EDIT:
I think I found a way. What do you think of this?
int[][] legalForBlack = {{0,1},{1,0},{2,3},{3,2}}; // keep in order! int cur = 0; for (int x=0;x<boardSize;x++) { for (int y=0;y<boardSize;y++) { int[] buffer = legalForBlack[cur]; if (x==buffer[0] && y==buffer[1]) { cur++; methodA(); } else { methodB(); } } }