Example #1
0
TEST_F(FigureMoveFixture, shouldTestPosWhenMoveLeft)
{
  // Given
  CFigureMove figureMove(&strictTetris);

  // Expected
  EXPECT_CALL(strictTetris, testPos(left(elem0))).InSequence(s).WillOnce(Return(true));
  EXPECT_CALL(strictTetris, testPos(left(elem1))).InSequence(s).WillOnce(Return(true));
  EXPECT_CALL(strictTetris, testPos(left(elem2))).InSequence(s).WillOnce(Return(true));
  EXPECT_CALL(strictTetris, testPos(left(elem3))).InSequence(s).WillOnce(Return(true));

  // When
  figureMove.left(spFigure.data());
}
Example #2
0
// computes the energy if the node returned by testNode() is moved
// to position testPos().
void PlanarityGrid::compCandEnergy()
{
	delete m_candidateGrid;
	node v = testNode();
	const DPoint& newPos = testPos();
	if(m_currentGrid->newGridNecessary(v,newPos))
		m_candidateGrid = new UniformGrid(m_layout,v,newPos);
	else
		m_candidateGrid = new UniformGrid(*m_currentGrid,v,newPos);
	m_candidateEnergy = m_candidateGrid->numberOfCrossings();
}
Example #3
0
TEST_F(FigureMoveFixture, shouldNotMoveLeftFigureWhenMoveLeft)
{
  // Given
  ON_CALL(niceTetris, testPos(_)).WillByDefault(Return(false));

  CFigureMove figureMove(&niceTetris);

  // When
  bool ret = figureMove.left(spFigure.data());

  // Then
  ASSERT_FALSE(ret);
  ASSERT_EQ(elem0.pos(), spFigure->elem[0].pos());
  ASSERT_EQ(elem1.pos(), spFigure->elem[1].pos());
  ASSERT_EQ(elem2.pos(), spFigure->elem[2].pos());
  ASSERT_EQ(elem3.pos(), spFigure->elem[3].pos());
}
Example #4
0
TEST_F(FigureMoveFixture, shouldMoveLeftFigureWhenMoveLeft)
{
  // Given
  ON_CALL(niceTetris, testPos(_)).WillByDefault(Return(true));

  CFigureMove figureMove(&niceTetris);

  // When
  bool ret = figureMove.left(spFigure.data());

  // Then
  ASSERT_TRUE(ret);
  ASSERT_EQ(left(elem0), spFigure->elem[0].pos());
  ASSERT_EQ(left(elem1), spFigure->elem[1].pos());
  ASSERT_EQ(left(elem2), spFigure->elem[2].pos());
  ASSERT_EQ(left(elem3), spFigure->elem[3].pos());
}
Example #5
0
	// computes the energy if the node returned by testNode() is moved
	// to position testPos().
	void Planarity::compCandEnergy()
	{
		node v = testNode();
		m_candidateEnergy = energy();
		edge e;
		m_crossingChanges.clear();

		forall_adj_edges(e,v) if(!e->isSelfLoop()) {
			// first we compute the two endpoints of e if v is on its new position
			node s = e->source();
			node t = e->target();
			DPoint p1 = testPos();
			DPoint p2 = (s==v)? currentPos(t) : currentPos(s);
			int e_num = (*m_edgeNums)[e];
			edge f;
			// now we compute the crossings of all other edges with e
			ListIterator<edge> it;
			for(it = m_nonSelfLoops.begin(); it.valid(); ++it) if(*it != e) {
				f = *it;
				node s2 = f->source();
				node t2 = f->target();
				if(s2 != s && s2 != t && t2 != s && t2 != t) {
					bool cross = lowLevelIntersect(p1,p2,currentPos(s2),currentPos(t2));
					int f_num = (*m_edgeNums)[f];
					bool priorIntersect = (*m_crossingMatrix)(min(e_num,f_num),max(e_num,f_num));
					if(priorIntersect != cross) {
						if(priorIntersect) m_candidateEnergy --; // this intersection was saved
						else m_candidateEnergy ++; // produced a new intersection
						ChangedCrossing cc;
						cc.edgeNum1 = min(e_num,f_num);
						cc.edgeNum2 = max(e_num,f_num);
						cc.cross = cross;
						m_crossingChanges.pushBack(cc);
					}
				}
			}
		}
	}
