Esempio n. 1
0
int testMove(int n,int m,int people)
{
    printf("%d,%d \n",n,m);
    people+=pointPeopleNum(n,m);
    if(people > maxPeople){
        maxPeople = people;
    }

    if(n == xMax && m == yMax){
	printf("people:%d\n",people);
    }


    if(n<xMax) {
        /*printf("move right\n");*/
        testMove(n+1,m,people);
    }

    if(m<yMax) {
        /*printf("move up\n");*/
        testMove(n,m+1,people);
    }

    return 0;
}
Esempio n. 2
0
int testEngine () {
    lvl_t* lvl = NULL;
    
    
    /* ouvre le fichier de level */
    if (lvl_openFileLvl("../data/levels.lvl") != 0) {
        puts("erreur\n");
        return (-1);
    }
    
    /* lit un level et test l'ouveture */
    lvl = lvl_readLevel(54);
    if (lvl == NULL) {
        puts("lecture impossible\n");
        return (-1);
    }
    
    
    _lvl_view(lvl);
    
    testMove(lvl, UP);
    
    _lvl_view(lvl);
    
    
    /* libere le level */
    lvl_closeLevel(lvl);
    
    /* non implemente */
    lvl_closeFileLvl();
    
    return 0;
}
Esempio n. 3
0
void boardUnitTest() {
    BoardType b;
    b.dump(std::cerr);
    b.checkIntegrity();
    std::list<Move> moveList = {
        {notation2Number("e2"), notation2Number("e4"), 0, Piece::empty},
        {notation2Number("c7"), notation2Number("c5"), 0, Piece::empty},
        {notation2Number("e4"), notation2Number("e5"), 0, Piece::empty},
        {notation2Number("f7"), notation2Number("f5"), 0, Piece::empty},
        {notation2Number("e5"), notation2Number("f6"), notation2Number("f5"), Piece::empty, MoveFlags::enPassantCapture},
        {notation2Number("g7"), notation2Number("f6"), 0, Piece::pawn},
        {notation2Number("f1"), notation2Number("a6"), 0, Piece::empty},
        {notation2Number("g8"), notation2Number("h6"), 0, Piece::empty},
        {notation2Number("g1"), notation2Number("f3"), 0, Piece::empty},
        {notation2Number("d8"), notation2Number("a5"), 0, Piece::empty},
        {notation2Number("e1"), notation2Number("g1"), 0, Piece::empty, MoveFlags::castling | MoveFlags::K_castling | MoveFlags::Q_castling},
        {notation2Number("b7"), notation2Number("a6"), 0, Piece::bishop},
        {notation2Number("g2"), notation2Number("g4"), 0, Piece::empty},
        {notation2Number("c8"), notation2Number("b7"), notation2Number("g4"), Piece::empty},
        {notation2Number("g4"), notation2Number("g5"), 0, Piece::empty},
        {notation2Number("b8"), notation2Number("c6"), 0, Piece::empty},
        {notation2Number("g5"), notation2Number("g6"), 0, Piece::empty},
        {notation2Number("a8"), notation2Number("c8"), 0, Piece::empty, MoveFlags::castling | MoveFlags::q_castling},
        {notation2Number("g6"), notation2Number("g7"), 0, Piece::empty},
        {notation2Number("a5"), notation2Number("a4"), 0, Piece::empty},
        {notation2Number("g7"), notation2Number("g8"), 0, Piece::empty, MoveFlags::queenPromotion}
    };
    for (const auto &move : moveList) {
        testMove(b, move);
    }

}
Esempio n. 4
0
// Move block by dx and dy; returns true if successful
bool Block::move(const int dx, const int dy)
{
   bool ok = testMove(dx,dy);
   if ( ok ) {
      x += dx;
      y += dy;
   }
   return ok;
}
Esempio n. 5
0
// Move block by dx and dy; returns true if successful
bool Block::move(const int dx, const int dy, const Puzzle* const puz)
{
   bool ok = testMove(dx,dy,puz);
   if ( ok ) {
      x += dx;
      y += dy;
   }
   return ok;
}
Esempio n. 6
0
    void testC11Practice()
    {
        testLRValue();

        testMove();

        testnullPointers();

        testEnableIf();

        testOverloadUniversalRef();
    }
