static int linecheck(const char *check, const char *in) { for (int col = 0; in[col] != '\0'; ++col) { if (colcheck(check, &in[col]) == 1) return col+1; } return 0; }
int setallowed(int *board, int cc, int num) { int j, d; int row, col, box; board[cc] &= ~Allow; board[cc] = (board[cc] & ~Solve) | (num << 4); row = getrow(cc); for (j = 0; j < 9; j++) { if (board[rowind[row][j]] & allowbits[num]) { board[rowind[row][j]] &= ~allowbits[num]; if ((board[rowind[row][j]] & Allow) == 0) return(0); } } col = getcol(cc); for (j = 0; j < 9; j++) { if (board[colind[col][j]] & allowbits[num]) { board[colind[col][j]] &= ~allowbits[num]; if ((board[colind[col][j]] & Allow) == 0) return(0); } } box = getbox(cc); for (j = 0;j < 9;j++) { if (board[boxind[box][j]] & allowbits[num]) { board[boxind[box][j]] &= ~allowbits[num]; if ((board[boxind[box][j]] & Allow)==0) return(0); } } for (j = 0;j < 81; j++) for (d = 0; d < 9; d++) if ((board[j] & Allow) == allowbits[d]) if (!setallowed(board, j, d)) return(0); if (!boxcheck(board)||!rowcheck(board)||!colcheck(board)) return(0); for (j = 0; j < 81; j++) for (d = 0; d < 9; d++) if ((board[j] & Allow) == allowbits[d]) if (!setallowed(board, j, d)) return(0); return(1); }
//search areas perpendicular to direction of travel for places to change direction bool ghost::search_for_intersection(level l){ //std::cout << "searching" << std::endl; bool opening = false; bool curr = true; std::vector<sf::FloatRect> levelcol = l.get_collisions(); if (xvel != 0){ sf::FloatRect colcheck (collision_box.left, collision_box.top + (4 * ghostvel), collision_box.width, collision_box.height); for (unsigned i = 0; i < levelcol.size(); i++){ if (colcheck.intersects(levelcol.at(i))){ curr = false; break; } } if (curr){ return true; } curr = true; colcheck = sf::FloatRect(collision_box.left, collision_box.top - (4 * ghostvel), collision_box.width, collision_box.height); for (unsigned i = 0; i < levelcol.size(); i++){ if (colcheck.intersects(levelcol.at(i))){ curr = false; break; } } return curr; } else if (yvel != 0){ sf::FloatRect colcheck (collision_box.left + (4 * ghostvel), collision_box.top, collision_box.width, collision_box.height); for (unsigned i = 0; i < levelcol.size(); i++){ if (colcheck.intersects(levelcol.at(i))){ curr = false; break; } } if (curr){ return true; } curr = true; colcheck = sf::FloatRect(collision_box.left - (4 * ghostvel), collision_box.top, collision_box.width, collision_box.height); for (unsigned i = 0; i < levelcol.size(); i++){ if (colcheck.intersects(levelcol.at(i))){ curr = false; break; } } return curr; } else { sf::FloatRect colcheck (collision_box.left, collision_box.top + (4 * ghostvel), collision_box.width, collision_box.height); for (unsigned i = 0; i < levelcol.size(); i++){ if (colcheck.intersects(levelcol.at(i))){ curr = false; break; } } if (curr){ return true; } curr = true; colcheck = sf::FloatRect(collision_box.left + (4 * ghostvel), collision_box.top, collision_box.width, collision_box.height); for (unsigned i = 0; i < levelcol.size(); i++){ if (colcheck.intersects(levelcol.at(i))){ curr = false; break; } } if (curr){ return true; } curr = true; colcheck = sf::FloatRect(collision_box.left - (4 * ghostvel), collision_box.top, collision_box.width, collision_box.height); for (unsigned i = 0; i < levelcol.size(); i++){ if (colcheck.intersects(levelcol.at(i))){ curr = false; break; } } if (curr){ return true; } curr = true; colcheck = sf::FloatRect(collision_box.left, collision_box.top - (4 * ghostvel), collision_box.width, collision_box.height); for (unsigned i = 0; i < levelcol.size(); i++){ if (colcheck.intersects(levelcol.at(i))){ curr = false; break; } } return curr; } }