Exemple #1
0
	public: void free(){
		for(int iside=0; iside<4; iside++){
			Side* side = getSide(iside);
			if(side != NULL)
				for(int jrib=0; jrib<4; jrib++){
					if(this == side->getRib(jrib)){
						side->setRib(NULL, jrib);
						break;
					}
				}
		}

		for(int icell=0; icell<4; icell++){
			Cell* cell = getCell(icell);
			if(cell != NULL)
				for(int jrib=0; jrib<4; jrib++){
					if(this == cell->getRib(getAxis(), jrib)){
						cell->setRib(getAxis(), jrib, NULL);
						break;
					}
				}
		}

		for(int i=0; i<4; i++){
			setSide(i, NULL);
			setCell(i, NULL);
		}
//cout << "delete " << this << endl;;
		delete this;
	}
Exemple #2
0
Result HordeBoard::result()
{
	Side side = sideToMove();
	Side opp = side.opposite();
	if (!hasMaterial(side))
		return Result(Result::Win, opp,
			      tr("%1 wins").arg(opp.toString()));

	return StandardBoard::result();
}
Exemple #3
0
Result KarOukBoard::result()
{
	Side side = sideToMove();
	if (!inCheck(side))
		return OukBoard::result();

	Side opp = side.opposite();
	QString str = tr("%1 wins by giving check").arg(opp.toString());
	return Result(Result::Win, opp, str);
}
Exemple #4
0
uint32_t Facade::getSidePixel(FacadeSide side, unsigned int x, unsigned int y)
{
    Side* s = _building.getSides().at((int) side);
    if(!s->isEnabled() || s->getAddress(x, y) == -1)
        return 0;

    x += s->getStartCol();
    y += s->getStartRow();
    return getPixel(x, y);
}
	public: double getBorderFlowOnSide(Rib* rib, int sideIndex, int flowIndex){
		int vIndex = 0;
		if(sideIndex == Rib::LEFT_SIDE) vIndex = Rib::RIGHT_SIDE;
		else if(sideIndex == Rib::RIGHT_SIDE) vIndex = Rib::LEFT_SIDE;
		else if(sideIndex == Rib::UP_SIDE) vIndex = Rib::DOWN_SIDE;
		else if(sideIndex == Rib::DOWN_SIDE) vIndex = Rib::UP_SIDE;

		Side* vside = rib->getSide(vIndex);
		return vside->getFlow(flowIndex);

//		return 0;
	};
Exemple #6
0
Result LosersBoard::result()
{
	Side winner;
	QString str;

	// Checkmate/Stalemate
	if (!canMove())
	{
		winner = sideToMove();
		str = tr("%1 gets mated").arg(winner.toString());
		return Result(Result::Win, winner, str);
	}

	// Lost all pieces
	int pieceCount = 0;
	for (int i = 0; i < arraySize(); i++)
	{
		if (pieceAt(i).side() == sideToMove()
		&&  ++pieceCount > 1)
			break;
	}
	if (pieceCount <= 1)
	{
		winner = sideToMove();
		str = tr("%1 lost all pieces").arg(winner.toString());
		return Result(Result::Win, winner, str);
	}

	// 50 move rule
	if (reversibleMoveCount() >= 100)
	{
		str = tr("Draw by fifty moves rule");
		return Result(Result::Draw, Side::NoSide, str);
	}

	// 3-fold repetition
	if (repeatCount() >= 2)
	{
		str = tr("Draw by 3-fold repetition");
		return Result(Result::Draw, Side::NoSide, str);
	}

	return Result();
}
Exemple #7
0
	public: void free(){
/*
		if(isSplitted()){
			for(int i=0; i<2; i++){
				subribs[i]->free();
			}
		}
*/
		for(int iside=0; iside<4; iside++){
			Side* side = getSide(iside);
			for(int jrib=0; jrib>4; jrib++){
				if(side != NULL && this == side->getRib(jrib)){
					side->setRib(NULL, jrib);
					break;
				}
			}
		}

		for(int icell=0; icell<4; icell++){
			Cell* cell = getCell(icell);
			for(int jrib=0; jrib>4; jrib++){
				if(cell != NULL && this == cell->getRib(getAxis(), jrib)){
					cell->setRib(getAxis(), jrib, NULL);
					break;
				}
			}
		}
/*
		if(getParent() != NULL){
			for(int i=0; i<2; i++){
				if(this == getParent()->getSubRib(i)){
					getParent()->setSubRib(i, NULL);
					break;
				}
			}
		}
*/
		for(int i=0; i<4; i++){
			setSide(i, NULL);
			setCell(i, NULL);
		}

		delete this;
	}
Exemple #8
0
        void Brush::pick(const Rayf& ray, PickResult& pickResults) {
            float dist = bounds().intersectWithRay(ray, NULL);
            if (Math<float>::isnan(dist))
                return;

            dist = Math<float>::nan();
            Side* side = NULL;
            for (unsigned int i = 0; i < m_geometry->sides.size() && Math<float>::isnan(dist); i++) {
                side = m_geometry->sides[i];
                dist = side->intersectWithRay(ray);
            }

            if (!Math<float>::isnan(dist)) {
                assert(side != NULL);
                Vec3f hitPoint = ray.pointAtDistance(dist);
                FaceHit* hit = new FaceHit(*(side->face), hitPoint, dist);
                pickResults.add(hit);
            }
        }
