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


C++ Puzzle类代码示例

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


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

示例1: main

int				main(int argc, char ** argv)
{
	Puzzle *	puzzle = NULL;
	Display *	display = NULL;

	if (argc > 4 || argc < 3 || strcmp(argv[1], "-g"))
	{
		std::cout << "Usage " << argv[0] << " -g greedness [filename]" << std::endl;
		return (EXIT_SUCCESS);
	}
	try
	{
		srand(time(NULL));
		Puzzle::_greedness = (atoi(argv[2]) > 0) ? atoi(argv[2]) : 1;
		if (argc == 4)
			puzzle = new Puzzle(argv[3]);
		else if (argc == 3)
			puzzle = new Puzzle();
		puzzle->isSolvable();
		display = new Display(puzzle);
		display->render();
	}
	catch (std::exception & e)
	{
		std::cout << e.what() << std::endl;
	}
	if (display)
		delete display;
	return (EXIT_SUCCESS);
}
开发者ID:jdG-,项目名称:taquin,代码行数:30,代码来源:main.cpp

示例2: manhattan

int manhattan(const Puzzle& state, const Puzzle& solution) {
    int result = -1;

    /*
     * These loops compare two vectors piece by piece,
     * finding the row and column indeces for corresponding
     * pieces, and adding the magnitudes of the differences.
     *
     * This is presently O(n^2).
     * TODO: investigate O(n) solution
     */
    if(state.get_width() == solution.get_width()) {
        size_t width = state.get_width();
        int i = 0;
        for(TileIt it1 = state.tiles.begin(); it1 != state.tiles.end(); it1++, i++) {
            if(*it1 != 0) {

                int j = 0;
                for(TileIt it2 = solution.tiles.begin(); *it1 != *it2; it2++, j++);

                int r1 = i / width;
                int r2 = j / width;
                int c1 = i % width;
                int c2 = j % width;

                result += abs(r2 - r1) + abs(c2 - c1);
            }
        }
    }

    return result;
}
开发者ID:jonolss,项目名称:libastar,代码行数:32,代码来源:n-puzzle.cpp

示例3: Game

Game CustomGame::createGame(int difficulty, int symmetry) {
	if (! createSKGraphObject()) {
	    return Game();
	}
	Puzzle* puzzle = new Puzzle(m_graph, true);
	puzzle->init(difficulty, symmetry);

	return Game(puzzle);
}
开发者ID:KDE,项目名称:ksudoku,代码行数:9,代码来源:gamevariants.cpp

示例4: main

int								main(int argc, char **argv)
{
    char Name = 'M';
    std::string taq = "TaquinA5_2.txt";
    if (argc == 3)
    {
        std::ifstream infile;
        infile.open(argv[2]);
        if (!infile.is_open())
        {
            std::cout << "Error: file <" << argv[2] << ">" << " not found" << std::endl;
            return (-1);
        }
        infile.close();
        taq = argv[2];
        FileLoader				F;
        std::string				S;
        Puzzle					P;
        SolutionGenerator		SG;
        short unsigned int**	Tab;
        clock_t					timeDeb, timeEnd;
        std::list<Puzzle>		OpenedList, ClosedList;
        int x = 0, y = 0, fg = -42;

        timeDeb = clock();
        DisplayLogo();
        F.LoadFile(taq.c_str(), S);
        std::istringstream		In(S);
        P.SetAlgo(Name);
        Tab = P.CreatePuzzle(S);
        std::list<Puzzle>::iterator FirstPuzzle;
        OpenedList.push_back(P);
        while (fg != 0 && !OpenedList.empty())
        {
            FirstPuzzle = OpenedList.begin();
            fg = Resume(FirstPuzzle, OpenedList, ClosedList, timeEnd);
            ProcessUp(FirstPuzzle, OpenedList, ClosedList);
            ProcessDown(FirstPuzzle, OpenedList, ClosedList);
            ProcessRight(FirstPuzzle, OpenedList, ClosedList);
            ProcessLeft(FirstPuzzle, OpenedList, ClosedList);

            (*FirstPuzzle).ClearListTab();
            ClosedList.push_back(*FirstPuzzle);
            OpenedList.erase(FirstPuzzle);
        }
        if (fg != 0)
            std::cout << "NO SOLUTION FOR THIS TAQUIN!!!" << std::endl;
        std::cout << "CLOSED LIST NUMBER OF CONTENTS	: \t\t[" << ClosedList.size() << "]"<< std::endl;
        std::cout << "TIME ELAPSED			: \t\t[" << static_cast<double>(timeEnd - timeDeb) << "] ms." << std::endl;
        ShowNbMoves();
        std::cout << "Cleaning..." << std::endl;
        Clean(OpenedList, ClosedList);
        std::cout << "Clean done" << std::endl;
    }
    return (0);
}
开发者ID:SouhaibDZ,项目名称:taquin42,代码行数:56,代码来源:main.cpp

示例5: main

