Ejemplo n.º 1
0
 void generateBoard(vector<int>& board, vector<vector<string>>& solutions, int n){
     if(board.size() == n){
         if(isValidCross(board)){
             vector<string> solution;
             for(int i=0; i<n; i++){
                 string line(n, '.');
                 line[board[i]] = 'Q';
                 solution.push_back(line);
             }
             solutions.push_back(solution);
         }
         return;
     }
     for(int i=0; i<n; i++){
         bool exist = false;
         for(int j=0; j<board.size(); j++){
             if(board[j] == i){
                 exist = true;
                 break;
             }
         }
         if(!exist){
             board.push_back(i);
             if(isValidCross(board)) generateBoard(board, solutions, n);
             board.pop_back();
         }
     }
 }
Ejemplo n.º 2
0
void Input::parseArguments(int _count, char** _args) { 
    if (_count < 2) {
        throw "To few arguments!";
    }
    
    bool helpSwitch = false;
    bool tokensCountSwitch = false;
    bool towersCountSwitch = false;
    bool targetTowerSwitch = false;
    bool maxDepthSwitch = false;
    bool fileNameSwitch = false;
    
    for (int i = 1; i < _count; i = i + 2) {       
        if (strcmp(_args[i], "-h") == 0) {
            // Napoveda.
            helpSwitch = true;
            printHelp();
        } else if (strcmp(_args[i], "-n") == 0) {
            // Pocet tokenu.
            tokensCount = atoi(_args[i + 1]);
            tokensCountSwitch = true;
        } else if (strcmp(_args[i], "-s") == 0) {
            // Pocet vezi.
            towersCount = atoi(_args[i + 1]);
            towersCountSwitch = true;
        } else if (strcmp(_args[i], "-r") == 0) {
            // Cilova vez.
            targetTower = atoi(_args[i + 1]);
            targetTowerSwitch = true;
        } else if (strcmp(_args[i], "-d") == 0) {
            // Maximalni hloubka.
            maxDepth = atoi(_args[i + 1]);
            maxDepthSwitch = true;
        } else if (strcmp(_args[i], "-f") == 0) {
            fileName = _args[i + 1];
            fileNameSwitch = true;
        } else {
            throw "Unknown arguments. Use -h for help.";
        }
    }
    
    if (helpSwitch == false) {
        if (fileNameSwitch == true) {
            // Data se nacitai ze souboru.
            parseFile();            
        } else {
            // Data se generuji.
            if (tokensCountSwitch && towersCountSwitch && targetTowerSwitch && maxDepthSwitch) {
                generateBoard();
            } else {
                throw "Incomplete input!";
            }
        }
       // printTask(); //chci aby to vypsal jen master
    }
}
Ejemplo n.º 3
0
void MainWindow::generateGame(int level)
{
	if (gameBoard != NULL)
		delete gameBoard;
	
	gameBoard = new Board(level);
	generateBoard();
	connect(gameBoard, SIGNAL(theEnd()), this, SLOT(gameFinished()));
	counter->setText("Number of moves: " + QString::number(gameBoard->previousMoves.size()));
}
Ejemplo n.º 4
0
/**
  * Constructor
  * Initializes the board
  */
Minesweeper::Minesweeper()
{
    //Initialize board
    for(int i = 0; i < 10; i++)
    {
        for ( int j = 0; j < 10; j++)
        {
            mineBoard[i][j] = 0;
        }
    }

    //Generates the board with mines and populates the number of mines around it
    generateBoard();
}
Ejemplo n.º 5
0
int main (int argc,char *argv[]){

	srand(time(NULL));
	int size=16;
	float density;
	switch(argc){
		case 2:
			printf("yay, ein parameter\n");
			density=strtod(argv[1],NULL);
			break;

		case 3:
			density=strtod(argv[1],NULL);
			size = strtol(argv[2],NULL,10); break;

		default:
			printf("usage: %s [density] <size>\n",*argv);
			return -1;
	}

	if (size<1 || density > 1 || density < 0){
			printf("usage: %s [density] <size>\n",*argv);
			return -1;
	}
	printf("size: <%d>\ndensity: <%f>\n",size,density);

//	static int board[size][size];
	int** board = generateBoard(density,size);
	update(board,size);
//	getNeighbors(board,size-1,0,0);
//	getNeighbors(board,size-1,0,size);
//	getNeighbors(board,size-1,size-1,0);
//	getNeighbors(board,size-1,size-1,size-1);
//	getNeighbors(board,size,2,2);

}
Ejemplo n.º 6
0
SudokuBoardGenerator::SudokuBoardGenerator(int N, int p, int q, int numAssigments)
    :N(N), p(p), q(q), numAssignments(numAssigments)
{
    generateBoard(N, p, q, numAssignments, 5000);

}
Ejemplo n.º 7
0
void MainWindow::resizeEvent(QResizeEvent *e)
{
	scene->setSceneRect(0, 0, gview->width() - 20, gview->height() - 10);
	generateBoard();
}
Ejemplo n.º 8
0
 vector<vector<string>> solveNQueens(int n) {
     vector<int> board;
     vector<vector<string>> solutions;
     generateBoard(board, solutions, n);
     return solutions;
 }