Exemple #1
0
void heapSort(int numbers[], int array_size)
{
  int i, temp;
  /* 自底向上构造最大堆*/
  for (i = (array_size / 2) - 1; i >= 0; i--)
    shiftDown(numbers, i, array_size);
  
  for (i = array_size-1; i >= 1; i--)
  {
    temp = numbers[0];
    numbers[0] = numbers[i];
    numbers[i] = temp;
    shiftDown(numbers, 0, i-1);
  }
}
Exemple #2
0
	void update(){
		for(int i=0;i<25;i++){
			for(int j=0;j<25;j++){
				board[i][j]->update1();
			}
		}
		for(int i=0;i<25;i++){
			for(int j=0;j<25;j++){
				board[i][j]->update2();
			}
		}
		
		
		if(board[12][12]->playerIsHere==false){
			//std::cout<<"ENTER LOOPS"<<std::endl;
			int pi=-1;
			int pj=-1;
			for(int i=0;i<25;i++){
				for(int j=0;j<25;j++){
					if(board[i][j]->playerIsHere){
						pi=i;
						pj=j;
					}
				}
			}
			if(pi==-1 || pj==-1)
				{std::cout<<"PLAYER SHIP LOST"<<std::endl; exit(1);}
			//std::cout<<pi<<","<<pj<<std::endl;
			while(pj<12){shiftRight();pj++;}
			while(pj>12){shiftLeft();pj--;}
			while(pi<12){shiftDown();pi++;}
			while(pi>12){shiftUp();pi--;}
			//std::cout<<pi<<","<<pj<<std::endl;
		}
	}
Exemple #3
0
minHeap_elem * pop(minHeap & min_h) {
    if ( min_h.size_ == 0 ) return NULL;
    minHeap_elem * res = min_h.vec_min_h.at(0);
    min_h.vec_min_h.at(0) = min_h.vec_min_h.at( min_h.size_ - 1 );
    min_h.vec_min_h.pop_back();
    min_h.size_--;
    shiftDown( min_h , 0 );
    return res;
}
Exemple #4
0
/*Shift k rows in given direction according to given Color of Piece at Location*/
int shiftRow(char board[BOARD_SIZE][BOARD_SIZE], Location *loc, MoveType type){
	switch (type)
	{
	case UR:case UL:case U:	return shiftUp(board, loc); break;
	case DL:case DR:case D:	return shiftDown(board, loc); break;
	case L:case R:return 0;
	}
	return 0;
}
 void insert(int val) {
     if(data.size() == size) {
         if(val > data[0]) {
             data[0] = val;
             shiftDown(0);
         }
     }
     else {
         data[size] = val;
         shiftUp(size);
         size++;
     }
 }
Exemple #6
0
void heapSort(/*int*/pelement items[], int array_size)
{

  heapify (items, array_size);

  int i;
  for (i = array_size; i >= 1; i--)  {
    items[0] = items[1];
    items[1] = items[i];
    items[i] = items[0];
    shiftDown(items, 1, i-1);
  }
}
//
//  REDRAW CONTENTS
//
void MainWin::drawContents(QPainter *painter)
{
    int deltay,i;

    QRect r = contentsRect();

    deltay = r.height() / CurvCnt - 1;

    r.setHeight(deltay);

    //
    //  draw curves
    //
    for (i=0;i<CurvCnt;i++)
    {
        xMap.setPaintInterval(r.left(), r.right());
        yMap.setPaintInterval(r.top(), r.bottom());

        painter->setRenderHint(QPainter::Antialiasing,
            d_curves[i].testRenderHint(QwtPlotItem::RenderAntialiased) );
        d_curves[i].draw(painter, xMap, yMap, r);

        shiftDown(r, deltay);
    }

    //
    // draw titles
    //
    r = contentsRect();     // reset r
    painter->setFont(QFont("Helvetica", 8));

    const int alignment = Qt::AlignTop|Qt::AlignHCenter;

    painter->setPen(Qt::black);

    painter->drawText(0,r.top(),r.width(), painter->fontMetrics().height(),
        alignment, "Style: Line/Fitted, Symbol: Cross");
    shiftDown(r, deltay);

    painter->drawText(0,r.top(),r.width(), painter->fontMetrics().height(),
        alignment, "Style: Sticks, Symbol: Ellipse");
    shiftDown(r, deltay);

    painter->drawText(0 ,r.top(),r.width(), painter->fontMetrics().height(),
        alignment, "Style: Lines, Symbol: None");
    shiftDown(r, deltay);

    painter->drawText(0 ,r.top(),r.width(), painter->fontMetrics().height(),
        alignment, "Style: Lines, Symbol: None, Antialiased");
    shiftDown(r, deltay);

    painter->drawText(0, r.top(),r.width(), painter->fontMetrics().height(),
        alignment, "Style: Steps, Symbol: None");
    shiftDown(r, deltay);

    painter->drawText(0,r.top(),r.width(), painter->fontMetrics().height(),
        alignment, "Style: NoCurve, Symbol: XCross");
}
void* removeMin(t_minHeap* h, t_comp c)
{
  void* ret;
  int i;
  if(h!=NULL&&size >0)
    {
      ret = h->heap[0];
      h->heap[0]=h->heap[h->size];
      h->size--;
      shiftDown(h, 0, c);
      for(i=0; i<h->size; i++)
	printf(" %d \n", i);
      return ret;
    }
  return 0;
}
Exemple #9
0
void shiftDown(int numbers[], int root, int heap_size)
{
  int largest,temp;
  if ((root*2 <= heap_size) && (numbers[root*2] > numbers[root]))
    largest = root * 2;
  else largest = root;
  if ((root*2 + 1 <= heap_size) && (numbers[root*2 + 1] > numbers[largest]))
    largest = root * 2 + 1;
  if (largest != root)
  {
    temp = numbers[root];
    numbers[root] = numbers[largest];
    numbers[largest] = temp;
    shiftDown(numbers,largest,heap_size);
  }
}
Exemple #10
0
ToolRot13::ToolRot13(QWidget *parent): 
  Tool(TOOLNAME, parent), m_textEdit(NULL), m_spinBox(NULL) {
  setWindowTitle(tr("Rot13/Cesar"));

  QWidget *mainWidget = new QWidget;
  QVBoxLayout *mainLayout = new QVBoxLayout;
  mainWidget->setLayout(mainLayout);

  QSettings settings;
  settings.beginGroup("Tools/" TOOLNAME);
  QString text = settings.value("text").toString();

  m_textEdit = new QTextEdit(text, this);
#ifdef FLICKCHARM
  new FlickCharm(m_textEdit, this);
#endif

  mainLayout->addWidget(m_textEdit);

  // create button box below
  QWidget *controlWidget = new QWidget;
  QHBoxLayout *controlLayout = new QHBoxLayout;
  controlWidget->setLayout(controlLayout);

  QPushButton *downButton = new QPushButton("-");
  connect(downButton, SIGNAL(clicked()), this, SLOT(shiftDown()));
  controlLayout->addWidget(downButton);

  m_spinBox = new QSpinBox();
  m_spinBox->setRange(1, 25);
  m_spinBox->setValue(settings.value("step").toInt());
  controlLayout->addWidget(m_spinBox);

  QPushButton *upButton = new QPushButton("+");
  connect(upButton, SIGNAL(clicked()), this, SLOT(shiftUp()));
  controlLayout->addWidget(upButton);

  QPushButton *rot13Button = new QPushButton(tr("Rot13"));
  connect(rot13Button, SIGNAL(clicked()), this, SLOT(rot13()));
  controlLayout->addWidget(rot13Button);

  mainLayout->addWidget(controlWidget);
  
  setCentralWidget(mainWidget);

  settings.endGroup();
}
 void shiftDown(int k) {
     int min = data[k];
     int minIndex = k;
     int left = 2*k+1;
     int right = 2*k+2;
     if(left < size && data[left] < min) {
         min = data[left];
         minIndex = left;
     }
     if(right < size && data[right] < min) {
         min = data[right];
         minIndex = right;
     }
     if(minIndex != k) {
         swap(data[k], data[minIndex]);
         shiftDown(minIndex);
     }
 }