int main(int argc, char** argv)
{
    freopen("CON", "w", stdout); // redirects stdout because SDL redirects it to a file.

    /* Parsing the input parameters. */
    if (argc < 6)
    {
        std::cout << "Missing some input parametr. Needed at least 5 but got only " << argc - 1 << std::endl;
        return -1;
    }

	if (!initGraphics(RESX, RESY)) return -1;
	renderScene();
	displayVFB(vfb);

    try
	{
		Puzzle puzzle;
		if (!puzzle.loadMap(argv[1]))
			throw "Something is wrong with the map file!";

        puzzle.setMonsterAndFoodCoords(fromStringToInt(argv[2]), fromStringToInt(argv[3]), fromStringToInt(argv[4]), fromStringToInt(argv[5]));

        // The flag for the SDL visualization
        if (argc >= 7)
        {
            puzzle.setVisualizationFlag(fromStringToInt(argv[6]));
        }

        // The flag for the SDL visualization
        if (argc >= 8)
        {
            puzzle.setDelay(fromStringToInt(argv[7]));
        }
		puzzle.printMap(std::cout);
		puzzle.solveAndVizualize(std::cout);
		puzzle.visualizeThePath();
		puzzle.basicVisualizePath(std::cout);
		puzzle.printFormatedPath(std::cout);

	}
	catch (const char * msg)
	{
		std::cout << "Error: " << msg << std::endl;
	}
	catch (const string msg)
	{
		std::cout << "Error: " << msg << std::endl;
	}


	waitForUserExit();
	closeGraphics();
	return 0;
}
开发者ID:Anton94,项目名称:Systems-based-on-knowledge,代码行数:55,代码来源:main.cpp

示例6: SKGraph

Game RoxdokuGame::createGame(int difficulty, int symmetry) {
	if(!m_graph) {
		m_graph = new SKGraph(m_order, TypeRoxdoku);
		m_graph->initRoxdoku();
	}

	Puzzle* puzzle = new Puzzle(m_graph, true);
	puzzle->init(difficulty, symmetry);

	return Game(puzzle);
}
开发者ID:KDE,项目名称:ksudoku,代码行数:11,代码来源:gamevariants.cpp

示例7: main

int main(int argc, char** argv)
{
    Puzzle test;
    Puzzle fit;
    srand(time(NULL));

    cin >> test;
    GeneticAlgorithm tryit(test, atoi(argv[1]), atoi(argv[2]));
    //GeneticAlgorithm tryit(test, POPSIZE, MAXGENS);
    fit = tryit.evolve();
    fit.display();
    cout << "Fitness: " << fit.fitness() << endl;

    return (EXIT_SUCCESS);
}
开发者ID:Whompithian,项目名称:css342-project4,代码行数:15,代码来源:sudoku.cpp

示例8: displaced

/*
 * These are the three examined heuristic functions.
 * displaced(...) counts how many tiles are out of place
 * manhattan(...) determines how far away each tile is from
 * its correct location, as specified in the solution.
 * sumdisman(...) simply sums displaced(...) and manhattan(...).
 */
int displaced(const Puzzle& state, const Puzzle& solution) {
    int result = -1;

    if(state.get_width() == solution.get_width()) {
        result = 0;

        for(TileIt it1 = state.tiles.begin(), it2 = solution.tiles.begin(); it1 != state.tiles.end(); it1++, it2++) {
            if(*it1 != 0 && *it1 != *it2) {
                result++;
            }
        }
    }

    return result;
}
开发者ID:jonolss,项目名称:libastar,代码行数:22,代码来源:n-puzzle.cpp

示例9: PuzzlesDraw

void PuzzlesDraw(const Puzzle & pzl, const Surface & sf, s16 dstx, s16 dsty)
{
    Display & display = Display::Get();
    Cursor & cursor = Cursor::Get();

    // show all for debug
    if(IS_DEVEL()) return;

    u8 alpha = 250;
    u32 ticket = 0;
    LocalEvent & le = LocalEvent::Get();
    while(le.HandleEvents() && 0 < alpha)
    {
        if(Game::ShouldAnimateInfrequent(ticket, 1))
        {
    	    cursor.Hide();
	    display.Blit(sf, dstx, dsty);
	    for(size_t ii = 0; ii < pzl.size(); ++ii)
	    {
    		const Sprite & piece = AGG::GetICN(ICN::PUZZLE, ii);
		if(pzl.test(ii))
		{
		    Surface fade(piece.w(), piece.h());
		    fade.SetColorKey();
		    fade.Blit(piece);
		    fade.SetAlpha(alpha);
		    if(Settings::Get().QVGA())
		    display.Blit(fade, dstx + 8 + piece.x() - BORDERWIDTH, dsty + 8 + piece.y() - BORDERWIDTH);
		    else
		    display.Blit(fade, dstx + piece.x() - BORDERWIDTH, dsty + piece.y() - BORDERWIDTH);
		}
		else
		{
		    if(Settings::Get().QVGA())
		    display.Blit(piece, dstx + 8 + piece.x() - BORDERWIDTH, dsty + 8 + piece.y() - BORDERWIDTH);
		    else
		    display.Blit(piece, dstx + piece.x() - BORDERWIDTH, dsty + piece.y() - BORDERWIDTH);
		}
	    }
	    cursor.Show();
    	    display.Flip();
    	    alpha -= 10;
	}

	++ticket;
    }
    cursor.Hide();
}
开发者ID:blchinezu,项目名称:EZX-Projects,代码行数:48,代码来源:puzzle.cpp