bool ConnectFour::Board::addMove(const Move& move)
{
    if(!isInBounds(move))
        return false;

    m_solved = m_solved || testMove(move);
    m_board[move.column()].push_back(move.player());

    if(m_solved)
        m_winningPlayer = &(move.player());
    if(m_board[move.column()].size() == COLUMN_SIZE)
        ++m_filledColumns;

    return m_solved;
}
void MoveVisibilityEffect::apply(void *value, void *data)
{
    if(trying) return;
    bool *v=(bool*)value;
    pair<Card*,Player*> *d=(pair<Card*,Player*> *)data;
    Card *c=d->first;
    Player *p=d->second;
    vector<MoveStruct*> testData;
    for(int i=0;i<event->data.size();i++) testData.push_back(new MoveStruct(*event->data[i]));
    PrimitiveMoveEvent testMove(testData);
    testMove.happen();
    trying=true;
    if(c->isVisibleTo(p)) *v=true;
    trying=false;
    testMove.undo();
}
Esempio n. 9
0
        void test()
        {
            std::vector<int> a{ 1,2,3,7,4,5 };
            std::vector<int> b{ 6,3,2,7,9,1 };
            std::set<int> combined;
            combined.insert(a.begin(), a.end());
            combined.insert(b.begin(), b.end());

            iprintf("%s, %d", "hello world", 5);

            std::string t;
            testMove(t);
            iprintf("%s", t.c_str());

            testCeil();

            uint64_t i1 = 11;
            printf("result: %12I64X\n", i1);

            
            std::vector<std::shared_ptr<int>> sss;
            sss.emplace_back(new int(40));

            auto p = std::move(sss[0]);
            assert(sss[0] == nullptr);
            assert(p != nullptr);
            printAndRemove(std::move(p));
 
            uint64_t x = 0;
            uint64_t y = 18446744072645148502;
            std::cout << "x-y:" << x - y << std::endl;

            testVirtual();

            std::map<int, SegmentBlob> blobs;
            blobs[1] = SegmentBlob{ 1, 2 };

            std::vector<SegmentBlob> tttttt;
            tttttt.emplace_back(SegmentBlob{ 1,3 });

            static const uint32_t t_num = *((const uint32_t*)("abcd"));
            printf("hello. %d\n", t_num);

            printf("%d\n", sizeof(PredefinedSegmentTag) / sizeof(SegmentTag));

            return;
        }
