Source Code (Use browser search to find items of interest.)

Class Index

ksirtet'AIPiece (./kdegames/ksirtet/ai.h:17)

class AIPiece
{
 public:
	AIPiece() {}
	AIPiece(const Piece *, const Board *);

	void reset();
	void place(Board *);
	void setPoints(double);
	bool increment();
	enum Order { RotateRight, RotateLeft, MoveRight, MoveLeft, NoOrderLeft };
	Order emitOrder();

 private:
	uint   nbPos, nbRot, curPos, curRot;
	uint   betterRot;
	int    curDec, betterDec;
	double betterPoints;
	const Piece *piece;
};


ksirtet'AIPiece::AIPiece() (./kdegames/ksirtet/ai.cpp:16)

AIPiece::AIPiece(const Piece *p, const Board *b)
: piece(p)
{
	nbPos = b->matrix().width() - p->width() + 1;
	nbRot = p->nbConfigurations();
}


ksirtet'AIPiece::reset() (./kdegames/ksirtet/ai.cpp:23)

void AIPiece::reset()
{
	curPos = 0;
	curRot = 0;
}


ksirtet'AIPiece::increment() (./kdegames/ksirtet/ai.cpp:29)

bool AIPiece::increment()
{
	curPos++;
	if ( curPos==nbPos ) {
		if ( curRot==nbRot ) return TRUE;
		curPos = 0;
		curRot++;
	}
	return FALSE;
}


ksirtet'AIPiece::setPoints() (./kdegames/ksirtet/ai.cpp:40)

void AIPiece::setPoints(double points)
{
	if ( (curPos==0 && curRot==0)  // first move
		 || points>betterPoints) { // better move
		betterPoints = points;
		betterRot    = curRot;
		betterDec    = curDec;
	}
}


ksirtet'AIPiece::place() (./kdegames/ksirtet/ai.cpp:50)

void AIPiece::place(Board *b)
{
	if ( curRot==3 ) b->rotateRight();
	else for (uint i=0; i<curRot; i++) b->rotateLeft();
	curDec = curPos - b->currentCol() - piece->minX();
	b->moveTo(curDec, 0);

	b->dropDown();	
}

AIPiece::Order AIPiece::emitOrder()
{
	if ( betterRot==3 ) {
		betterRot = 0;
		return RotateRight;
	} else if (betterRot) {
		betterRot--;
		return RotateLeft;
	} else if ( betterDec>0 ) {
		betterDec--;
		return MoveRight;
	} else if ( betterDec<0 ) {
		betterDec++;
		return MoveLeft;
	} else return NoOrderLeft;
}

//-----------------------------------------------------------------------------