No older revisions available
No older revisions available
8Bit Version
~cpp #include <stdio.h> #define MASK 0x01 unsigned char rmap[8], map[8] = {0,0,0,0,0,0,0,0}; void result(void) { int i = 0; for (printf("\nResult: "); i < 8 ; printf("[%2x] ", rmap[i++])); } int mask(unsigned char * tmap , register int x, register int y) { register int i; if(map[y] & MASK << x) return 0; memcpy(tmap, map, 8); rmap[y] = MASK << x; map[y] |= 0xff; for (i = 0;i < 8;i++) map[i] |= (MASK << x) | (MASK << (x - y + i)) | (MASK << (x + y - i)); return 1; } void checkQueen(int depth) { int i; unsigned char tmap[8]; for( i = 0;i < 8 && depth < 8;i++) { if(mask(tmap, i, depth)) { if((depth + 1) == 8) result(); checkQueen(depth + 1); memcpy(map, tmap, 8); } } } int main() { checkQueen(0); return 0; }