Esempio n. 10
0
void testParseSan() {
  try {
    testType("O-O", SanProps::KING_CASTLE);
    testCheckType("O-O+", SanProps::KING_CASTLE);
    testType("O-O-O", SanProps::QUEEN_CASTLE);
    testCheckType("O-O-O+", SanProps::QUEEN_CASTLE);
    testType("1/2-1/2", SanProps::DRAW);
    testType("1-0", SanProps::WHITE_WINS);
    testType("0-1", SanProps::BLACK_WINS);
    testMove("Be5", SanProps::BISHOP, 'e', 5);
    testMove("Nf3", SanProps::KNIGHT, 'f', 3);
    testMove("c5", SanProps::PAWN, 'c', 5);
    testCapture("Bxe5", SanProps::BISHOP, 'e', 5);
    testCapture("B:e5", SanProps::BISHOP, 'e', 5);
    testCapture("Be5:", SanProps::BISHOP, 'e', 5);
    testCapture("exd5", SanProps::PAWN, 'd', 5, 'e');
    testEnPassant("exd6e.p.", 'd', 6, 'e');
    testMove("Ngf3", SanProps::KNIGHT, 'f', 3, 'g');
    testMove("Ndf3", SanProps::KNIGHT, 'f', 3, 'd');
    testMove("N5f3", SanProps::KNIGHT, 'f', 3, 0, 5);
    testMove("N1f3", SanProps::KNIGHT, 'f', 3, 0, 1);
    testCapture("N5xf3", SanProps::KNIGHT, 'f', 3, 0, 5);
    testMove("Rdd5", SanProps::ROOK, 'd', 5, 'd');
    testMove("R3d5", SanProps::ROOK, 'd', 5, 0, 3);
    testCapture("Rdxd5", SanProps::ROOK, 'd', 5, 'd');
    testPromotion("e8Q", 'e', 8, SanProps::QUEEN);
    testPromotion("e8=Q", 'e', 8, SanProps::QUEEN);
    testCheck("Nd7+", SanProps::KNIGHT, 'd', 7);
    testCheck("Rb7+", SanProps::ROOK, 'b', 7);
    testCheck("Ba6+", SanProps::BISHOP, 'a', 6);
    testCheckmate("Rg7#", SanProps::ROOK, 'g', 7);
    testCheckmateCapture("Nxh6#", SanProps::KNIGHT, 'h', 6);
    testCheckmate("Rh4#", SanProps::ROOK, 'h', 4);
  } catch (std::runtime_error const & err) {
    std::cerr << "caught error while parsing san " << err.what() << std::endl;
  }
}
Esempio n. 11
0
int main(int argc,char** argv)
{
    int ntmp=1,mtmp=1;
    freopen("in.txt","r",stdin);
    scanf("%d %d %d",&xMax,&yMax,&nuPointsPeople);
    PP = malloc(sizeof(struct PointPeople)*nuPointsPeople);
    int k=0;
    for(k=0;k<nuPointsPeople;k++) {
        scanf("%d %d %d",&PP[k].n,&PP[k].m,&PP[k].nuPeople);
        //printf("k:%d,n:%d,m:%d,people:%d\n",k,PP[k].n,PP[k].m,PP[k].nuPeople);
    }

    testMove(ntmp,mtmp,0);

    printf("maxPeople:%d\n",maxPeople);
    freopen("out.txt","w",stdout);
    printf("%d\n",maxPeople);

    return 0;
}
Esempio n. 12
0
void testState()
{
    testMove();
    state s = newStartingState(0b00010010);
    if(getPScores(s, PLAYER_ONE) != 0) {fail("getPScores() failed in State module\n");}
    if(getPScores(s, PLAYER_TWO) != 0) {fail("getPScores() failed in State module\n");}
    s = addPScore(s, PLAYER_ONE, 16);
    s = addPScore(s, PLAYER_TWO, 52);
    if(getPScores(s, PLAYER_ONE) != 16) {fail("addPScore() failed in State module\n");}
    if(getPScores(s, PLAYER_TWO) != 52) {fail("addPScore() failed in State module\n");}
    card firstDealt = getNextCard(s);
    if(numCardsLeft(getDeck(s) & DECK) != 9) {fail("getNextCard() failed in State module\n");}
    s = removeNextCard(s, firstDealt);
    if(!equal(s.deckOrder[0], firstDealt)) {fail("getNextCard() failed in State module\n");}
    if(numCardsLeft(getDeck(s) & DECK) != 8) {fail("removeNextCard() failed in State module\n");}
    if(((getDeck(s) & ~DECK) >> 28) != 1) {fail("removeNextCard() failed in State module\n");}
    pile p = newCardRankSuit(KING, CLUBS) | newCardRankSuit(KING, HEARTS) |
        newCardRankSuit(ACE, CLUBS) | newCardRankSuit(JACK, DIAMONDS);
    if(numCardsLeft(getPHand(s, PLAYER_ONE)) != 5) {fail("getPHand() failed in State module\n");}
    s = setPHand(s, PLAYER_ONE, p);
    if(numCardsLeft(getPHand(s, PLAYER_ONE)) != 4) {fail("setPHand() failed in State module\n");}
    s = addCardPHand(s, PLAYER_ONE, newCardRankSuit(QUEEN, SPADES));
    if(!contains(getPHand(s, PLAYER_ONE), newCardRankSuit(JACK, DIAMONDS)))
        {fail("addCardPHand() failed in State module\n");}
    if(!contains(getPHand(s, PLAYER_ONE), newCardRankSuit(QUEEN, SPADES)))
        {fail("addCardPHand() failed in State module\n");}
    if(numCardsLeft(getPHand(s, PLAYER_ONE)) != 5)
        {fail("addCardPHand() failed in State module\n");}
    s = removePHandCard(s, PLAYER_ONE, newCardRankSuit(KING, HEARTS));
    if(!contains(getPHand(s, PLAYER_ONE), newCardRankSuit(JACK, DIAMONDS)))
        {fail("removePHandCard() failed in State module\n");}
    if(!contains(getPHand(s, PLAYER_ONE), newCardRankSuit(QUEEN, SPADES)))
        {fail("removePHandCard() failed in State module\n");}
    if(!contains(getPHand(s, PLAYER_ONE), newCardRankSuit(KING, CLUBS)))
        {fail("removePHandCard() failed in State module\n");}
    if(!contains(getPHand(s, PLAYER_ONE), newCardRankSuit(ACE, CLUBS)))
        {fail("removePHandCard() failed in State module\n");}
    if(contains(getPHand(s, PLAYER_ONE), newCardRankSuit(KING, HEARTS)))
        {fail("removePHandCard() failed in State module\n");}
    if(numCardsLeft(getPHand(s, PLAYER_ONE)) != 4)
        {fail("removePHandCard() failed in State module\n");}
    if(getPType(s, PLAYER_ONE) != MINIMAX_HIGHEST_CLOSE)
        {fail("getPType() failed in State module\n");}
    if(getPType(s, PLAYER_TWO) != MINIMAX_LOWEST_CLOSE)
        {fail("getPType() failed in State module\n");}
    s = switchPTypes(s);
    if(getPType(s, PLAYER_ONE) != MINIMAX_LOWEST_CLOSE)
        {fail("switchPTypes() failed in State module\n");}
    if(getPType(s, PLAYER_TWO) != MINIMAX_HIGHEST_CLOSE)
        {fail("switchPTypes() failed in State module\n");}
    if(getPCurrGamePoints(s, PLAYER_ONE) != 0)
        {fail("getPCurrGamePoints() failed in State module\n");}
    if(getPCurrGamePoints(s, PLAYER_TWO) != 0)
        {fail("getPCurrGamePoints() failed in State module\n");}
    s = addGamePoints(s, PLAYER_ONE, 4);
    if(getPCurrGamePoints(s, PLAYER_ONE) != 4)
        {fail("addGamePoints() failed in State module\n");}
    if(getPCurrGamePoints(s, PLAYER_TWO) != 0)
        {fail("addGamePoints() failed in State module\n");}
    if(numCardsLeft(getPRevCards(s, PLAYER_ONE)) != 0)
        {fail("getPRevCards() failed in State module\n");}
    if(numCardsLeft(getPRevCards(s, PLAYER_TWO)) != 0)
        {fail("getPRevCards() failed in State module\n");}
    s = addCardPRevCards(s, PLAYER_TWO, newCardRankSuit(JACK, HEARTS));
    if(numCardsLeft(getPRevCards(s, PLAYER_ONE)) != 0)
        {fail("addCardPRevCards() failed in State module\n");}
    if(numCardsLeft(getPRevCards(s, PLAYER_TWO)) != 1)
        {fail("addCardPRevCards() failed in State module\n");}
    s = removePRevCard(s, PLAYER_TWO, newCardRankSuit(QUEEN, HEARTS));
    s = removePRevCard(s, PLAYER_TWO, newCardRankSuit(JACK, DIAMONDS));
    s = removePRevCard(s, PLAYER_ONE, newCardRankSuit(JACK, DIAMONDS));
    if(numCardsLeft(getPRevCards(s, PLAYER_ONE)) != 0)
        {fail("removePRevCard() failed in State module\n");}
    if(numCardsLeft(getPRevCards(s, PLAYER_TWO)) != 1)
        {fail("removePRevCard() failed in State module\n");}
    s = removePRevCard(s, PLAYER_TWO, newCardRankSuit(JACK, HEARTS));
    if(numCardsLeft(getPRevCards(s, PLAYER_TWO)) != 0)
        {fail("removePRevCard() failed in State module\n");}
    if(getTrumpSwapped(s))
        {fail("getTrumpSwapped() failed in State module\n");}
    s = setTrumpSwapped(s);
    if(!getTrumpSwapped(s))
        {fail("setTrumpSwapped() failed in State module\n");}
    if(getP1ClosedTalon(s))
        {fail("newStartingState() with getP1ClosedTalon() failed in State module\n");}
    s = setPClosedTalon(s, PLAYER_ONE);
    if(!getP1ClosedTalon(s))
        {fail("setPClosedTalon() 1failed in State module\n");}
    s = setPClosedTalon(s, PLAYER_TWO);
    if(getP1ClosedTalon(s))
        {fail("setPClosedTalon() 2failed in State module\n");}
    if(getDealEnded(s)) {fail("newStartingState() failed in State module\n");}
    s = setDealEnded(s);
    if(!getDealEnded(s)) {fail("setDealEnded() failed in State module\n");}
    bool p1Leading = getP1PlayedFirst(s);
    if(p1Leading)
    {
        if(!getP1LeadTrick(s)) {fail("getP1LeadTrick() failed in State module\n");}
        s = setP1LeadTrick(s, false);
        if(getP1LeadTrick(s)) {fail("setP1LeadTrick() failed in State module\n");}
    }
    else
    {
        if(getP1LeadTrick(s)) {fail("getP1LeadTrick() failed in State module\n");}
        s = setP1LeadTrick(s, true);
        if(!getP1LeadTrick(s)) {fail("setP1LeadTrick() failed in State module\n");}
    }
    if(numCardsLeft(getAllUnseenCards(s, PLAYER_ONE)) != 13)
        {fail("getAllUnseenCards() 1failed in State module\n");}
    s = updatePPossGamePoints(s, PLAYER_ONE);
    if(getPPossGamePoints(s, PLAYER_ONE) != 3)
        {fail("updatePPossGamePoints() failed in State module\n");}
    if(getPPossGamePoints(s, PLAYER_TWO) != 3)
        {fail("updatePPossGamePoints() failed in State module\n");}
    s = setPWonATrick(s, PLAYER_TWO);
    s = updatePPossGamePoints(s, PLAYER_ONE);
    if(getPPossGamePoints(s, PLAYER_ONE) != 4)
        {fail("updatePPossGamePoints() failed in State module\n");}
    if(getPPossGamePoints(s, PLAYER_TWO) != 5)
        {fail("updatePPossGamePoints() failed in State module\n");}
    if(strcmp(strPlayerNum(PLAYER_ONE), "Player One") != 0)
        {fail("strPlayerNum() failed in State module\n");}
    if(strcmp(strPlayerNum(PLAYER_TWO), "Player Two") != 0)
        {fail("strPlayerNum() failed in State module\n");}
    if(strcmp(strPType(MINIMAX_HIGHEST_CLOSE), "Minimax (highest close)") != 0)
        {fail("strPType() failed in State module\n");}
    puts("State Module OK\n");
}
Esempio n. 13
0
        bool Tela::playGame() {
		    Ponto p1 = {-1, -1}, p2 = {-1, -1}, pDica = {-1, -1};
		    bool quit = false, execute = true;
		    showGame();
            if(testMove() == false) quit = true;
			float frame = 0;
    		Uint32 start = SDL_GetTicks();
			SDL_Rect rect0[20], rect1[20], rect2[20], rect3[20], rect4[20], rect5[20], rect6[20];
		    setrects(rect0, 60, 0);
		    setrects(rect1, 62, 70);
		    setrects(rect2, 58, 140);
		    setrects(rect3, 58, 210);
		    setrects(rect4, 60, 280);
		    setrects(rect5, 64, 350);
		    setrects(rect6, 64, 420);

		    while( execute ) {
		    	changeLevel();
                if( level == 5 ) {
                    execute = false;
                    return execute;
                }

		        if( SDL_PollEvent( &event ) ) {

		            Ponto tmp;

		            //Botão esquerdo do mouse pressionado
		            if( event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) {
	                    tmp.x = event.button.x;
	                    tmp.y = event.button.y;
                        if((tmp.x >= 135 && tmp.x <= 250) && (tmp.y >= 480 && tmp.y <= 595)) {
                            undoPlay();
                            SDL_Flip( screen );
	                    } else if((tmp.x >= 45 && tmp.x <= 160) && (tmp.y >= 395 && tmp.y <= 505)){
	                    	pDica = getDica();
	        				apply_surface(pDica.x, pDica.y, gems_dica, screen);
        					SDL_UpdateRect(screen, matriz[pDica.x][pDica.y].celula.x, matriz[pDica.x][pDica.y].celula.y, matriz[pDica.x][pDica.y].celula.w, matriz[pDica.x][pDica.y].celula.h);
	                    } else if((tmp.x >= 30 && tmp.x <= 115) && (tmp.y >= 525 && tmp.y <= 605)){
                            if(showConfScreen()) {
                                quit = true;
                                return quit;
                            } else {
                                showGame();
                            }
                        } else if((tmp.x >= 175 && tmp.x <= 265) && (tmp.y >= 380 && tmp.y <= 465)){
                            if(showInstrucoes()) {
                                quit = true;
                                return quit;
                            } else {
                                showGame();
                            }
                        } else if((tmp.x >= MAT_INITIAL_POINT_X && tmp.x <= MAT_INITIAL_POINT_X + 480) && (tmp.y >= MAT_INITIAL_POINT_Y && tmp.y <= MAT_INITIAL_POINT_Y + 480)) {
	                    	if(pDica.x >= 0) {
		        				apply_surface(pDica.x, pDica.y, gems, screen);
	        					SDL_UpdateRect(screen, matriz[pDica.x][pDica.y].celula.x, matriz[pDica.x][pDica.y].celula.y, matriz[pDica.x][pDica.y].celula.w, matriz[pDica.x][pDica.y].celula.h);
	                    	}
		                    tmp.x = (tmp.x - MAT_INITIAL_POINT_X) / 60;
		                    tmp.y = (tmp.y - MAT_INITIAL_POINT_Y) / 60;
			                if(p1.x < 0) {
			                    p1.x = tmp.y;
			                    p1.y = tmp.x;
			                    //Destaca a nova joia selecionada
			                } else if(p2.x < 0) {
			                	if(saoAdjacentes(p1.x, p1.y, tmp.y, tmp.x)) {
				                    p2.x = tmp.y;
				                    p2.y = tmp.x;
			                	} else {
			                		//Ignora selecao
			                		//Tira o destaque da joia que tinha sido selecionada
			        				apply_surface(p1.x, p1.y, gems, screen);
                					SDL_UpdateRect(screen, matriz[p1.x][p1.y].celula.x, matriz[p1.x][p1.y].celula.y, matriz[p1.x][p1.y].celula.w, matriz[p1.x][p1.y].celula.h);
			                		p1.x = tmp.y;
					                p1.y = tmp.x;
			                	}
			                }
	                    }
	                //Se o usuario fechar a janela
		            } else if( (event.type == SDL_QUIT) ) {
		                //Encerra o programa
		                quit = true;
                        return quit;
                    //Se o usuario teclar ESC
	            	} else if ( (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) ) {
                        level = 5; /* Show Game Over */
                    } else if( (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_SPACE) ) {
	            		if(audio == true) {
							//Pausa a musica
							Mix_PauseMusic();
	            			audio = false;
	            		} else {
							//Toca a musica novamente
							Mix_ResumeMusic();
	            			audio = true;
	            		}
	            	}
		    	}
	            SDL_Rect offset;
	            offset.x = matriz[p1.x][p1.y].celula.x;
	            offset.y = matriz[p1.x][p1.y].celula.y;
	            switch(getElement(p1.x, p1.y)) {
	            	case 1:
						SDL_BlitSurface( gems, &rect0[static_cast<int>(frame)], screen, &offset );
	            		break;
	            	case 2:
						SDL_BlitSurface( gems, &rect1[static_cast<int>(frame)], screen, &offset );
	            		break;
	            	case 3:
						SDL_BlitSurface( gems, &rect2[static_cast<int>(frame)], screen, &offset );
	            		break;
	            	case 4:
						SDL_BlitSurface( gems, &rect3[static_cast<int>(frame)], screen, &offset );
	            		break;
	            	case 5:
						SDL_BlitSurface( gems, &rect4[static_cast<int>(frame)], screen, &offset );
	            		break;
	            	case 6:
						SDL_BlitSurface( gems, &rect5[static_cast<int>(frame)], screen, &offset );
	            		break;
	            	case 7:
						SDL_BlitSurface( gems, &rect6[static_cast<int>(frame)], screen, &offset );
	            		break;
	            }
				SDL_UpdateRect(screen, matriz[p1.x][p1.y].celula.x, matriz[p1.x][p1.y].celula.y, matriz[p1.x][p1.y].celula.w, matriz[p1.x][p1.y].celula.h);
				//Velocidade de transição entre frames
				frame += 0.5;
		 
		        if(frame > 7) {
		        	frame = 0;
		        }
		 
				if(1000/FPS > SDL_GetTicks()-start) 
				{
					SDL_Delay(1000/FPS-(SDL_GetTicks()-start));
				}
            	if((p1.x >= 0) && (p2.x >= 0)) {
		            checkSwitch(p1.x, p1.y, p2.x, p2.y);
		            contrastItem(p1.x, p1.y, matriz[p1.x][p1.y].elemento);
			        apply_surface(p1.x, p1.y, gems, screen);
                	SDL_UpdateRect(screen, matriz[p1.x][p1.y].celula.x, matriz[p1.x][p1.y].celula.y, matriz[p1.x][p1.y].celula.w, matriz[p1.x][p1.y].celula.h);
	                p1.x = -1;
	                p1.y = -1;
	                p2.x = -1;
	                p2.y = -1;
		            if(testMove() == false) 
                        level = 5;
		        }
			}
            return execute;
		}
