示例#1
0
文件: Grid.cpp 项目: amecky/breakout
// -------------------------------------------------------
// move down
// -------------------------------------------------------
bool Grid::moveDown() {
	if (_limit == 0) {
		return false;
	}
	// FIXME: check if we can even move down
	ds::SID ids[256];
	int num = _world->find_by_type(OT_BRICK, ids, 256);
	Vector2i gp;
	for (int i = 0; i < num; ++i) {
		v2 p = _world->getPosition(ids[i]);
		if (convertToGrid(p, &gp)) {
			_board[gp.x][gp.y] = ds::INVALID_SID;
			_board[gp.x][gp.y - 1] = ids[i];
			if (gp.y - 1 < 0) {
				// game over
			}
			else {
				_world->scaleTo(ids[i], v2(0.7f, 0.7f), v2(1, 1), 0.4f, 0, tweening::easeInOutQuad);
				_world->moveTo(ids[i], p, v2(p.x, p.y - GDY), 0.4f, 0, tweening::easeInOutQuad);
			}
		}
	}

	findLimit();

	num = _world->find_by_type(OT_NEW_BRICK, ids, 256);
	for (int i = 0; i < num; ++i) {
		v2 p = _world->getPosition(ids[i]);
		gp.y = 0;
		gp.x = (p.x - GSX) / GDX;
		int r = -1;
		for (int j = GMY - 1; j >= 0; --j) {
			if (r == -1 && _board[gp.x][j] != ds::INVALID_SID) {
				r = j;
			}
		}		
		r += 1;
		if (r == -1) {
			r = _limit;
		}
		if (r < _limit) {
			r = _limit;
		}
		LOG << "p.x " << gp.x << " r " << r;
		_board[gp.x][r] = ids[i];
		_world->setType(ids[i], OT_BRICK);
		_world->attachBoxCollider(ids[i], OT_BRICK, 0);
		v2 np;
		if (convertFromGrid(gp.x, r, &np)) {
			_world->moveTo(ids[i], p, np, 0.4f, 0, tweening::easeInOutQuad);
		}
	}
	return true;
	//debug();
}
示例#2
0
template<> QList<dpoint> Spirals<dpoint>::findSpiralCliffs(ListCopyable<dpoint> toBeProcessed){
    ListCopyable<dpoint> forward = ListCopyable<dpoint>(toBeProcessed);

    //qreal frontSpiral= toBeProcessed.measureSpiral();
    //debug()<<"Forward Spiral Size is: "<<frontSpiral;
    qreal limit = findLimit(toBeProcessed);
    debug()<<"Limit from forward analysis is: "<<limit;

    // TODO
    //this should be a copy!
    Analyzer<dpoint> reversed = Analyzer<dpoint>(toBeProcessed);
    //reversed.tripletFilters();
    reversed.reverseOrder();
    //qreal backSpiral= reversed.measureSpiral();
    //debug()<<"Backward Spiral Size is: "<<backSpiral;
    ListCopyable<dpoint> backward = ListCopyable<dpoint>(reversed);
    qreal backLimit = findLimit(backward);
    debug()<<"Limit from backward analysis is: "<<backLimit;
    //if (static_cast<int>(frontSpiral)!=static_cast<int>(backSpiral)){
        //throw "ShapeMatcher::process: spiral-size front/back not equal";
    //}

    // change: use reference?
    QList<dpoint>* cliffs = new QList<dpoint>;
    if (limit!=backLimit){
        debug()<< "ShapeMatcher::process: different limits found, using larger";
        if (backLimit>limit){
            *cliffs = findAreas(backward,backLimit);
            //if (cliffs->size()>0){
            Calculator<dpoint> calc = Calculator<dpoint>(*cliffs);
            calc.reverse();
            *cliffs = calc;
            //}
        } else {
            *cliffs = findAreas(forward,limit);
        }
    } else {
        debug()<<"******************* findAreas::Main **********************";
        *cliffs = findAreas(forward,limit);
    }
    return *cliffs;
}
示例#3
0
int
RotationShearCurve::checkElementState(double springForce)
{	
	double shearForce = fabs(springForce);	
	getElemForces();	
	const Vector &dispI = theNodeI->getTrialDisp();
	const Vector &dispJ = theNodeJ->getTrialDisp();
	double rotDef = fabs(dispJ(rotAxis-1) - dispI(rotAxis-1));

	if (stateFlag == 0)
	{
		if (Vn == 0.0) {
			double ShearForceLimit = findCritLimit(shearForce, M);
			if(shearForce >= ShearForceLimit) {
				stateFlag = 1;
				setDegSlope(shearForce);
			}
		}
		else if (Vn > 0.0) {
			if (shearForce >= Vn) {
				stateFlag = 1;
				setDegSlope(shearForce);
			}
		}
		if (defType == 0) {
			if (rotDef >= rotLim) {
				stateFlag = 1;
				setDegSlope(shearForce);
			}
		} else {
			double shearRotLimit = findLimit(shearForce);
			if ((rotDef >= shearRotLimit) && (rotDef >= thetaMin)) {
				stateFlag = 1;
				setDegSlope(shearForce);
			}
		}
	}
	else 
	{
		stateFlag = 2;
	}
	return stateFlag;
}
示例#4
0
文件: ai.c 项目: JiweiLiu/Scrabble-1
void makeMove(player you, rackRef yourRack, Trie dictionary) {
    strncpy(myRack, yourRack, RACK_SIZE+1);
    me = you;
    bestScore = INITIAL;
    dict = dictionary;

    word emptyWord = {INVALID_LETTER};
    word startingPartialWord = {INVALID_LETTER};

    int i, j;
    direction d;
    for(d=HORIZONTAL;d<=VERTICAL;d++) {
        D("DIRECTION: %d\n",d);
        findAnchors(d);

        for(i=0;i<BOARD_SIZE;i++) {
            for(j=0;j<BOARD_SIZE;j++){
                strncpy(startingPartialWord, emptyWord, BOARD_SIZE);
                if(anchors[i][j]) {
//                if(getCell(i,j) != INVALID_LETTER) {
                    D("finding word from (%d,%d)\n",i,j);
                    int limit = findLimit(i, j, d);
                    if(limit > 0) {
                        leftPart(startingPartialWord, dict,
                                 findLimit(i, j, d), d, i, j);
                    } else {
                        int spwLength = 0;

                        // we already have a left part
                        int row = i;
                        int col = j;

                        int rowChange = 0;
                        int colChange = 0;

                        if(d == HORIZONTAL) {
                            colChange = -1;
                        } else if(d == VERTICAL) {
                            rowChange = -1;
                        }

                        row += rowChange;
                        col += colChange;

                        while(row >= 0 && col >= 0 &&
                              row < BOARD_SIZE && col < BOARD_SIZE) {
                            startingPartialWord[spwLength] = getCell(row, col);
                            spwLength++;

                            row += rowChange;
                            col += colChange;
                        }

                        // reverse the part
                        int k;
                        for(k=0;k<spwLength;k++) {
                            letter temp = startingPartialWord[k];
                            startingPartialWord[k] = startingPartialWord
                                                        [spwLength-k-1];
                            startingPartialWord[spwLength-k-1] = temp;
                        }

                        // extend to the right
                        extendRight(startingPartialWord, dict, d,
                                    i, j, FALSE);
                    }
                }
            }
        }
    }

    if(bestScore == INITIAL) {
        D("DECIDED TO PASS\n");
        playMove(me, PASS, PASS, NULL, HORIZONTAL);
    } else {
        playMove(me, bestRow, bestCol, bestWord, bestDir);
    }
}
示例#5
0
// check if limit state surface has been reached
int
ShearCurve::checkElementState(double springForce)
{
  DummyStream dummy;
	// find associated beam-column elementon first visit
	if (theElement == 0)
	{
		theElement = theDomain->getElement(eleTag);

		if (theElement == 0) {
//			g3ErrorHandler->fatal("WARNING ShearCurve - no element with tag %i exists in Domain",eleTag);
		}
		// find length between nodes if drift is desired
		if (defType == 2)
		{
			Node *nodeI = theDomain->getNode(ndI);
			Node *nodeJ = theDomain->getNode(ndJ);

			const Vector &crdI = nodeI->getCrds();
			const Vector &crdJ = nodeJ->getCrds();

			if (crdI(perpDirn) == crdJ(perpDirn)) {
//				g3ErrorHandler->warning("%s -- Nodal projection has zero component along chosen direction",
//						"AxialCurve::AxialCurve");

				oneOverL = 0.0;
			}
			else 
				oneOverL = 1.0/fabs(crdJ(perpDirn) - crdI(perpDirn));
		}
	}

	double deform;	// value of deformation parameter from element
	double force;	// value of force parameter from element
	int result;		//junk variable


	// Based on "defType" and "forType" calculate 
	// the desired response parameters "deform" and "force"
	if (defType == 1) // maximum chord rotations
	{

		Response *theRotations =0; // integer element returns in setResponse

		const char *r[1] = {"basicDeformations"}; // must be implemented in element

		Vector *rotVec; //vector of chord rotations at beam-column ends

		// set type of beam-column element response desired
		theRotations = theElement->setResponse(r, 1, dummy);

		// put element response in the vector of "myInfo"
		result = theRotations->getResponse();

		// access the myInfo vector containing the response (new for Version 1.2)
		Information &theInfo = theRotations->getInformation();
		rotVec = (theInfo.theVector);

		deform = (fabs((*rotVec)(1)) > fabs((*rotVec)(2))) ? 
			fabs((*rotVec)(1)) : fabs((*rotVec)(2));  //use larger of two end rotations
	}
	else if (defType == 2) // interstory drift
	{
		// find associated nodes 
		Node *nodeI = theDomain->getNode(ndI);
		Node *nodeJ = theDomain->getNode(ndJ);


		// get displacements
		const Vector &dispI = nodeI->getTrialDisp();
		const Vector &dispJ = nodeJ->getTrialDisp();

//opserr << "Drift ndI: " << dispI(dof) << endln;
//opserr << "Drift ndJ: " << dispJ(dof) << endln;

		
		// calc drift
		double dx = fabs(dispJ(dof)-dispI(dof));
		deform = dx*oneOverL;
	}
	else {
//		g3ErrorHandler->fatal("WARNING ShearCurve - deformation type flag %i not implemented",defType);
	}

		Response *theForces =0;

		const char *f[1] = {"localForce"}; // does not include influence of P-delta
								     // for P-delta use forType = 0

		Vector *forceVec; //vector of basic forces from beam column

		// set type of beam-column element response desired
		theForces    = theElement->setResponse(f, 1, dummy);

		// put element response in the vector of "myInfo"
		result += theForces->getResponse();

		// access the myInfo vector containing the response (new for Version 1.2)
		Information &theInfo = theForces->getInformation();
		forceVec = (theInfo.theVector);

	// Local forces (assuming no element loads)
	if (forType == 0)
		force = fabs(springForce);    // force in associated LimitState material
	else if (forType == 1) 
		force = fabs((*forceVec)(1)); // shear
	else if (forType == 2) 
		force = fabs((*forceVec)(0)); // axial
	else {
//		g3ErrorHandler->fatal("WARNING ShearCurve - force type flag %i not implemented",forType);
	}

	P = fabs((*forceVec)(0));

	// Determine if (deform,force) is outside limit state surface.
	// 
	// Use absolute value of deform and force
	double forceSurface = findLimit(deform); // force on surface at deform

//	double deformSurface = findLimit(force); // deform on surface at force	SDK


//opserr << "The shear force in the element is: " << force << endln;


//opserr << "State flag............................:" << stateFlag << endln;
//opserr << "Shear force in the column.........: " << force << endln;
//opserr << "forceSurface: " << forceSurface << endln;

	if (stateFlag == 0) //prior to failure
	{
		if (force >= forceSurface) // on/outside failure surface
	//	  if (deform >= deformSurface) // on/outside failure surface	SDK

		{	
			stateFlag = 1;
			setDegSlope(force, deform);
//			g3ErrorHandler->warning("ShearCurve - failure detected at deform = %f (Kdeg = %f) ", deform, Kdeg);
//opserr << "*********************" << endln;
        opserr << "ShearCurve - failure detected....."<< endln;//SDK

       // opserr << "deformSurface: " << deformSurface << endln; //SDK
  
      



//opserr << "Capacity: " << forceSurface << endln;
//opserr << "*********************" << endln;
		}
		else // inside failure surface
		{
			stateFlag = 0;
		}
	}
	else //after failure
	{
		if (force >= forceSurface) // on/outside failure surface
		//  if (deform >= deformSurface) // on/outside failure surface SDK
		{	
			stateFlag = 2;
		}
		else // inside failure surface
		{
			stateFlag = 3;
		}
	}

	return stateFlag;
}