示例#1
0
/*****************************************************************
 * 函数名称:haveConnect
 * 描述说明:判断是否死局
 * 输入参数:p_mat:连连看逻辑矩阵类指针
 * 输出参数:0:死局1:未死局
*****************************************************************/
int haveConnect(mat_t *p_mat)
{
	int i, j;
	int max;
	gameMng_t gameMng;

	max = MAT_ROW * MAT_CLUMN;

	for(i = 0; i < max; i ++){
		if(p_mat->mat[i / MAT_ROW][i % MAT_ROW].m_picId != 0){
			gameMng.firLoc.row = i / MAT_ROW;
			gameMng.firLoc.clumn = i % MAT_ROW;
			for(j = i + 1; j < max; j ++){
				if(p_mat->mat[j / MAT_ROW][j % MAT_ROW].m_picId != 0){
					gameMng.secLoc.row = j / MAT_ROW;
					gameMng.secLoc.clumn = j % MAT_ROW;
					if(isConnect(&gameMng, p_mat)){
						return 1;
					}
				}
			}
		}
	}

	return 0;
}
示例#2
0
void MainWindow::validateConnect()
{
    bool connect = isConnect();
    if(!connect)
        this->close(),
            qDebug() << "close";
}
示例#3
0
int ladderLength(string start, string end, unordered_set<string> & dict)
{
	if(start.size() != end.size()) return 0;

	if(isConnect(start, end)) return 2;

	int res = 0;
	string tem = "";
	queue<string> Q, P;
	Q.push(start);
	while(!Q.empty())
	{
		res++;
		while(!Q.empty())
		{
			tem = Q.front();
			Q.pop();
			if(isConnect(tem, end))
			{
				res++;
				return res;
			}
			for (int i = 0; i < tem.size(); ++i)
			{
				char c = tem[i];
				for (int j = 0; j < 26; ++j)
				{
					tem[i] = 'a' + j;
					unordered_set<string>::iterator itr = dict.find(tem);
					if(itr != dict.end())
					{
						P.push(tem);
						dict.erase(itr);
					}
				}
				tem[i] = c;
			}

		}
		while(!P.empty())
		{
			Q.push(P.front());
			P.pop();
		}
	}
	return 0;
}
示例#4
0
void MainWindow::buttons()
{
    connect(this, SIGNAL(adminEditType()), dialHall, SLOT(editHallType()));
    connect(this, SIGNAL(isConnect()), connecting, SLOT(isConnected()));
    connect(this, SIGNAL(adminEditBldg()), dialBldg, SLOT(editBldg()));
    connect(this, SIGNAL(adminEditShow()), dialShow, SLOT(editShow()));
    connect(this, SIGNAL(adminEditTimes()),dialTimes, SLOT(editTimes()));
    connect(this, SIGNAL(adminEditMap()), dialMap, SLOT(editMap()));
    connect(this, SIGNAL(adminEditZone()), dialZone, SLOT(editZone()));

    // temp slots
    connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateRelation(int)));
}
示例#5
0
int MRSClient::proceed()
{
	if (false == isConnect()) {
		void*	pState = m_pClient->getFSM().getCurrentState();
		if (pState == oneup::CSConnecting::getInstance()) {
		} else if (pState == oneup::CSEstablished::getInstance()) {
			// Establishedなら、接続が完了している
			m_bConnect = true;
		} else if (pState == oneup::CSException::getInstance()) {
			// Exceptionの場合、タイムアウトなどのエラーが発生している
			return -100;
		} else if (pState == oneup::CSTerminate::getInstance()) {
			return -200;
		} else if (pState == oneup::CSClosing::getInstance()) {
			return -300;
		}
	} else {
	}
	return 0;
}
Graph *RandomGeometric::getRandomGraph() {
    std::srand(std::time(0));
    pair<int,int> x;
    for (int i = 0; i < this->n; ++i) {
        x.first = rand()%this->getSquareSize();
        x.second = rand()%this->getSquareSize();
        this->vertexes->push_back(x);
    }
    Vertex *a,*b;
    for (int i = 0; i < n; ++i) {
        for(int j = 0;j< i; ++j){
            if (isConnect(vertexes->at(i),vertexes->at(j))){
                if(!graph->isExist(i+1,j+1)){
                    a = new Vertex(i+1);
                    b = new Vertex(j+1);
                    graph->addEdge(a,b);
                }
            }
        }

    }
    return graph;

}
示例#7
0
CmtSpiSdCard* 
CmtSpiSdCard::CreateCard( CmtSpiPipeBase *spi, CmtSdIsConnect isConnect ) {
  if( isConnect() != CMTE_OK ) return 0; //Карта не подключена
  CCHLOCK(spi,0);  //SPI не доступно
  uint32 i;
  uint8 MMCCmd[16];
  uint8 dummi[2];

  spi->UnSelect(); /* set SPI SSEL */
  /* initialise the MMC card into SPI mode by sending 80 clks on */
  /* Use MMCRDData as a temporary buffer for SPI_Send() */
  for(i=0; i<10; i++) {
    MMCCmd[i] = 0xFF;
    }
  spi->WriteBlock( MMCCmd, 10, 0 );
  spi->Select(); /* clear SPI SSEL */

  /* send CMD0(RESET or GO_IDLE_STATE) command, all the arguments
  are 0x00 for the reset command, precalculated checksum */
  MMCCmd[0] = 0x40;
  MMCCmd[1] = 0x00;
  MMCCmd[2] = 0x00;
  MMCCmd[3] = 0x00;
  MMCCmd[4] = 0x00;
  MMCCmd[5] = 0x95;
  spi->WriteBlock( MMCCmd, MMC_CMD_SIZE, 0 );

  /* if = 1 then there was a timeout waiting for 0x01 from the MMC */
  if( Response(spi,0x01) != CMTE_OK ) {
//strcpy( (char*)gpsGeo, "            A" );
    spi->UnSelect(); /* set SPI SSEL */
    CUNLOCK(spi);
    return 0;
    }
//strcpy( (char*)gpsGeo, "            U" );

  /* Send some dummy clocks after GO_IDLE_STATE */
  spi->UnSelect(); /* set SPI SSEL */
  MMCCmd[0] = 0xff;
  spi->WriteBlock( MMCCmd, 1, 0 );

  spi->Select(); /* clear SPI SSEL */

  /* must keep sending command until zero response ia back. */
  i = MAX_TIMEOUT;
  do {
    /* send mmc CMD1(SEND_OP_COND) to bring out of idle state */
    /* all the arguments are 0x00 for command one */
    MMCCmd[0] = 0x41;
    MMCCmd[1] = 0x00;
    MMCCmd[2] = 0x00;
    MMCCmd[3] = 0x00;
    MMCCmd[4] = 0x00;
    /* checksum is no longer required but we always send 0xFF */
    MMCCmd[5] = 0xFF;
    spi->WriteBlock( MMCCmd, MMC_CMD_SIZE, 0 );
    i--;
    } while ( (Response(spi,0x00) != CMTE_OK) && (i>0) );

  /* timeout waiting for 0x00 from the MMC */
  if ( i == 0 ) {
    //MMCStatus = OP_COND_TIMEOUT;
//strcpy( (char*)gpsGeo, "            B" );
    spi->UnSelect(); /* set SPI SSEL */
    CUNLOCK(spi);
    return 0;
    }

  /* Send some dummy clocks after SEND_OP_COND */
  spi->UnSelect(); /* set SPI SSEL */
  MMCCmd[0] = 0xff;
  spi->WriteBlock( MMCCmd, 1, 0 );

  //Команда чтения CSD
  spi->Select(); /* clear SPI SSEL */

  /* send CMD9(SEND_CSD) command */
  MMCCmd[0] = 0x49;
  MMCCmd[1] = 0x00;
  MMCCmd[2] = 0x00;
  MMCCmd[3] = 0x00;
  MMCCmd[4] = 0x00;
  MMCCmd[5] = 0xFF;
  spi->WriteBlock( MMCCmd, MMC_CMD_SIZE, 0 );

  /* if = 1 then there was a timeout waiting for 0x01 from the MMC */
  if( Response(spi,0x00) != CMTE_OK ) {
//strcpy( (char*)gpsGeo, "            D" );
    spi->UnSelect(); /* set SPI SSEL */
    CUNLOCK(spi);
    return 0;
    }
  
  /* wait for data token */
  if( Response( spi, 0xFE ) != CMTE_OK ) {
//strcpy( (char*)gpsGeo, "            E" );
    spi->UnSelect(); /* set SPI SSEL */
    CUNLOCK(spi);
    return 0;
    }

  for(i=0; i<16; i++) {
    MMCCmd[i] = 0xff;
    }
  /* Get the block of data based on the length */
  
  spi->ReadBlock( MMCCmd, 16, 0 );
  /* CRC bytes that are not needed */
  dummi[0] = 0xff;
  dummi[1] = 0xff;
  spi->WriteBlock( dummi, 2, 0 );
//GPIO_SetBits( GPIOA, MBIT3 );
  spi->UnSelect(); /* set SPI SSEL */
  dummi[0] = 0;
  spi->WriteBlock( dummi, 1, 0 );

  //Анализ размера карты (определение количества блоков)
  uint32 blockCount; //Количество блоков по 512 байт
  int factor;
  //Регистр CSD MSB битами вперед
  //Биты  127-120  119-112 111-104  103-96  95-88  87-80  79-72  71-64  63-56  55-48  47-40  39-32  31-24  23-16  15-8  7-0
  //Байты    0        1       2        3      4      5      6      7      8      9      10     11     12     13     14   15
  if( (MMCCmd[0] & 0xc0) == 0 ) {
    //SD 1.0
    uint32 c_size;
    c_size = MMCCmd[6] & 0x3; //[73:62]
    c_size <<= 8;
    c_size += MMCCmd[7];
    c_size <<= 2;
    c_size += (MMCCmd[8] >> 6) & 0x3;
    
    uint32 c_size_mult; 
    c_size_mult = MMCCmd[9] & 0x3; //[49:47]
    c_size_mult <<= 1;
    c_size_mult += (MMCCmd[10] >> 7) & 1;
    
    uint32 read_bl_len;
    read_bl_len = MMCCmd[5] & 0xf; //[83:80]
    
    read_bl_len -= 9; //Перейти к блокам
    
    blockCount = (c_size + 1) * (1 << (c_size_mult + 2)) * (1 << read_bl_len);
    factor = 9;
    }