Esempio n. 14
0
int
main(int argc, char **argv) {
   int status;
   rsComm_t *Comm;
   /*   rErrMsg_t errMsg;*/
   rodsArguments_t myRodsArgs;
   char *mySubName;
   char *myName;
   int didOne;
   rodsServerConfig_t serverConfig;

   Comm = (rsComm_t*)malloc (sizeof (rsComm_t));
   memset (Comm, 0, sizeof (rsComm_t));

   parseCmdLineOpt(argc, argv, "", 0, &myRodsArgs);

   rodsLogLevel(LOG_NOTICE);

   rodsLogSqlReq(1);

   if (argc < 2) {
      printf("Usage: test_chl testName [args...]\n");
      exit(3);
   }

   status = getRodsEnv (&myEnv);
   if (status < 0) {
      rodsLog (LOG_ERROR, "main: getRodsEnv error. status = %d",
	       status);
      exit (1);
   }

   if (strstr(myEnv.rodsDebug, "CAT") != NULL) {
      chlDebug(myEnv.rodsDebug);
   }

   memset(&serverConfig, 0, sizeof(serverConfig));
   status = readServerConfig(&serverConfig);

   strncpy(Comm->clientUser.userName, myEnv.rodsUserName, 
	   sizeof Comm->clientUser.userName);

   strncpy(Comm->clientUser.rodsZone, myEnv.rodsZone, 
	   sizeof Comm->clientUser.rodsZone);

   /*
   char rodsUserName[NAME_LEN];
   char rodsZone[NAME_LEN];

     userInfo_t clientUser;
    char userName[NAME_LEN];
    char rodsZone[NAME_LEN];
   */
   if ((status = chlOpen(serverConfig.DBUsername,
			 serverConfig.DBPassword)) != 0) {
        rodsLog (LOG_SYS_FATAL,
		 "initInfoWithRcat: chlopen Error. Status = %d",
		 status);
        free(Comm); // cppcheck - Memory leak: Comm
        return (status);
   }

   didOne=0;
   if (strcmp(argv[1],"reg")==0) {
      status = testRegDataObj(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }
   if (strcmp(argv[1],"regmulti")==0) {
      status = testRegDataMulti(Comm, argv[2], argv[3], argv[4], argv[5]);
      didOne=1;
   }

   if (strcmp(argv[1],"mod")==0) {
      status = testModDataObjMeta(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"mod2")==0) {
      status = testModDataObjMeta2(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"modr")==0) {
      status = testModRuleMeta(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"modc")==0) {
      status = testModColl(Comm, argv[2], argv[3], argv[4], argv[5]);
      didOne=1;
   }

   if (strcmp(argv[1],"rmrule")==0) {
      status = testDelRule(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"modrfs")==0) { 
      status = testModResourceFreeSpace(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"rep")==0) {
      if (argc < 6) {
	 printf("too few arguments\n");
	 exit(1);
      }
      status = testRegReplica(Comm, argv[2], argv[3], argv[4], argv[5]);
      didOne=1;
   }

   /*
   if (strcmp(argv[1],"cml")==0) {
      status = testCml(Comm);
      didOne=1;
   }
   */

   if (strcmp(argv[1],"rmuser")==0) {
      status = testDelUser(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"mkdir")==0) {
      status = testRegColl(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"rmdir")==0) {
      status = testDelColl(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"sql")==0) {
      status = testSimpleQ(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"rm")==0) {
      status = testDelFile(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"rmtrash")==0) {
      status = testDelFileTrash(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"rmpriv")==0) {
      status = testDelFilePriv(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"chmod")==0) {
      status = testChmod(Comm, argv[2], argv[3], argv[4], argv[5]);
      didOne=1;
   }

   if (strcmp(argv[1],"regrule")==0) {
      status = testRegRule(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"rename")==0) {
      status = testRename(Comm, argv[2], argv[3]);
      testCurrent(Comm);  /* exercise this as part of rename;
                             testCurrent needs a SQL context */
      didOne=1;
   }

   if (strcmp(argv[1],"login")==0) {
      status = testLogin(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"move")==0) {
      status = testMove(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"checkauth")==0) {
      status = testCheckAuth(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"temppw")==0) {
      status = testTempPw(Comm);
      didOne=1;
   }

   if (strcmp(argv[1],"tpc")==0) {
      status = testTempPwConvert(argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"tpw")==0) {
      status = testTempPwCombined(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"tpwforother")==0) {
      status = testTempPwForOther(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"serverload")==0) {
      status = testServerLoad(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"purgeload")==0) {
      status = testPurgeServerLoad(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"serverdigest")==0) {
      status = testServerLoadDigest(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"purgedigest")==0) {
      status = testPurgeServerLoadDigest(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"checkquota")==0) {
      if (argc < 5) {
	 status = testCheckQuota(Comm, argv[2], argv[3],
				 NULL, NULL);
      }
      else {
	 status = testCheckQuota(Comm, argv[2], argv[3],
				 argv[4], argv[5]);
      }
      didOne=1;
   }

   if (strcmp(argv[1],"open")==0) {
      int i;
      for (i=0;i<3;i++) {
	 status = chlClose();
	 if (status) {
	    printf ("close %d error", i);
	 }
      
	 if ((status = chlOpen(serverConfig.DBUsername,
			       serverConfig.DBPassword)) != 0) {
	    rodsLog (LOG_SYS_FATAL,
		     "initInfoWithRcat: chlopen %d Error. Status = %d",
		     i, status);
	    return (status);
	 }
      }
      didOne=1;
   }

   if (strcmp(argv[1],"addrule")==0) {
     status = testAddRule(Comm, argv[2], argv[3],
			     argv[4], argv[5],
			  argv[6], argv[7]);
     didOne=1;
   }

   if (strcmp(argv[1],"versionrulebase")==0) {
     status = testVersionRuleBase(Comm, argv[2]);
     didOne=1;
   }

   if (strcmp(argv[1],"versiondvmbase")==0) {
     status = testVersionDvmBase(Comm, argv[2]);
     didOne=1;
   }

   if (strcmp(argv[1],"versionfnmbase")==0) {
     status = testVersionFnmBase(Comm, argv[2]);
     didOne=1;
   }

   if (strcmp(argv[1],"insfnmtable")==0) {
      status = testInsFnmTable(Comm, argv[2], argv[3], argv[4], argv[5] );
      didOne=1;
   }

   if (strcmp(argv[1],"insdvmtable")==0) {
      status = testInsDvmTable(Comm, argv[2], argv[3], argv[4], argv[5] );
      didOne=1;
   }

   if (strcmp(argv[1],"insmsrvctable")==0) {
      status = testInsMsrvcTable(Comm, argv[2], argv[3], argv[4], argv[5],
			       argv[6], argv[7], argv[8], argv[9], argv[10]);
      if (status==0) {
	/* do it a second time to test another logic path and
           different SQL.  Since no commit is part of the chl
           function, and there is not corresponding Delete call, this
           is an easy way to do this. */
	status = testInsMsrvcTable(Comm, argv[2], argv[3], argv[4], argv[5],
			   argv[6], argv[7], argv[8], argv[9], argv[10]);
      }
     didOne=1;
   }
   if (strcmp(argv[1],"getlocalzone")==0) {
      status = testGetLocalZone(Comm, argv[2]);
      didOne=1;
   }
   if (strcmp(argv[1],"getpampw")==0) {
      status = testGetPamPw(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (status != 0) {
      /*
      if (Comm->rError) {
	 rError_t *Err;
         rErrMsg_t *ErrMsg;
	 int i, len;
	 Err = Comm->rError;
	 len = Err->len;
	 for (i=0;i<len;i++) {
	    ErrMsg = Err->errMsg[i];
	    rodsLog(LOG_ERROR, "Level %d: %s",i, ErrMsg->msg);
	 }
      }
      */
      myName = rodsErrorName(status, &mySubName);
      rodsLog (LOG_ERROR, "%s failed with error %d %s %s", argv[1],
	       status, myName, mySubName);
   }
   else {
      if (didOne) printf("Completed successfully\n");
   }

   if (didOne==0) {
      printf("Unknown test type: %s\n", argv[1]);
   }

   exit(status);
}
Esempio n. 15
0
void BasePerformanceTest::realTest(int i) {
    testAdd(i);
    testMove(i);
    testLeave(i);
}