Esempio n. 1
0
void fillQueue(nodeQueue currentNode, nodeQueue queueTop, map previousState, list listMap, bool* cleared, bool isRH)
{
	//crée une map pour currentNode: currentMap si non présente dans la liste, si elle y est, on récupère
	//cherche tous les coups possibles
	for (int p = 0; p < game_nb_pieces(currentNode->m->g); p++)
	{
		//for (int dist = 1; dist < 1; dist++)
			for (int d = 0; d < 4; d++)
			{

				map r = createNewState(previousState, p, d, 1);
				if (r != NULL)
				{
					r = checkMapExistence(r, listMap);
					if (r != NULL)
					{
						//drawInterface(r->g, "TEST");
						queueTop = newQueueItem(r, queueTop);
						if (isCleared(queueTop, isRH))
						{
							//drawInterface(queueTop->m->g, "TEST");
							currentNode = queueTop;
							*cleared = true;
							return;
						}
						// queueTop = queueTop->next;
					}
				}
			}
	}
	
	//pour chaque coup (donc game), on crée une Map: newMap(newGame, currentMap)
	//si la map n'est pas présente dans  listMap, alors on l'y insère. On y ajoute un nouveau node dans la file, � partir de top
		//et on "incrémente" top (top = top->next or something)
}
void StatesEditorWidget::reloadQmlSource()
{
    QString statesListQmlFilePath = qmlSourcesPath() + QStringLiteral("/StatesList.qml");
    QTC_ASSERT(QFileInfo::exists(statesListQmlFilePath), return);
    engine()->clearComponentCache();
    setSource(QUrl::fromLocalFile(statesListQmlFilePath));

    QTC_ASSERT(rootObject(), return);
    connect(rootObject(), SIGNAL(currentStateInternalIdChanged()), m_statesEditorView.data(), SLOT(synchonizeCurrentStateFromWidget()));
    connect(rootObject(), SIGNAL(createNewState()), m_statesEditorView.data(), SLOT(createNewState()));
    connect(rootObject(), SIGNAL(deleteState(int)), m_statesEditorView.data(), SLOT(removeState(int)));
    m_statesEditorView.data()->synchonizeCurrentStateFromWidget();
    setFixedHeight(initialSize().height());

    connect(rootObject(), SIGNAL(expandedChanged()), this, SLOT(changeHeight()));
}
Esempio n. 3
0
void StatesEditorWidget::reloadQmlSource()
{
    QString statesListQmlFilePath = statesEditorResourcesPath() + QStringLiteral("/stateslist.qml");
    QTC_ASSERT(QFileInfo::exists(statesListQmlFilePath), return);
    m_quickView->engine()->clearComponentCache();
    m_quickView->setSource(QUrl::fromLocalFile(statesListQmlFilePath));

    QTC_ASSERT(m_quickView->rootObject(), return);
    connect(m_quickView->rootObject(), SIGNAL(currentStateInternalIdChanged()), m_statesEditorView.data(), SLOT(synchonizeCurrentStateFromWidget()));
    connect(m_quickView->rootObject(), SIGNAL(createNewState()), m_statesEditorView.data(), SLOT(createNewState()));
    connect(m_quickView->rootObject(), SIGNAL(deleteState(int)), m_statesEditorView.data(), SLOT(removeState(int)));
}
StatesEditorWidget::StatesEditorWidget(StatesEditorView *statesEditorView, StatesEditorModel *statesEditorModel):
        QWidget(),
    m_declarativeView(new QDeclarativeView(this)),
    m_statesEditorView(statesEditorView),
    m_imageProvider(0)
{
    m_imageProvider = new Internal::StatesEditorImageProvider;
    m_imageProvider->setNodeInstanceView(statesEditorView->nodeInstanceView());
    m_declarativeView->engine()->addImageProvider(
            QLatin1String("qmldesigner_stateseditor"), m_imageProvider);

    m_declarativeView->setAcceptDrops(false);

    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->setMargin(0);
    layout->setSpacing(0);
    layout->addWidget(m_declarativeView.data());

    m_declarativeView->setResizeMode(QDeclarativeView::SizeRootObjectToView);

    m_declarativeView->rootContext()->setContextProperty(QLatin1String("statesEditorModel"), statesEditorModel);
    QColor highlightColor = palette().highlight().color();
    if (0.5*highlightColor.saturationF()+0.75-highlightColor.valueF() < 0)
        highlightColor.setHsvF(highlightColor.hsvHueF(),0.1 + highlightColor.saturationF()*2.0, highlightColor.valueF());
    m_declarativeView->rootContext()->setContextProperty(QLatin1String("highlightColor"), highlightColor);

    // Work around ASSERT in the internal QGraphicsScene that happens when
    // the scene is created + items set dirty in one event loop run (BAUHAUS-459)
    //QApplication::processEvents();

    m_declarativeView->setSource(QUrl("qrc:/stateseditor/stateslist.qml"));

    if (!m_declarativeView->rootObject())
        throw InvalidQmlSourceException(__LINE__, __FUNCTION__, __FILE__);

    m_declarativeView->setFocusPolicy(Qt::ClickFocus);
    QApplication::sendEvent(m_declarativeView->scene(), new QEvent(QEvent::WindowActivate));

    connect(m_declarativeView->rootObject(), SIGNAL(currentStateInternalIdChanged()), statesEditorView, SLOT(synchonizeCurrentStateFromWidget()));
    connect(m_declarativeView->rootObject(), SIGNAL(createNewState()), statesEditorView, SLOT(createNewState()));
    connect(m_declarativeView->rootObject(), SIGNAL(deleteState(int)), statesEditorView, SLOT(removeState(int)));

    setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));

    setWindowTitle(tr("States", "Title of Editor widget"));
}
Esempio n. 5
0
/**
    Searches for solution
*/
int solveFifteen()
{
    struct GameState *queue;
    int i;
    
    while (notEmptyPQ())
    {
        queue = getQueueTop();
        
        if (queue->manhattanDistance == 0)
        {
            printSolution(queue);
            
            for (i = 0; i < rows; i++)
            {
                free(queue->tilesPosition[i]);
            }
            free(queue->tilesPosition);
            free(queue->prev);
            queue->prev = NULL;
            
            /* deallocate memory */
            int pocet = 0;
            while (notEmptyPQ())
            {
                pocet++;
                free(queue);
                queue = NULL;
                queue = getQueueTop();
                for (i = 0; i < rows; i++)
                {
                    free(queue->tilesPosition[i]);
                }
                free(queue->tilesPosition);
                free(queue->prev);
                queue->prev = NULL;
            }
            printf("Ve fronte bylo %d\n", pocet);
            system("PAUSE");
            return 0;
        }
        else
        {
            int lastMove = getLastMove(queue);
            if (canMoveLeft(queue) && lastMove != MOVE_RIGHT)
            {
                struct GameState *s = createNewState(queue);
                if (s == NULL)
                {
                    return OUT_OF_MEMORY;    
                }
                moveLeft(s);
                s->manhattanDistance = getManhattanDistance(*s);
                insertPQ(s);
            }
            if (canMoveRight(queue) && lastMove != MOVE_LEFT)
            {
                struct GameState *s = createNewState(queue);
                if (s == NULL)
                {
                    return OUT_OF_MEMORY;    
                }
                moveRight(s);
                s->manhattanDistance = getManhattanDistance(*s);
                insertPQ(s);
            }
            if (canMoveUp(queue) && lastMove != MOVE_DOWN)
            {
                struct GameState *s = createNewState(queue);
                if (s == NULL)
                {
                    return OUT_OF_MEMORY;    
                }
                moveUp(s);
                s->manhattanDistance = getManhattanDistance(*s);
                insertPQ(s);
            }
            if (canMoveDown(queue) && lastMove != MOVE_UP)
            {
                struct GameState *s = createNewState(queue);
                if (s == NULL)
                {
                    return OUT_OF_MEMORY;    
                }
                moveDown(s);
                s->manhattanDistance = getManhattanDistance(*s);
                insertPQ(s);
            }
        }
        
    }
    return 1;
}