当前位置: 首页>>代码示例>>C++>>正文


C++ Sudoku::setField方法代码示例

本文整理汇总了C++中Sudoku::setField方法的典型用法代码示例。如果您正苦于以下问题:C++ Sudoku::setField方法的具体用法?C++ Sudoku::setField怎么用?C++ Sudoku::setField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sudoku的用法示例。


在下文中一共展示了Sudoku::setField方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: guess

void Solver::guess(int index) { //Where slot=0-80
	Sudoku s = Sudoku();
	s.setField(_field);
	s.print();
	usleep(300);
	bool succes = false;
	for (int option : missing[index]) {
		if (_field.get(index) >= option) { // We have tried this slot before
			continue;
		}
		if (_field.fit(index, option)) {
			_field.set(index, option);
			succes = true;
			break;
		}
	}
	if (succes) {
		if (_field.countEmpty(true) > 0) {
			// Find the the next empty slot in the vector
			int curIndex = std::distance(emptySlots.begin(), std::find(emptySlots.begin(), emptySlots.end(), index));
			guess(emptySlots.at(curIndex + 1));
		} else {
			return;
		}
	} else {
		_field.set(index, 0);
		// Find the the previous tried slot in the vector
		int curIndex = std::distance(emptySlots.begin(), std::find(emptySlots.begin(), emptySlots.end(), index));
		guess(emptySlots.at(curIndex - 1));
	}
}
开发者ID:zenopax,项目名称:Sudoku,代码行数:31,代码来源:Solver.cpp

示例2: solve

void RecursiveSolver::solve(Sudoku& sudoku) {
	this->_field = sudoku.getField();
	options = findMissing();
	
	for(map<int,vector<int>>::iterator it = options.begin(); it != options.end(); ++it) {
		cout << it->first << " " << ": ";
		for (vector<int>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
			cout << *it2 << ", ";
		}
		cout << endl;
	}
	map<int,vector<int>>::iterator it = options.begin();
	count = 0;
	
	int status = -1;
	do {
		status = guess(it->first);
		switch(status) {
		case RETURN_NEXT:
			it = std::next(it);
			break;
		case RETURN_PREV:
			it = std::prev(it);
			break;
		}
	} while(status != RETURN_EXIT);
	
	
	sudoku.setField(_field);
}
开发者ID:zenopax,项目名称:Sudoku,代码行数:30,代码来源:RecursiveSolver.cpp

示例3: printProgress

void printProgress(int &count, Field &_field) {
	++count;
	if (count % 100000 == 0) {
		count = 0;
		Sudoku s = Sudoku();
		s.setField(_field);
		s.print();
		//usleep(300);
	}
}
开发者ID:zenopax,项目名称:Sudoku,代码行数:10,代码来源:RecursiveSolver.cpp

示例4: solve

void Solver::solve(Sudoku& sudoku) {
	this->_field = sudoku.getField();
	if (_field.countEmpty() == 0) {
		cout << "RETURN SOLVE BECAUSE NO EMPTY SLOTS 1" << endl;
		return;
	}
	// Look for slots with only one option, fill it in and repeat
	bool hit;
	do {
		hit = false;
		// Find all possible options for the empty slots
		missing = findMissing();
		
		// Find all slots with only one option
		for (int index = 0; index < _field.getSizeSq(); ++index) {
			if (missing[index].size() == 1) {
				_field.set(index, missing[index].at(0));
				missing[index].clear();
				cout << "MADE A HIT AT " << index << " WITH " << _field.get(index) << endl;
				hit = true;
			}
		}
	} while (hit == true);

	// We completed the puzzle, thus return
	if (_field.countEmpty(true) == 0) {
		cout << "RETURN SOLVE BECAUSE NO EMPTY SLOTS 2" << endl;
		sudoku.setField(_field);
		return;
	}
	// No more sure slots, so start guessing
	std::cout << "COMPLETED ALL SURE HITS, START GUESSING" << std::endl;
	// Print the result so far
	std::cout << "RESULT SO FAR: " << std::endl;
	Sudoku s = Sudoku();
	s.setField(_field);
	s.print();
	
	// Find all possible options for the remaining empty slots
	missing = findMissing();
	
	// Print all options
	for (int index = 0; index < _field.getSizeSq(); ++index) {
		cout << "[" << index << "]: ";
		for (int index2 = 0; index2 < missing[index].size(); ++index2) {
			cout << missing[index].at(index2) << " ";
		}
		cout << "\n";
	}
	emptySlots.clear();
	// Fill in the empty slots to the array
	for(map<int,vector<int>>::iterator it = missing.begin(); it != missing.end(); ++it) {
		if ((it->second).size() > 0)
			emptySlots.push_back(it->first);
	}
	// Sort the emptyslot indices by size small->big
	std::sort(emptySlots.begin(), emptySlots.end(), lessThan);
	
	guess(emptySlots.at(0));
	sudoku.setField(_field);
}
开发者ID:zenopax,项目名称:Sudoku,代码行数:61,代码来源:Solver.cpp


注:本文中的Sudoku::setField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。