Example #6
0
bool Morpion()
{
    SDL_Surface *screen = NULL, *texte[3] = {NULL,NULL,NULL};
    SDL_Rect posBlock[9], posFond, posTexte[3];
    SDL_Event event_morpion;
    IMAGE images;

    bool continuer = true, correct = false, rejouer = true, full_case = false,finJeux = true;
    int joueur = 1;
    int blocks[9], i, block_boutton;
    int pointJ[2] = {0}, manche = 1;
    int n = 9;
    const int jeu = MORPION;

    /******************************************************************************/
    screen = SDL_GetVideoSurface();
    verifSetVideo(screen);
    iniPos(&posFond,0,0);

    for(i=0; i<9; i++)
    {
        blocks[i] = RIEN;
        posBlock[i].x = (Sint16)(MIN + ((i%3)*TAILLE));
        posBlock[i].y = (Sint16)(MAX + ((i/3)*TAILLE));
    }

    /* position police */
    for(i=0; i<2; i++)
    {
        posTexte[i].x = 125;
        posTexte[i].y = (Sint16)(555 + (22*i));
    }

    iniPos(&posTexte[2],322,577);

    /******************************************************************************/

    initialiseImagesMorpion(&images);
    verifChargImage(images.fond);
    verifChargImage(images.croix);
    verifChargImage(images.rond);

    /******************************************************************************/

    SDL_WM_SetCaption("Morpion", NULL);

    /******************************************************************************/

    SDL_BlitSurface(images.fond, NULL,screen, &posFond);
    SDL_Flip(screen);


    while(rejouer)
    {
        full_case = false;
        continuer = true;
        while(continuer == true)
        {
            block_boutton = 0;
            if (joueur == 1)
                joueur++;
            else
                joueur--;
            /**********/
            if (joueur == 2) /*IA*/
            {
                i = verifie(blocks);
                if (i != -1)
                {
                    blocks[i] = ROND;
                    if(check(blocks,&full_case))
                        continuer=false;
                }
                else if(continuer)
                {
                    do
                    {
                        i=(rand()%9);
                    }
                    while(blocks[i] != RIEN);
                    blocks[i] = ROND;
                }

                if(check(blocks,&full_case))
                    continuer=false;
            }
            /**********/
            else if (joueur&&continuer)
            {
                do
                {
                    correct = false;
                    SDL_WaitEvent(&event_morpion);
                    switch(event_morpion.type)
                    {
                    case SDL_QUIT:
                        correct = true;
                        continuer = false;
                        rejouer = false;
                        finJeux = false;
                        break;

                    case SDL_KEYDOWN:
                        switch (event_morpion.key.keysym.sym)
                        {
                        case SDLK_ESCAPE:
                            if(afficherMenuJeux(jeu))
                            {
                                correct = true;
                                continuer = false;
                                rejouer = false;
                            }
                            else
                            {
                                initialiseImagesMorpion(&images);
                                SDL_BlitSurface(images.fond,NULL,screen,&posFond);
                                affiche_score(texte, manche,pointJ, posTexte);

                                for(i=0; i<9; i++)
                                {
                                    if(blocks[i]==CROIX)
                                        SDL_BlitSurface(images.croix, NULL,screen, &posBlock[i]);
                                    else if(blocks[i]==ROND)
                                        SDL_BlitSurface(images.rond, NULL,screen, &posBlock[i]);

                                }
                                SDL_Flip(screen);
                            }
                            break;

                        default :
                            break;
                        }
                        break;

                    case SDL_MOUSEBUTTONUP:
                        switch(event_morpion.button.button)
                        {
                        case SDL_BUTTON_LEFT:
                            block_boutton = testPos(posBlock, TAILLE,TAILLE,n,event_morpion);
                            if (block_boutton > -1 && blocks[block_boutton] == RIEN)
                            {
                                blocks[block_boutton] = CROIX;
                                if(check(blocks, &full_case))
                                {
                                    continuer=false;
                                }
                                correct = true;
                            }
                            else if(block_boutton == -2)
                            {
                                if(afficherMenuJeux(jeu))
                                {
                                    correct = true;
                                    continuer = false;
                                    rejouer = false;
                                }
                                else
                                {
                                    initialiseImagesMorpion(&images);
                                    SDL_BlitSurface(images.fond,NULL,screen,&posFond);
                                    affiche_score(texte, manche,pointJ, posTexte);

                                    for(i=0; i<9; i++)
                                    {
                                        if(blocks[i]==CROIX)
                                            SDL_BlitSurface(images.croix, NULL,screen, &posBlock[i]);
                                        else if(blocks[i]==ROND)
                                            SDL_BlitSurface(images.rond, NULL,screen, &posBlock[i]);

                                    }
                                    SDL_Flip(screen);
                                }
                            }
                            break;

                        default :
                            break;
                        }
                        break;

                    default :
                        break;
                    }
                }
                while(!correct);
            }
            SDL_BlitSurface(images.fond, NULL,screen, &posFond);
            for(i=0; i<9; i++)
            {
                if(blocks[i]==CROIX)
                    SDL_BlitSurface(images.croix, NULL,screen, &posBlock[i]);
                else if(blocks[i]==ROND)
                    SDL_BlitSurface(images.rond, NULL,screen, &posBlock[i]);
            }
            affiche_score(texte, manche,pointJ, posTexte);
            SDL_Flip(screen);
        }
        if(rejouer)
        {
            SDL_Delay(1500);
            if(!full_case)
                pointJ[joueur - 1]++;
            manche++;
        }

        for(i=0; i<9; i++)
        {
            blocks[i] = RIEN;
        }

        SDL_BlitSurface(images.fond, NULL,screen, &posFond);
        affiche_score(texte, manche,pointJ, posTexte);
        SDL_Flip(screen);

    }

    /******************************************************************************/

    SDL_FreeSurface(images.fond);
    SDL_FreeSurface(images.croix);
    SDL_FreeSurface(images.rond);
    return finJeux;
}