Exemple #9
0
	private: void calculateFieldE(Rib* rib){
		int axis = rib->getAxis();

		Side* upSide  = rib->getCell(Cell::ur)->getSide((axis+1)%3, Cell::BACKWARD_SIDE);
		Side* downSide = rib->getCell(Cell::dr)->getSide((axis+1)%3, Cell::BACKWARD_SIDE);
		Side* rightSide  = rib->getCell(Cell::ur)->getSide((axis+2)%3, Cell::BACKWARD_SIDE);
		Side* leftSide  = rib->getCell(Cell::ul)->getSide((axis+2)%3, Cell::BACKWARD_SIDE);

		double leftE = 	1.0 / Constants::c * leftSide->getFlow(5 + (axis+1)%3 );
		double rightE = 1.0 / Constants::c * rightSide->getFlow(5 + (axis+1)%3 );
		double upE = 	-1.0 / Constants::c * upSide->getFlow(5 + (axis+2)%3 );
		double downE = 	-1.0 / Constants::c * downSide->getFlow(5 + (axis+2)%3 );

		double dE = 0.25 * (leftE + rightE + upE + downE) - rib->getE();

		rib->setdE(dE);
	}
	public: void markCell(Cell* cell){
		if(!isBorder(cell)) return;

		cell->setMark(getMark());
		for(int axis=0; axis<3; axis++){
			for(int dir=0; dir<2; dir++){
				Side* side = cell->getSide(axis, dir);
				if(isBorder(side->getBCell()) && isBorder(side->getFCell()))
					side->setMark(getMark());
			}

			for(int irib=0; irib<4; irib++){
				Rib* rib = cell->getRib(axis, irib);
/*
				if((rib->getCell(Cell::ur) == NULL || isBorder(rib->getCell(Cell::ur))) 
					&& (rib->getCell(Cell::ul) == NULL || isBorder(rib->getCell(Cell::ul)))
					&& (rib->getCell(Cell::dl) == NULL || isBorder(rib->getCell(Cell::dl)))
					&& (rib->getCell(Cell::dr) == NULL || isBorder(rib->getCell(Cell::dr)))
				  )
*/
					rib->setMark(getMark());
			}
		}
	}
Exemple #11
0
bool OukBoard::inCheck(Side side, int square) const
{
	int sign = (side == Side::White) ? 1 : -1;
	Side opSide = side.opposite();
	if (square == 0)
		square = kingSquare(side);

	// Attack by Advisor (Maiden, Neang), initial move
	if (!m_moveCount[opSide][Maiden]
	&&  m_initialSquare[opSide][Maiden] == square - 2 * sign * (width() + 2))
		return true;

	// Attack by King, initial move
	int ksq = kingSquare(opSide);
	bool attacked = (ksq == square - 8 * sign || ksq == square - 12 * sign);

	if (!m_moveCount[opSide][King] && attacked)
	{
		if (square == kingSquare(side)
		|| !inCheck(opSide))
			return true;
	}
	return MakrukBoard::inCheck(side, square);
}
	public: double getBorderFlowOnSide(Rib* rib, int sideIndex, int flowIndex){
		Side* side = rib->getSide(sideIndex);
		return side->getFlow(flowIndex);
	};
Exemple #13
0
bool SideCollision::isCollision ( ) {
	Side* s = (Side*) o;
	Ball* b = (Ball*) p;	// pallina vera
	Ball* d;		// pallina fittizzia per gestire il bordo stondato
	bool ret;
	
	#if DEBUG > 1
	cout << "Guardo se c'e' veramente scontro fra la pallina ";
	b->print();
	cout << "e il bordo ";
	s->print();
	#endif
	
	// posizione nuova della pallina
	bb.pos = b->pos + dt * b->vel;
	bb.vel = b->vel;
	
	
	// gestione scontro col bordo
	if ( s->isInside( bb.pos ) ) {
		#if DEBUG > 1
		cout << "Controllo eventuale collisione EASY.\n";
		#endif
		
		if ( ( ( s->type == VERTICAL ) && ( fabs( b->vel.x ) >= EPSILON ) ) || 
		     ( ( s->type == ORIZONTAL ) && ( fabs( b->vel.y ) >= EPSILON ) ) ) {
			type = EASY;
			ret = true;
		} else ret = false;
	} else {
		#if DEBUG > 1
		cout << "Controllo eventuale collisione HARD.\n";
		#endif
		
		if ( s->type == VERTICAL ) {
			//s->a.print();
			if ( bb.pos.y < s->beg.y ) d = &(s->a);
			else d = &(s->b);
		} else {
			//s->a.print();
			if ( bb.pos.x < s->beg.x ) d = &(s->a);
			else d = &(s->b);
		}
		
		//d->print();
		//b->print();
		// TODO
		c.set( d, b, dt );
		ret = c.isCollision();
		if ( ret ) type = HARD;
	}
	
	
	#if DEBUG > 1
	if ( ret )
		cout << "Ci sara' collisione.\n";
	else	cout << "Non ci sara' collisione.\n";
	#endif
	
	return ret;
}