Example #1
0
void solve_board(board_t* board)
{
	stats.solve++;
	if (is_complete(board)) {
		printf("SOLVED!\n");
		print_board(board);
		print_stats(stats);
		assert(0);
	} else if (is_dead_end(board)) {
		debugf("dead end, skip\n");
	} else {
		size_t i_row, i_col;
		digits_t digits;
		find_next_continuation(board, &i_row, &i_col, &digits);
		debugf("best continuation [%lu,%lu]\n", i_row, i_col);
		size_t i;
		for (i = 1; i < NDIGITS; i++) {
			if (0 == digits.digits[i]) {
				debugf("extending [%lu,%lu] <- %lu\n", i_row, i_col, i);
				board_t* new_board = copy_board(board);
				set_digit(new_board, i_row, i_col, i);
				solve_board(new_board);
				free(new_board);
			}
		}
	}
}
Example #2
0
void Maze::remove_dead_end(MapPrototype &map) {
	//To remove dead ends, we just look all the cells
	//If there's a dead ends, we add a way to a random direction
	for (int i=1;i<(map.x-1);i+=2)
		for (int j=1;j<(map.y-1);j+=2)
			if (is_dead_end(map,i,j)) {
				int dir = rand()%4;
				for (int k=0;k<4;k++) {
					switch (dir) {
						case 0:
							if ((i != 1) && (map.cell[i-1][j] == WALL)) {
								map.cell[i-1][j] = FLOOR;
								k = 4;
							}
							break;
						case 1:
							if ((i < (map.x-2-!(map.x%2))) && (map.cell[i+1][j] == WALL)) {
								map.cell[i+1][j] = FLOOR;
								k = 4;
							}
							break;
						case 2:
							if ((j != 1) && (map.cell[i][j-1] == WALL)) {
								map.cell[i][j-1] = FLOOR;
								k = 4;
							}
							break;
						case 3:
							if ((j < (map.y-2-!(map.y%2))) && (map.cell[i][j+1] == WALL)) {
								map.cell[i][j+1] = FLOOR;
								k = 4;
							}
							break;
					}
					dir = (dir+1)%4;
				}
			}
}