int Preprocessor::fillAllPossible(Sudokufield& field){ int anz( onlyOnePossible.size()); while(!onlyOnePossible.empty()){ Pos curr = *(onlyOnePossible.begin()); onlyOnePossible.erase(onlyOnePossible.begin()); field(curr.getX(), curr.getY()) = curr.getValue(); deleteDoubleCell(curr.getX(), curr.getY(), curr.getValue(), field); deleteDoubleColAndRow(curr.getX(), curr.getY(), curr.getValue(), field); deleteDoubleSquare(curr.getX(), curr.getY(), curr.getValue(), field); } return anz; }
void Solver::DeepSearch::backtrack(uint tile){ Pos<uint> newPos = positions[tile]; uint x, y; for(x=0; x<gameField.getTile(tile).getSizeX(); ++x) for(y=0; y<gameField.getTile(tile).getSizeY(); ++y){ if(gameField.getTile(tile).getField(x, y) == true){ if(currentValue[newPos.getX() + x][newPos.getY() + y] == 0){ currentValue[newPos.getX()+ x][newPos.getY() + y] = gameField.getField().getMod()-1; heuristicValue++; }else if (currentValue[newPos.getX() + x][newPos.getY() + y] == 1){ currentValue[newPos.getX() + x][newPos.getY()+ y] = 0; heuristicValue -= gameField.getField().getMod() -1; } else { currentValue[newPos.getX()+ x][newPos.getY() + y]--; heuristicValue++; } } } }
/************************************************************************************************** * Move * ***********************************************************************************************/ void Solver::DeepSearch::move(uint tile, Pos<uint> newPos){ uint x, y; for(x=0; x<gameField.getTile(tile).getSizeX(); ++x) for(y=0; y<gameField.getTile(tile).getSizeY(); ++y){ if(gameField.getTile(tile).getField(x, y) == true){ if(currentValue[newPos.getX() + x][newPos.getY() + y] == gameField.getField().getMod()-1){ currentValue[newPos.getX()+ x][newPos.getY() + y] = 0; heuristicValue--; }else if (currentValue[newPos.getX() + x][newPos.getY() + y] == 0){ currentValue[newPos.getX() + x][newPos.getY()+ y] = 1; heuristicValue += gameField.getField().getMod()-1; } else { currentValue[newPos.getX()+ x][newPos.getY() + y]++; heuristicValue--; } } } positions[tile] = newPos; }
int simplehero::selectNeighbor(GraphMap* map, int cur_x, int cur_y) { // printf("Selecting neighbor\n"); int x, y, a, b; Pos* goal = findGoal(map, cur_x, cur_y); int g; if(goal == 0) { printf("Couldn't find goal\n"); return 0; } g = map->getVertex(goal->getX(), goal->getY()); int toGo = BFSearch(map, cur_x, cur_y, g); //printf("Done searching\n"); if(toGo == -1) { // printf("No target found\n"); delete goal; return 0; } /* if(p == 0 || p[1]->getX() < 0) { printf("ERRRORRORROR\n"); goal = findGoal(map, cur_x, cur_y); toGo = BFSearch(map ,cur_x, cur_y, goal); }*/ map->getPosition(toGo, x, y); for(int i = 0; i < map->getNumNeighbors(cur_x, cur_y); i++) { map->getNeighbor(cur_x, cur_y, i, a, b); if(x == a && y == b) { delete goal; return i; } } printf("Shouldn't get here"); return 0; }
int Preprocessor::getIntForPos(const Pos& t){ return varToNumber[t.getX()][t.getY()][t]; }
/** @param p1: Die Koordinaten der ersten Position @param p2: Die Koordinaten der zweiten Position @return Die Distance Zwischen den 2 Koordinaten */ float Pos::calcDist(const Pos& p1, const Pos& p2){ return calcDist(p1.getX(), p1.getY(), p2.getX(), p2.getY()); }