Exemple #12
0
void shiftDown(t_minHeap* h, int rootIndex, t_comp c)
{
  int lc;
  void* temp;

  if(rootIndex >=0)
    {
      lc=getLeftChildIndex(rootIndex);
      if(lc<h->size)
	{
	  if((lc+1)<h->size && c(h->heap[(lc+1)] , h->heap[lc]) <0)
	    lc++;
	  if(c(h->heap[rootIndex] , h->heap[lc])>0)
	    {
	      temp = h->heap[rootIndex];
	      h->heap[rootIndex]=h->heap[lc];
	      h->heap[lc] = temp;

	      shiftDown(h, lc, c);
	    }
	}
    }
}
Exemple #13
0
//
//  REDRAW CONTENTS
//
void arnMulVectorPlot::drawContents(QPainter *painter)
{
    int deltay;

    QRect r = contentsRect();

    deltay = r.height() / NumOfPlot -1;

    r.setHeight(deltay);

    //
    //  draw curve
    //
    for (int i = 0; i < NumOfPlot; i++) {
        xMap[i].setPaintInterval(r.left(), r.right());
        yMap[i].setPaintInterval(r.bottom(),r.top());

        painter->setRenderHint(QPainter::Antialiasing,d_curves[i].testRenderHint(QwtPlotItem::RenderAntialiased) );
        d_curves[i].draw(painter, xMap[i], yMap[i], r);

        shiftDown(r, deltay);
        }

}
Exemple #14
0
MainWindow::MainWindow(const QString& initialFilename, QWidget *parent) :
    QMainWindow(parent),
    m_appSettings("OpenSource", "Sproxel"),
    m_activeFilename(""),
    m_project(new SproxelProject())
{
    // Project
    VoxelGridGroupPtr sprite(new VoxelGridGroup(Imath::V3i(DEFAULT_VOXGRID_SZ, DEFAULT_VOXGRID_SZ, DEFAULT_VOXGRID_SZ),
      ColorPalettePtr()));
    sprite->setName("unnamed");
    m_project->sprites.push_back(sprite);

    // Windows
    m_glModelWidget = new GLModelWidget(this, &m_appSettings, &m_undoManager, sprite);
    setCentralWidget(m_glModelWidget);

    // The docking palette widget
    m_paletteDocker = new QDockWidget(tr("Palette"), this);
    m_paletteDocker->setObjectName("paletteDocker");
    m_paletteDocker->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    m_paletteWidget = new PaletteWidget(this, &m_undoManager);
    m_paletteDocker->setWidget(m_paletteWidget);
    m_paletteWidget->setPalette(m_project->mainPalette);
    addDockWidget(Qt::RightDockWidgetArea, m_paletteDocker);

    // The docking project widget
    m_projectDocker=new QDockWidget(tr("Project"), this);
    m_projectDocker->setObjectName("projectDocker");
    m_projectWidget=new ProjectWidget(this, &m_undoManager, &m_appSettings);
    m_projectDocker->setWidget(m_projectWidget);
    m_projectWidget->setProject(m_project);
    addDockWidget(Qt::RightDockWidgetArea, m_projectDocker);

    // The docking layers widget
    //m_layersDocker = new QDockWidget(tr("Layers"), this);
    //m_layersDocker->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    //m_layersWidget = new LayersWidget(this);
    //m_layersDocker->setWidget(m_layersWidget);
    //addDockWidget(Qt::RightDockWidgetArea, m_layersDocker);

    // Connect some window signals together
    QObject::connect(m_paletteWidget, SIGNAL(activeColorChanged(Imath::Color4f, int)),
                     m_glModelWidget, SLOT(setActiveColor(Imath::Color4f, int)));
    QObject::connect(m_glModelWidget, SIGNAL(colorSampled(Imath::Color4f, int)),
                     m_paletteWidget, SLOT(setActiveColor(Imath::Color4f, int)));
    QObject::connect(&m_undoManager, SIGNAL(cleanChanged(bool)),
                     this, SLOT(reactToModified(bool)));

    QObject::connect(m_projectWidget, SIGNAL(spriteSelected(VoxelGridGroupPtr)),
      m_glModelWidget, SLOT(setSprite(VoxelGridGroupPtr)));


    // Toolbar
    m_toolbar = new QToolBar("Tools", this);
    m_toolbar->setObjectName("toolbar");
    m_toolbar->setOrientation(Qt::Vertical);
    addToolBar(Qt::LeftToolBarArea, m_toolbar);


    // Actions & Menus
    menuBar()->show();
    m_menuFile = menuBar()->addMenu("Fi&le");

    m_actFileNew = new QAction("&New", this);
    m_actFileNew->setShortcut(Qt::CTRL + Qt::Key_N);
    m_menuFile->addAction(m_actFileNew);
    connect(m_actFileNew, SIGNAL(triggered()),
            this, SLOT(newGrid()));

    m_menuFile->addSeparator();

    m_actFileOpen = new QAction("&Open", this);
    m_actFileOpen->setShortcut(Qt::CTRL + Qt::Key_O);
    m_menuFile->addAction(m_actFileOpen);
    connect(m_actFileOpen, SIGNAL(triggered()),
            this, SLOT(openFile()));

    m_actFileSave = new QAction("&Save", this);
    m_actFileSave->setShortcut(Qt::CTRL + Qt::Key_S);
    m_menuFile->addAction(m_actFileSave);
    connect(m_actFileSave, SIGNAL(triggered()),
            this, SLOT(saveFile()));

    m_actFileSaveAs = new QAction("Save &As", this);
    m_menuFile->addAction(m_actFileSaveAs);
    connect(m_actFileSaveAs, SIGNAL(triggered()),
            this, SLOT(saveFileAs()));

    m_menuFile->addSeparator();

    m_actFileImport = new QAction("&Import...", this);
    m_menuFile->addAction(m_actFileImport);
    connect(m_actFileImport, SIGNAL(triggered()),
            this, SLOT(import()));

    m_actFileExportGrid = new QAction("&Export...", this);
    m_menuFile->addAction(m_actFileExportGrid);
    connect(m_actFileExportGrid, SIGNAL(triggered()),
            this, SLOT(exportGrid()));

    m_menuFile->addSeparator();

    m_actQuit = new QAction("&Quit", this);
    m_actQuit->setShortcut(Qt::CTRL + Qt::Key_Q);
    m_menuFile->addAction(m_actQuit);
    connect(m_actQuit, SIGNAL(triggered()),
            this, SLOT(close()));


    // ------ edit menu
    m_menuEdit = menuBar()->addMenu("&Edit");

    m_actUndo=m_undoManager.createUndoAction(this, "Undo");
    m_actUndo->setShortcut(Qt::CTRL + Qt::Key_Z);
    m_menuEdit->addAction(m_actUndo);

    m_actRedo=m_undoManager.createRedoAction(this, "Redo");
    m_actRedo->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Z);
    m_menuEdit->addAction(m_actRedo);

    m_menuEdit->addSeparator();

    m_actShiftUp = new QAction("Shift up", this);
    m_actShiftUp->setShortcut(Qt::CTRL + Qt::Key_BracketRight);
    m_menuEdit->addAction(m_actShiftUp);
    connect(m_actShiftUp, SIGNAL(triggered()),
            this, SLOT(shiftUp()));

    m_actShiftDown = new QAction("Shift down", this);
    m_actShiftDown->setShortcut(Qt::CTRL + Qt::Key_BracketLeft);
    m_menuEdit->addAction(m_actShiftDown);
    connect(m_actShiftDown, SIGNAL(triggered()),
            this, SLOT(shiftDown()));

    m_actShiftWrap = new QAction("Wrap shift ops", this);
    m_actShiftWrap->setCheckable(true);
    m_actShiftWrap->setChecked(m_glModelWidget->shiftWrap());
    m_menuEdit->addAction(m_actShiftWrap);
    connect(m_actShiftWrap, SIGNAL(toggled(bool)),
            m_glModelWidget, SLOT(setShiftWrap(bool)));

    m_actRotateCw = new QAction("Rotate clockwise", this);
    m_actRotateCw->setShortcut(Qt::CTRL + Qt::Key_Greater);
    m_menuEdit->addAction(m_actRotateCw);
    connect(m_actRotateCw, SIGNAL(triggered()),
            this, SLOT(rotateCw()));

    m_actRotateCcw = new QAction("Rotate counter-clockwise", this);
    m_actRotateCcw->setShortcut(Qt::CTRL + Qt::Key_Less);
    m_menuEdit->addAction(m_actRotateCcw);
    connect(m_actRotateCcw, SIGNAL(triggered()),
            this, SLOT(rotateCcw()));

    m_actMirror = new QAction("Mirror", this);
    m_actMirror->setShortcut(Qt::CTRL + Qt::Key_M);
    m_menuEdit->addAction(m_actMirror);
    connect(m_actMirror, SIGNAL(triggered()),
            this, SLOT(mirror()));

    m_menuEdit->addSeparator();

    m_actPreferences = new QAction("Preferences...", this);
    m_menuEdit->addAction(m_actPreferences);
    connect(m_actPreferences, SIGNAL(triggered()),
            this, SLOT(editPreferences()));


    // ------ grid menu
    m_menuGrid = menuBar()->addMenu("&Grid");

    m_actExtendUp = new QAction("Extend grid dimension up", this);
    m_actExtendUp->setShortcut(Qt::CTRL + Qt::Key_Plus);
    m_menuGrid->addAction(m_actExtendUp);
    connect(m_actExtendUp, SIGNAL(triggered()),
            this, SLOT(extendUp()));

    m_actExtendDown = new QAction("Extend grid dimension down", this);
    m_actExtendDown->setShortcut(Qt::CTRL + Qt::Key_Minus);
    m_menuGrid->addAction(m_actExtendDown);
    connect(m_actExtendDown, SIGNAL(triggered()),
            this, SLOT(extendDown()));

    m_actContractUp = new QAction("Contract grid dimension from above", this);
    m_menuGrid->addAction(m_actContractUp);
    connect(m_actContractUp, SIGNAL(triggered()),
            this, SLOT(contractUp()));

    m_actContractDown = new QAction("Contract grid dimension from below", this);
    m_menuGrid->addAction(m_actContractDown);
    connect(m_actContractDown, SIGNAL(triggered()),
            this, SLOT(contractDown()));

    m_menuGrid->addSeparator();

    m_actUpRes = new QAction("Double grid resolution", this);
    m_menuGrid->addAction(m_actUpRes);
    connect(m_actUpRes, SIGNAL(triggered()),
            this, SLOT(upRes()));

    m_actDownRes = new QAction("Half grid resolution", this);
    m_menuGrid->addAction(m_actDownRes);
    connect(m_actDownRes, SIGNAL(triggered()),
            this, SLOT(downRes()));


    // ------ view menu
    m_menuView = menuBar()->addMenu("&View");

    QAction *action=new QAction(tr("Frame sprite"), this);
    action->setShortcut(Qt::Key_Z);
    m_menuView->addAction(action);
    connect(action, SIGNAL(triggered()),
      m_glModelWidget, SLOT(frameFull()));

    m_actViewGrid = new QAction("View Grid", this);
    m_actViewGrid->setShortcut(Qt::CTRL + Qt::Key_G);
    m_actViewGrid->setCheckable(true);
    m_actViewGrid->setChecked(m_glModelWidget->drawGrid());
    m_menuView->addAction(m_actViewGrid);
    connect(m_actViewGrid, SIGNAL(toggled(bool)),
            m_glModelWidget, SLOT(setDrawGrid(bool)));

    m_actViewVoxgrid = new QAction("Voxel Grid", this);
    m_actViewVoxgrid->setShortcut(Qt::Key_G);
    m_actViewVoxgrid->setCheckable(true);
    m_actViewVoxgrid->setChecked(m_glModelWidget->drawVoxelGrid());
    m_menuView->addAction(m_actViewVoxgrid);
    connect(m_actViewVoxgrid, SIGNAL(toggled(bool)),
            m_glModelWidget, SLOT(setDrawVoxelGrid(bool)));

    m_actViewBBox = new QAction("Bounding Box", this);
    m_actViewBBox->setShortcut(Qt::CTRL + Qt::Key_B);
    m_actViewBBox->setCheckable(true);
    m_actViewBBox->setChecked(m_glModelWidget->drawBoundingBox());
    m_menuView->addAction(m_actViewBBox);
    connect(m_actViewBBox, SIGNAL(toggled(bool)),
            m_glModelWidget, SLOT(setDrawBoundingBox(bool)));

    action=new QAction("Sprite Bounds", this);
    action->setShortcut(Qt::Key_B);
    action->setCheckable(true);
    action->setChecked(m_glModelWidget->drawSpriteBounds());
    m_menuView->addAction(action);
    connect(action, SIGNAL(toggled(bool)),
            m_glModelWidget, SLOT(setDrawSpriteBounds(bool)));


    // ------ window menu
    m_menuWindow = menuBar()->addMenu("&Window");
    m_menuWindow->addAction(m_toolbar->toggleViewAction());
    m_menuWindow->addAction(m_paletteDocker->toggleViewAction());
    m_menuWindow->addAction(m_projectDocker->toggleViewAction());
    //m_menuWindow->addAction(m_layersDocker->toggleViewAction());
    m_menuWindow->addAction(get_python_console_widget()->toggleViewAction());
    get_python_console_widget()->toggleViewAction()->setChecked(false);


    // ------ toolbar hookups
    // Icons from the brilliant icon pack located at : http://pen-art.ru/
    m_toolbarActionGroup = new QActionGroup(this);

    m_actToolSplat = new QAction("Splat", m_toolbarActionGroup);
    m_actToolSplat->setIcon(QIcon(QPixmap(":/icons/splat.png")));
    m_actToolSplat->setCheckable(true);
    connect(m_actToolSplat, SIGNAL(toggled(bool)), this, SLOT(setToolSplat(bool)));

    m_actToolReplace = new QAction("Replace", m_toolbarActionGroup);
    m_actToolReplace->setIcon(QIcon(QPixmap(":/icons/pencil.png")));
    m_actToolReplace->setCheckable(true);
    connect(m_actToolReplace, SIGNAL(toggled(bool)), this, SLOT(setToolReplace(bool)));

    m_actToolFlood = new QAction("Flood", m_toolbarActionGroup);
    m_actToolFlood->setIcon(QIcon(QPixmap(":/icons/paintBucket.png")));
    m_actToolFlood->setCheckable(true);
    connect(m_actToolFlood, SIGNAL(toggled(bool)), this, SLOT(setToolFlood(bool)));

    m_actToolDropper = new QAction("Dropper", m_toolbarActionGroup);
    m_actToolDropper->setIcon(QIcon(QPixmap(":/icons/eyeDropper.png")));
    m_actToolDropper->setCheckable(true);
    connect(m_actToolDropper, SIGNAL(toggled(bool)), this, SLOT(setToolDropper(bool)));

    m_actToolEraser = new QAction("Eraser", m_toolbarActionGroup);
    m_actToolEraser->setIcon(QIcon(QPixmap(":/icons/eraser.png")));
    m_actToolEraser->setCheckable(true);
    connect(m_actToolEraser, SIGNAL(toggled(bool)), this, SLOT(setToolEraser(bool)));

    m_actToolSlab = new QAction("Slab", m_toolbarActionGroup);
    m_actToolSlab->setIcon(QIcon(QPixmap(":/icons/slab.png")));
    m_actToolSlab->setCheckable(true);
    connect(m_actToolSlab, SIGNAL(toggled(bool)), this, SLOT(setToolSlab(bool)));

    m_actToolLine = new QAction("Line", m_toolbarActionGroup);
    m_actToolLine->setIcon(QIcon(QPixmap(":/icons/line.png")));
    m_actToolLine->setCheckable(true);
    connect(m_actToolLine, SIGNAL(toggled(bool)), this, SLOT(setToolLine(bool)));

    m_actToolBox = new QAction("Box", m_toolbarActionGroup);
    m_actToolBox->setIcon(QIcon(QPixmap(":/icons/box.png")));
    m_actToolBox->setCheckable(true);
    connect(m_actToolBox, SIGNAL(toggled(bool)), this, SLOT(setToolBox(bool)));

    m_actToolExtrude = new QAction("Extrude", m_toolbarActionGroup);
    m_actToolExtrude->setIcon(QIcon(QPixmap(":/icons/extrude.png")));
    m_actToolExtrude->setCheckable(true);
    connect(m_actToolExtrude, SIGNAL(toggled(bool)), this, SLOT(setToolExtrude(bool)));

    //m_actToolRay = new QAction("Ray", this);

    m_actToolSplat->setChecked(true);
    m_toolbar->addActions(m_toolbarActionGroup->actions());


    // Toolbar widgets for slicing
    m_toolbar->addSeparator();
    m_minSliceBox=new QSpinBox();
    m_maxSliceBox=new QSpinBox();
    m_toolbar->addWidget(m_maxSliceBox);
    m_toolbar->addWidget(m_minSliceBox);

    connect(m_glModelWidget, SIGNAL(sliceChanged(int, int, int)), this, SLOT(updateSlice(int, int, int)));
    connect(m_minSliceBox, SIGNAL(valueChanged(int)), m_glModelWidget, SLOT(setMinSlice(int)));
    connect(m_maxSliceBox, SIGNAL(valueChanged(int)), m_glModelWidget, SLOT(setMaxSlice(int)));

    // axis selection
    QActionGroup *axisGroup=new QActionGroup(this);

    QAction *a=new QAction("X", axisGroup);
    a->setCheckable(true);
    connect(a, SIGNAL(toggled(bool)), m_glModelWidget, SLOT(setAxisX()));
    m_actAxisX=a;

    a=new QAction("Y", axisGroup);
    a->setCheckable(true);
    connect(a, SIGNAL(toggled(bool)), m_glModelWidget, SLOT(setAxisY()));
    m_actAxisY=a;

    a=new QAction("Z", axisGroup);
    a->setCheckable(true);
    connect(a, SIGNAL(toggled(bool)), m_glModelWidget, SLOT(setAxisZ()));
    m_actAxisZ=a;

    m_toolbar->addSeparator();
    m_toolbar->addActions(axisGroup->actions());

    m_actAxisY->setChecked(true);


    // Remaining verbosity
    setWindowTitle(BASE_WINDOW_TITLE);
    statusBar()->showMessage(tr("Ready"));

    // Load up some settings
    if (m_appSettings.value("saveUILayout", true).toBool())
    {
        resize(m_appSettings.value("MainWindow/size", QSize(546, 427)).toSize());
        move(m_appSettings.value("MainWindow/position", QPoint(200, 200)).toPoint());
        setWindowState((Qt::WindowStates)m_appSettings.value("MainWindow/windowState", Qt::WindowActive).toInt());
        restoreState(m_appSettings.value("MainWindow/widgetsState").toByteArray());
        m_toolbar->setVisible(m_appSettings.value("toolbar/visibility", true).toBool());
        m_paletteDocker->setVisible(m_appSettings.value("paletteWindow/visibility", true).toBool());
        m_projectDocker->setVisible(m_appSettings.value("projectWindow/visibility", true).toBool());
        //m_layersDocker->setVisible(m_appSettings.value("layersWindow/visibility", true).toBool());
    }

    // Load the commandline supplied filename
    if (initialFilename != "")
    {
        openFile(initialFilename);
    }

    // Better way to keep the state in one place
    //std::cout << (m_toolbarActionGroup->checkedAction()->text() == "Splat") << std::endl;
    //std::cout << qPrintable(m_toolbarActionGroup->checkedAction()->text()) << std::endl;

    // Start things off focused on the GLWidget
    m_glModelWidget->setFocus();
}
Exemple #15
0
dlgMapper::dlgMapper( QWidget * parent, Host * pH, TMap * pM )
: QWidget( parent )
, mpMap( pM )
, mpHost( pH )
{
    setupUi(this);
    glWidget->mpMap = pM;
    mp2dMap->mpMap = pM;
    mp2dMap->mpHost = pH;
    repopulateAreas();

    bubbles->setChecked( mpHost->mBubbleMode );
    mp2dMap->mBubbleMode = mpHost->mBubbleMode;

    d3buttons->setVisible(false);
    roomSize->setValue(mpHost->mRoomSize*10);
    lineSize->setValue(mpHost->mLineSize);

    showInfo->setChecked( mpHost->mShowInfo );
    mp2dMap->mShowInfo = mpHost->mShowInfo;

    showRoomIDs->setChecked( mpHost->mShowRoomID );
    mp2dMap->mShowRoomID = mpHost->mShowRoomID;

    panel->setVisible(mpHost->mShowPanel);

    //searchList->setSelectionMode( QAbstractItemView::SingleSelection );
    //connect(roomID, SIGNAL(returnPressed()), this, SLOT(goRoom()));
    connect(bubbles, SIGNAL(clicked()), this, SLOT(slot_bubbles()));
    connect(showInfo, SIGNAL(clicked()), this, SLOT(slot_info()));
    connect(ortho, SIGNAL(pressed()), glWidget, SLOT(fullView()));
    connect(singleLevel, SIGNAL(pressed()), glWidget, SLOT(singleView()));
    connect(increaseTop, SIGNAL(pressed()), glWidget, SLOT(increaseTop()));
    connect(increaseBottom, SIGNAL(pressed()), glWidget, SLOT(increaseBottom()));
    connect(reduceTop, SIGNAL(pressed()), glWidget, SLOT(reduceTop()));
    connect(reduceBottom, SIGNAL(pressed()), glWidget, SLOT(reduceBottom()));
    //connect(searchList, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(choseRoom(QListWidgetItem*)));
    connect(shiftZup, SIGNAL(pressed()), mp2dMap, SLOT(shiftZup()));
    connect(shiftZdown, SIGNAL(pressed()), mp2dMap, SLOT(shiftZdown()));
    connect(shiftLeft, SIGNAL(pressed()), mp2dMap, SLOT(shiftLeft()));
    connect(shiftRight, SIGNAL(pressed()), mp2dMap, SLOT(shiftRight()));
    connect(shiftUp, SIGNAL(pressed()), mp2dMap, SLOT(shiftUp()));
    connect(shiftDown, SIGNAL(pressed()), mp2dMap, SLOT(shiftDown()));

    connect(shiftZup, SIGNAL(pressed()), glWidget, SLOT(shiftZup()));
    connect(shiftZdown, SIGNAL(pressed()), glWidget, SLOT(shiftZdown()));
    connect(shiftLeft, SIGNAL(pressed()), glWidget, SLOT(shiftLeft()));
    connect(shiftRight, SIGNAL(pressed()), glWidget, SLOT(shiftRight()));
    connect(shiftUp, SIGNAL(pressed()), glWidget, SLOT(shiftUp()));
    connect(shiftDown, SIGNAL(pressed()), glWidget, SLOT(shiftDown()));
    connect(showInfo, SIGNAL(clicked()), glWidget, SLOT(showInfo()));
    connect(showArea, SIGNAL(activated(QString)), mp2dMap, SLOT(switchArea(QString)));
    connect(showArea, SIGNAL(activated(QString)), glWidget, SLOT(showArea(QString)));
    connect(defaultView, SIGNAL(pressed()), glWidget, SLOT(defaultView()));
    connect(dim2,SIGNAL(pressed()), this, SLOT(show2dView()));
    connect(sideView, SIGNAL(pressed()), glWidget, SLOT(sideView()));
    connect(topView, SIGNAL(pressed()), glWidget, SLOT(topView()));
    connect(togglePanel, SIGNAL(pressed()), this, SLOT(slot_togglePanel()));
    connect(lineSize, SIGNAL(valueChanged(int)), this, SLOT(slot_lineSize(int)));
    connect(roomSize, SIGNAL(valueChanged(int)), this, SLOT(slot_roomSize(int)));
    connect(scale, SIGNAL(valueChanged(int)), glWidget, SLOT(setScale(int)));
    connect(xRot, SIGNAL(valueChanged(int)), glWidget, SLOT(setXRotation(int)));
    connect(yRot, SIGNAL(valueChanged(int)), glWidget, SLOT(setYRotation(int)));
    connect(zRot, SIGNAL(valueChanged(int)), glWidget, SLOT(setZRotation(int)));
    mpDownloader = new QNetworkAccessManager( this );
    connect(mpDownloader, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*)));
    connect(showRoomIDs, SIGNAL(stateChanged(int)), this, SLOT(slot_toggleShowRoomIDs(int)));
    mp2dMap->mFontHeight = QFontMetrics( mpHost->mDisplayFont ).height();
    glWidget->hide();
    mpMap->customEnvColors[257] = mpHost->mRed_2;
    mpMap->customEnvColors[258] = mpHost->mGreen_2;
    mpMap->customEnvColors[259] = mpHost->mYellow_2;
    mpMap->customEnvColors[260] = mpHost->mBlue_2;
    mpMap->customEnvColors[261] = mpHost->mMagenta_2;
    mpMap->customEnvColors[262] = mpHost->mCyan_2;
    mpMap->customEnvColors[263] = mpHost->mWhite_2;
    mpMap->customEnvColors[264] = mpHost->mBlack_2;
    mpMap->customEnvColors[265] = mpHost->mLightRed_2;
    mpMap->customEnvColors[266] = mpHost->mLightGreen_2;
    mpMap->customEnvColors[267] = mpHost->mLightYellow_2;
    mpMap->customEnvColors[268] = mpHost->mLightBlue_2;
    mpMap->customEnvColors[269] = mpHost->mLightMagenta_2;
    mpMap->customEnvColors[270] = mpHost->mLightCyan_2;
    mpMap->customEnvColors[271] = mpHost->mLightWhite_2;
    mpMap->customEnvColors[272] = mpHost->mLightBlack_2;
    mp2dMap->init();
}
Exemple #16
0
void heapify(/*int*/pelement items[], int array_size) {
    int i;
    for (i = (array_size/2); i >= 1; i--) {
        shiftDown(items, i, array_size);
    }
}
Exemple #17
0
void makeHeap(minHeap & min_h) {
    for (int i = min_h.size_/2 - 1 ; i >= 0 ; i--) {
        shiftDown(min_h , i);
    }
}
Exemple #18
0
void run(int col) {
	compute(col);
	printf("\nBUFFER   = %d\n", BUFF);
	printf("COLUMNS  = %d\n", COLS);
	printf("ROWS     = %d\n", ROWS);
	printf("FULL     = %d\n", FULL);
	printf("END      = %d\n", END);
	printf("SIZE     = %d\n\n", SIZE);

	int *array = allocate(FULL);
	printf("\n");
	init_data(array);

	if(toPr) { 
		printf("\nINITIAL LIST WITH BUFFER\n");
		shiftUp();
		print(array);
		shiftDown();
	}

	printf("\n\nSTEP 1: Sort: ");
	//STEP 1
	if(nThreads > 1) psort(array, nThreads); //Sort using parallel insertion sort
		else insort(array); //Sort using serial insertion sort
	if(toPr) print(array);

	printf("\nSTEP 2: Transpose Up: ");
	//STEP 2
	array = transposeUp(array);
	if(toPr) print(array);

	printf("\nSTEP 3: Sort: ");
	//STEP 3
	if(nThreads > 1) psort(array, nThreads); //Sort using parallel insertion sort
		else insort(array); //Sort using serial insertion sort
	if(toPr) print(array);

	printf("\nSTEP 4: Transpose Down: ");
	//STEP 4
	array = transposeDown(array);
	if(toPr) print(array);

	printf("\nSTEP 5: Sort: ");
	//STEP 5
	if(nThreads > 1) psort(array, nThreads); //Sort using parallel insertion sort
		else insort(array); //Sort using serial insertion sort
	if(toPr) print(array);

	printf("\nSTEP 6: Shift Up: ");
	//STEP 6
	shiftUp();
	if(toPr) print(array);

	printf("\nSTEP 7: Sort: ");
	//STEP 7
	if(nThreads > 1) psort(array, nThreads); //Sort using parallel insertion sort
		else insort(array); //Sort using serial insertion sort
	if(toPr) print(array);

	printf("\nSTEP 8: Shift Down: ");
	//STEP 8
	shiftDown();
	if(toPr) print(array);
	printf("\n");
	
	if(isSorted(array)){
		printf("Array is sorted!\n\n");
	} else {
		printf("Array not sorted!\n\n");
	}
	
	free(array);
}
Exemple #19
0
bool Node::aStarVisit(std::deque<Node*>* deque, std::vector<bool>* visitedNodes)
{
    visitedNodes->at(stateNumber) = true;
    showFile();


    if (gameWon())
    {
        return true;
    }
    

    if (Node* n = shiftLeft())
    {
        if (n->notVisited(visitedNodes))
        {
            //n->setHeight(height+1);
            deque->push_back(n);
            child.push_back(n);
        }
        else
        {
            delete n;
        }
    }

    if (Node* n = shiftUp())
    {
        if (n->notVisited(visitedNodes))
        {
            //n->setHeight(height+1);
            deque->push_back(n);
            child.push_back(n);
        }
        else
        {
            delete n;
        }
    }

    if (Node* n = shiftRight())
    {
        if (n->notVisited(visitedNodes))
        {
            //n->setHeight(height+1);
            deque->push_back(n);
            child.push_back(n);
        }
        else
        {
            delete n;
        }
    }

    if (Node* n = shiftDown())
    {
        if (n->notVisited(visitedNodes))
        {
            //n->setHeight(height+1);
            deque->push_back(n);
            child.push_back(n);
        }
        else
        {
            delete n;
        }
    }
	
	
    return false;
}
Exemple #20
0
uint16_t getValueFromBits(uint16_t extractFrom, int high, int length) 
{
   int low= high-length +1;
   uint16_t mask = createMask(low ,high);
   return shiftDown(extractFrom & mask, low); 
}
Exemple #21
0
// returns true if this node or a descendent is the goal
bool Node::depthVisit(std::vector<Node*>* vector, std::vector<bool>* visitedNodes)
{
    visitedNodes->at(stateNumber) = true;
    //showFile();


    if (gameWon())
    {
        vector->pop_back();
        return true;
    }



    if (Node* n = shiftLeft())
    {
        if (n->notVisited(visitedNodes))
        {
            child.push_back(n);
            vector->push_back(n);
            //n->setHeight(height+1);

            // if this child or a descendant is the goal stop returns true
            if (vector->back()->depthVisit(vector, visitedNodes))
            {
                vector->pop_back();
                return true;
            }
        }
        else
        {
            delete n;
        }
    }

    if (Node* n = shiftUp())
    {
        if (n->notVisited(visitedNodes))
        {
            child.push_back(n);
            vector->push_back(n);
            //n->setHeight(height+1);

            // if this child or a descendant is the goal stop returns true
            if (vector->back()->depthVisit(vector, visitedNodes))
            {
                vector->pop_back();
                return true;
            }
        }
        else
        {
            delete n;
        }
    }

    if (Node* n = shiftRight())
    {
        if (n->notVisited(visitedNodes))
        {
            child.push_back(n);
            vector->push_back(n);
            //n->setHeight(height+1);

            // if this child or a descendant is the goal stop returns true
            if (vector->back()->depthVisit(vector, visitedNodes))
            {
                vector->pop_back();
                return true;
            }
        }
        else
        {
            delete n;
        }
    }

    if (Node* n = shiftDown())
    {
        if (n->notVisited(visitedNodes))
        {
            child.push_back(n);
            vector->push_back(n);
            //n->setHeight(height+1);

            // if this child or a descendant is the goal stop returns true
            if (vector->back()->depthVisit(vector, visitedNodes))
            {
                vector->pop_back();
                return true;
            }
        }
        else
        {
            delete n;
        }
    }


    vector->pop_back();
    return false;
}
Exemple #22
0
int main(void) {
    int addScore, position, pauseSel;

    // Initializations
    PLL_Init();  			// Clock set at 80 MHz
    LCD_Init();
    Board_Init();
    Input_Init();
    DAC_Init();
    Random_Init(NVIC_ST_CURRENT_R);
    Timer2_Init(80000000); 	// time interrupt
    Timer1_Init(2000);		// sound interrupt
    EnableInterrupts();
    generateRandomTile();
    drawAllTiles();
    writeScore(0);
    writeHighscore(0);
    writeTime(0);
    displayHighestTile();

    while(1) {

        // draw arrow if ready
        if (arrowReady == 1) {
            // acknowledge flag
            arrowReady = 0;
            // draw arrow
            drawArrow();
        }

        // write time if ready
        if (timeReady == 1) {
            // acknowledge flag
            timeReady = 0;
            // write time
            writeTime(elapsedTime);
        }

        // Play mode and button1 is pushed
        if(Button1 && !pauseMode && !gameOver) {
            // Play sound
            playSound = 1;
            // shift and merge tiles towards arrow
            position = getSliderPosition();
            if (position == 1) {
                shiftLeft();
                addScore = mergeLeft();
                shiftLeft();
            }
            else if (position == 2) {
                shiftUp();
                addScore = mergeUp();
                shiftUp();
            }
            else if (position == 3) {
                shiftRight();
                addScore = mergeRight();
                shiftRight();
            }
            else {
                shiftDown();
                addScore = mergeDown();
                shiftDown();
            }

            eraseBoard();
            drawAllTiles();

            // update score
            score += addScore;
            addScore = 0;
            writeScore(score);
            displayHighestTile();

            // delay before adding new tile
            delay(200);

            // create new tile
            if (countEmptyTiles() != 0) {
                generateRandomTile();
            }
            drawAllTiles();

            // update highest tile image
            displayHighestTile();

            // check if game over
            if (checkGameOver() == 1) {
                gameOver = 1;
            }

            // unset flag
            Button1 = 0;
        }

        // button 2 is pause
        else if (Button2 && !gameOver && !pauseMode) {
            pauseMode = 1;
            pauseSel = 0;

            // disable arrow and timer
            NVIC_ST_CTRL_R = 0;
            TIMER2_CTL_R = 0x00000000;
            LCD_DrawFilledRect(prevX,prevY,20,20,BLACK);

            // draw pause mode screen
            drawPauseMode();

            // acknowledge button
            Button2 = 0;

            // wait until button is pushed
            while (pauseMode) {

                // Button 1 selects current pause selection button
                if (Button1) {

                    // acknowledge button
                    Button1 = 0;
                    Button2 = 0;
                    pauseMode = 0;

                    // if pause selection = "continue" (pauseSel = 0), continue with game
                    if (pauseSel == 0) {

                        // redraw screen
                        eraseBoard();
                        drawAllTiles();

                        // enable gameplay
                        NVIC_ST_CTRL_R = 0x07;
                        TIMER2_CTL_R = 0x00000001;
                    }

                    // if pause selection = "restart" (pauseSel = 0), end game
                    else if (pauseSel == 1) {
                        if (score > highscore) {
                            writeHighscore(score);
                        }
                        score = 0;
                        eraseScore();
                        writeScore(0);
                        clearBoard();
                        eraseBoard();
                        pauseMode = 0;
                        generateRandomTile();
                        drawAllTiles();
                        elapsedTime = 0;
                        eraseTime();
                        writeTime(0);
                        displayHighestTile();
                        NVIC_ST_CTRL_R = 0x07;
                        TIMER2_CTL_R = 0x00000001;
                    }
                }

                // Button 2 changes pause selection
                else if (Button2) {
                    Button2 = 0;
                    if (pauseSel == 0) {
                        pauseSel = 1;
                        LCD_DrawRect(144,112,58,16,BLACK);
                        LCD_DrawRect(222,112,51,16,WHITE);
                    }
                    else if (pauseSel == 1) {
                        pauseSel = 0;
                        LCD_DrawRect(222,112,51,16,BLACK);
                        LCD_DrawRect(144,112,58,16,WHITE);
                    }
                }
            }
        }

        // game over
        if (gameOver == 1) {
            NVIC_ST_CTRL_R = 0;
            TIMER2_CTL_R = 0x00000000;
            LCD_DrawFilledRect(156,38,100,20,BLACK);
            LCD_SetTextColor(255,255,240);
            LCD_Goto(30,5);
            printf("GAME OVER");
            while (Button1 == 0 && Button2 == 0) {}
            Button1 = 0;
            Button2 = 0;
            LCD_DrawFilledRect(prevX,prevY,20,20,BLACK);
            drawGameOver(score, elapsedTime);
            if (score > highscore) {
                writeHighscore(score);
                gameOverHighscore(score);
            }
            // wait til button is pushed
            while (Button1 == 0 && Button2 == 0) {}
            // acknowledge buttons
            Button1 = 0;
            Button2 = 0;
            // start new game
            score = 0;
            eraseScore();
            writeScore(0);
            clearBoard();
            eraseBoard();
            pauseMode = 0;
            generateRandomTile();
            drawAllTiles();
            elapsedTime = 0;
            eraseTime();
            writeTime(0);
            displayHighestTile();
            NVIC_ST_CTRL_R = 0x07;
            TIMER2_CTL_R = 0x00000001;

            // finish game over mode
            gameOver = 0;
        }
    }
}