示例10: ZoneOpenRandomTiles

void ZoneOpenRandomTiles(Puzzle & pzl, u8 & opens, const u8* it1, const u8* it2)
{
    std::vector<u8> values;
    values.reserve(25);
    const u8* it = NULL;

    while(opens)
    {
	values.clear();
	it = it1;
	while(it && it2 && it <= it2){ if(! pzl.test(*it)) values.push_back(*it); ++it; }
	if(values.empty()) break;
	pzl.set(*Rand::Get(values));
	--opens;
    }
}
开发者ID:blchinezu,项目名称:EZX-Projects,代码行数:16,代码来源:puzzle.cpp

示例11: printAndSolve

void printAndSolve( Puzzle sudoku ) {

  cout << "\nThe given puzzle looks like this: \n\n";

  sudoku.printBoard();

  if (!sudoku.solve()) {
    printf("Cannot solve puzzle\n");
    exit(0);
  }
    
  cout << "\n\nThe solved puzzle looks like this: \n\n";

  sudoku.printBoard();
  cout << "\n\n";
}
开发者ID:jgautsch,项目名称:Sudoku-Solver,代码行数:16,代码来源:main.cpp

示例12: getMostConstrainedHole

inline GridPoint* PuzzleSolverInterface::getMostConstrainedHole(
        const int* remainingShapeList,
        int numRemainingShapes,
        bool estimate)
{
    return puzzle->getMostConstrainedHole(remainingShapeList, numRemainingShapes, estimate);
}
开发者ID:khursani8,项目名称:poly,代码行数:7,代码来源:PuzzleSolverInterface.hpp

示例13: outputExpanding

void outputExpanding(Puzzle puzzle)
{
    printf("The best state to expand is ...:\n");
    puzzle.output();
    printf("Expanding this node..\n");

}
开发者ID:ninocanna,项目名称:8-puzzle-solver,代码行数:7,代码来源:main.cpp

示例14: main

int main(){
   Puzzle sudoku;
   cin >> sudoku;
   cout << "Unsolved Puzzle:" << endl;
   sudoku.display();
   cout << endl;
   //Solve returns true if solved, false if not.
   if (sudoku.solve(0, 0)) {
      cout << "Solved Puzzle:" << endl;
      sudoku.display();
      cout << endl;
   }
   else {
      cout << "Puzzle is unsolvable." << endl;
   }
   return 0;
}
开发者ID:kestemm,项目名称:work_examples,代码行数:17,代码来源:SudokuSolver.cpp

示例15: RunPuzzleSolver

int RunPuzzleSolver(int argc, char **argv)
{ 
    printf("usage: RunPuzzleSolver fnameBoard heuristic tmax fnameMoves\n");
    
    const char  *fnameIn = argc > 1 ? argv[1] : "puzzle.txt";
    const char  *hname   = argc > 2 ? argv[2] : NULL;
    const double tmax    = argc > 3 ? atof(argv[3]) : 3.0;
    const char  *fnameOut= argc > 4 ? argv[4] : "moves.txt";
    

    printf("..using fnameBoard = %s\n", fnameIn);
    printf("..using heuristic  = %s\n", hname);
    printf("..using tmax       = %f\n", tmax);
    printf("..using fnameMoves = %s\n", fnameOut);
     
    Puzzle puzzle;
    Puzzle::Board *b = puzzle.ReadBoard(fnameIn);
    PuzzleSolver solver;
    PuzzleHeuristic *h = NULL;
    std::vector<Puzzle::Move> moves;
    
    
    if(hname == NULL)
	h = new PuzzleHeuristic();
    else if(strcmp(hname, "H1") == 0)
	h = new PuzzleHeuristic1();
    else if(strcmp(hname, "H2") == 0)
	h = new PuzzleHeuristic2();
    else if(strcmp(hname, "H3") == 0)
	h = new PuzzleHeuristic3();
    
   
    Utils::Timer::Clock clk;

    Utils::Timer::Start(&clk);
    const bool solved = solver.Solve(&puzzle,  h, b, tmax, &moves);
    printf("..solved = %d nrMoves = %d time = %f\n", solved, (int) moves.size(), Utils::Timer::Elapsed(&clk));

    printf("..checking solution\n");
    for(int i = 0; i < (int) moves.size(); ++i)
	puzzle.MakeMove(b, moves[i]);
    if(puzzle.IsSolved(b) == false)
    {
	printf("..did not reach goal configuration, see\n");
	puzzle.PrintBoard(NULL, b);
    }
    else 
	printf("..ok\n");
    
    
    puzzle.PrintMoves(fnameOut, &moves);
    
    
    puzzle.DeleteBoard(b);
    delete h;
    
    
    return 0;
}
开发者ID:DianeRay,项目名称:N-puzzle,代码行数:59,代码来源:RunPuzzleSolver.cpp


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