Exemplo n.º 1
0
void
TUIGame::play() {
    handleCommand("new");
    while (true) {
        // Print last move
        if (currentMove > 0) {
            Position prevPos(getPos());
            prevPos.unMakeMove(moveList[currentMove - 1], uiInfoList[currentMove - 1]);
            std::string moveStr= TextIO::moveToString(prevPos, moveList[currentMove - 1], false);
            if (haveDrawOffer())
                moveStr += " (offer draw)";
            std::cout << "Last move: " << prevPos.getFullMoveCounter()
                    << (prevPos.isWhiteMove() ? "." : "...")
                    << ' ' << moveStr << std::endl;
        }
        /*
        {
            std::stringstream ss;
            ss << "Hash: " << std::hex << std::setw(16) << std::setfill('0') << pos.zobristHash();
            std::cout << ss.str() << std::endl;
        }
        */
        {
            auto et = Evaluate::getEvalHashTables();
            Evaluate eval(*et);
            int evScore = eval.evalPos(getPos()) * (getPos().isWhiteMove() ? 1 : -1);
            std::stringstream ss;
            ss.precision(2);
            ss << std::fixed << "Eval: " << (evScore / 100.0);
            std::cout << ss.str() << std::endl;
        }

        // Check game state
        std::cout << TextIO::asciiBoard(getPos());
        std::string stateStr = getGameStateString();
        if (stateStr.length() > 0)
            std::cout << stateStr << std::endl;
        if (getGameState() != Game::ALIVE)
            activateHumanPlayer();

        // Get command from current player and act on it
        Player& pl = getPos().isWhiteMove() ? *whitePlayer : *blackPlayer;
        std::vector<Position> posList;
        getHistory(posList);
        std::string moveStr = pl.getCommand(getPos(), haveDrawOffer(), posList);
        if (moveStr == "quit")
            return;
        bool ok = processString(moveStr);
        if (!ok)
            std::cout << "Invalid move: " << moveStr << std::endl;
    }
}
Exemplo n.º 2
0
void Player::update(sf::Time dT, std::vector<Wall> walls)
{
    sf::Vector2f prevPos(this->getPosition());
    sf::Vector2f movement(0.f, 0.f);

    if(_movingUp)
        movement.y -= _speed;
    if(_movingDown)
        movement.y += _speed;
    if(_movingLeft)
        movement.x -= _speed;
    if(_movingRight)
        movement.x += _speed;

    if(_movingUp || _movingDown || _movingLeft || _movingRight)
    {
        rotate(movement);
        this->move(movement * dT.asSeconds());

        for(Wall wall: walls)
        {
            if(this->getGlobalBounds().intersects(wall.getGlobalBounds()))
                this->setPosition(prevPos);
        }

        if(!_walking)
            _animator.playAnimation("walking", true);
        _walking = true;
    }
    else
    {
        if(_walking)
            _animator.playAnimation("standing");
        _walking = false;
    }

    _animator.update(dT);
    _animator.animate(*this);
}
Exemplo n.º 3
0
Arquivo: Main.cpp Projeto: Seyfel/SGI
void drawRoad() {
	GLfloat Em[] = { 0.0, 0.0, 0.0, 1.0 };
	GLfloat Am[] = { 0.2, 0.2, 0.2, 1.0 };
	GLfloat Dm[] = { 0.8, 0.8, 0.8, 1.0 };
	GLfloat Sm[] = { 0.3, 0.3, 0.3, 1.0 };
	GLfloat s = 3.0;
	glMaterialfv(GL_FRONT, GL_EMISSION, Em);
	glMaterialfv(GL_FRONT, GL_AMBIENT, Am);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Dm);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Sm);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, s);

	//RenderUtils::quads(Pointf(0, 0, 0), Pointf(4, 0, 1), Pointf(0, 3, 2), Pointf(5, 4, -2), 10, 10);


	float sinAmplitude = 5;
	float sinPeriod = 50;
	float roadWidth = 5;
	float lightDistance = 50/4;
	int frontLength = 50;
	int backLength = 15;

	glColor3f(.1, 0.1, 0.1);

	static GLfloat posicionFarola1[] = { sinAmplitude * sin(-0 * lightDistance * (Constants::pi / (sinPeriod / 2))), 4, -0 * lightDistance, 1.0 };
	static GLfloat posicionFarola2[] = { sinAmplitude * sin(-1 * lightDistance * (Constants::pi / (sinPeriod / 2))), 4, -1 * lightDistance, 1.0 };
	static GLfloat posicionFarola3[] = { sinAmplitude * sin(-2 * lightDistance * (Constants::pi / (sinPeriod / 2))), 4, -2 * lightDistance, 1.0 };
	static GLfloat posicionFarola4[] = { sinAmplitude * sin(-3 * lightDistance * (Constants::pi / (sinPeriod / 2))), 4, -3 * lightDistance, 1.0 };

	float z = camera.position.z + backLength;

	
	if (std::abs(camera.position.z) > std::abs(posicionFarola1[2] - lightDistance / 2)) {
		posicionFarola1[0] = posicionFarola2[0];
		posicionFarola1[2] = posicionFarola2[2];

		posicionFarola2[0] = posicionFarola3[0];
		posicionFarola2[2] = posicionFarola3[2];

		posicionFarola3[0] = posicionFarola4[0];
		posicionFarola3[2] = posicionFarola4[2];

		posicionFarola4[2] -= lightDistance;
		posicionFarola4[0] = sinAmplitude * sin(posicionFarola4[2] * (Constants::pi / (sinPeriod / 2)));
	}

	glLightfv(GL_LIGHT2, GL_POSITION, posicionFarola1);
	glLightfv(GL_LIGHT3, GL_POSITION, posicionFarola2);
	glLightfv(GL_LIGHT4, GL_POSITION, posicionFarola3);
	glLightfv(GL_LIGHT5, GL_POSITION, posicionFarola4);

	float roadZ = z;
	float roadX = sinAmplitude * sin(roadZ * (Constants::pi / (sinPeriod / 2)));
	float tgAlpha = (Constants::pi / sinAmplitude) * sin(roadZ * (Constants::pi / (sinPeriod / 2)));

	GLVector3f::GLVector3f perp(-1, 0, tgAlpha);
	GLVector3f::GLVector3f n = GLVector3f::normalize(perp);
	GLVector3f::GLVector3f scaled = GLVector3f::scale(n, roadWidth);

	Pointf prevPos(roadX + scaled.x, 0, roadZ + scaled.z);
	Pointf prevNeg(roadX - scaled.x, 0, roadZ - scaled.z);

	for (int i = 1; i <= frontLength + backLength; i++) {
		float roadZ = z - i;
		float roadX = sinAmplitude * sin(roadZ * (Constants::pi / (sinPeriod / 2)));
		float tgAlpha = (Constants::pi / sinAmplitude) * sin(roadZ * (Constants::pi / (sinPeriod / 2)));

		GLVector3f::GLVector3f perp(-1, 0, tgAlpha);
		GLVector3f::GLVector3f n = GLVector3f::normalize(perp);
		GLVector3f::GLVector3f scaled = GLVector3f::scale(n, roadWidth);

		Pointf actualPos(roadX + scaled.x, 0, roadZ + scaled.z);
		Pointf actualNeg(roadX - scaled.x, 0, roadZ - scaled.z);

		RenderUtils::quads(prevPos, prevNeg, actualPos, actualNeg, 32, 32);

		prevPos = actualPos;
		prevNeg = actualNeg;
	}
}
Exemplo n.º 4
0
//====================================================================
// DebugDrawRangePolygon
//====================================================================
void CAIDebugRenderer::DrawRangePolygon(const Vec3 polygon[], int nVertices, float fWidth,
													 const ColorB& colorFill, const ColorB& colorOutline, bool bDrawOutline)
{
	static std::vector<Vec3>		verts;
	static std::vector<vtx_idx>	tris;
	static std::vector<Vec3>		outline;

	if (nVertices < 3) return;

	Vec3	prevDir(polygon[0] - polygon[nVertices - 1]);
	prevDir.NormalizeSafe();
	Vec3	prevNorm(-prevDir.y, prevDir.x, 0.0f);
	prevNorm.NormalizeSafe();
	Vec3	prevPos(polygon[nVertices - 1]);

	verts.clear();
	outline.clear();

	const Vec3* li, * linext;
	const Vec3* liend = polygon + nVertices;
	for (li = polygon; li != liend ; ++li)
	{
		linext = li;
		++linext;
		if (linext == liend)
			linext = polygon;

		const Vec3&	curPos(*li);
		const Vec3&	nextPos(*linext);
		Vec3	vDir(nextPos - curPos);
		Vec3	norm(-vDir.y, vDir.x, 0.0f);
		norm.NormalizeSafe();

		Vec3	mid((prevNorm + norm) * 0.5f);
		float	dmr2 = sqr(mid.x) + sqr(mid.y);
		if (dmr2 > 0.00001f)
			mid *= 1.0f / dmr2;

		float	cross = prevDir.x * vDir.y - vDir.x * prevDir.y;

		outline.push_back(curPos);

		if (cross < 0.0f)
		{
			if (dmr2 * sqr(2.5f) < 1.0f)
			{
				// bevel
				verts.push_back(curPos);
				verts.push_back(curPos + prevNorm * fWidth);
				verts.push_back(curPos);
				verts.push_back(curPos + norm * fWidth);
			}
			else
			{
				verts.push_back(curPos);
				verts.push_back(curPos + mid * fWidth);
			}
		}
		else
		{
			verts.push_back(curPos);
			verts.push_back(curPos + mid * fWidth);
		}

		prevDir = vDir;
		prevNorm = norm;
		prevPos = curPos;
	}

	tris.clear();
	size_t	n = verts.size()/2;
	for (size_t i = 0; i < n; ++i)
	{
		size_t	j = (i + 1) % n;
		tris.push_back(i*2);
		tris.push_back(j*2);
		tris.push_back(j*2+1);

		tris.push_back(i*2);
		tris.push_back(j*2+1);
		tris.push_back(i*2+1);
	}

	m_pRenderer->GetIRenderAuxGeom()->DrawTriangles(&verts[0], verts.size(), &tris[0], tris.size(), colorFill);
	if (bDrawOutline)
		DrawPolyline(&outline[0], outline.size(), true, colorOutline);
}