Exemplo n.º 1
0
void PositionNoOfficer::undo(const Move m) {
	// std::cerr << "PositionNoOfficer::undo(" << m.toString() << ");" << std::endl;

	// move_history.pop_back();
	switchTurn();

	bitb.move(m.to(), m.from(), turn);
	std::swap(tower[m.to()], tower[m.from()]);

	if (m.isPromotion()) {
		tower[m.from()].degrade();
		bitb.bits[turn+2] &= ~(1<<m.from());
	}	

	if (m.isJump()) {
		unsigned int other = !turn;
		for (unsigned int j = m.size(); j; j--) {	// cause unsigned
			unsigned int over = m.over(j-1);	// substract here
			if (tower[over].empty()) {			// last stone of tower was captured
				bitb.set(over, tower[m.from()].back());
			} else if (tower[over].color() == turn) {	// color change
				bitb.switchColor(over, other);
			}
			const bool iso = tower[over].isOfficer();
			tower[over].push(tower[m.from()].pop_back());	// restore stone on top of tower
			if      ( iso && !tower[over].isOfficer()) bitb.degrade (over, other);
			else if (!iso &&  tower[over].isOfficer()) bitb.promote (over, other);
		}
	}
}
Exemplo n.º 2
0
bool TicTacToe::handleEvent(const sf::Event& event, const sf::Window& relativeTo)
{
    if(event.type == sf::Event::MouseMoved)
        m_lastPointerLoc = sf::Vector2f(sf::Mouse::getPosition(relativeTo).x, sf::Mouse::getPosition(relativeTo).y);

    if(m_multi || (!m_multi && m_turn != m_iaColor))
    {
        if(event.type == sf::Event::MouseButtonReleased && event.mouseButton.button == sf::Mouse::Left )
        {
            sf::Vector2f mousePos(sf::Mouse::getPosition(relativeTo).x, sf::Mouse::getPosition(relativeTo).y);
            if(mousePos.x > OFFSET_X && mousePos.x < OFFSET_X + GRID_SIZE*CASE_SIZE
               && mousePos.y > OFFSET_Y && mousePos.y < OFFSET_Y + GRID_SIZE*CASE_SIZE)
            {
                int caseX = (mousePos.x - OFFSET_X) / CASE_SIZE;
                int caseY = (mousePos.y - OFFSET_Y) / CASE_SIZE;

                if(m_grid[caseY][caseX] == NONE)
                {
                    m_grid[caseY][caseX] = m_turn;
                    switchTurn();
                }
            }
        }
    }


    return false;
}
Exemplo n.º 3
0
void PositionNoOfficer::move(const Move m) {
	// std::cerr << "PositionNoOfficer::move(" << m.toString() << ");" << std::endl;

	// move_history.push_back(m);

	bitb.move(m.from(), m.to(), turn);
	std::swap(tower[m.to()], tower[m.from()]);			// swap towers

	assert (bitb.isOfficer(m.to(), turn) == tower[m.to()].isOfficer());
	if (m.isOnPromotionSquare() && !tower[m.to()].isOfficer()) {	// move promotes
		tower[m.to()].promote();
		bitb.bits[turn+2] |= (1<<m.to());
	}

	if (m.isJump()) {
		unsigned int other = !turn;
		for (unsigned int j = 0; j<m.size(); j++) {		// captures
			unsigned int over = m.over(j);
			const bool iso = tower[over].isOfficer();
			tower[m.to()].push_back(tower[over].pop());	// add captured stone ot turns tower
			if      ( iso && !tower[over].isOfficer()) bitb.degrade (over, other);
			else if (!iso &&  tower[over].isOfficer()) bitb.promote (over, other);
			if (tower[over].empty()) {			// last stone of tower captured
				bitb.erase(over, other);
			} else if (tower[over].color() == turn) {	// color switch
				bitb.switchColor(over, turn);
			}						// if color remains same after hit, nothing to do.
		}
	}

	switchTurn();
}
Exemplo n.º 4
0
void Sea::checkGameOver()
{
    if (otherField()->ships() <= 0) {
        m_status = m_turn == PLAYER_A ? A_WINS : B_WINS;
    }
    else {
        switchTurn();
    }
}
Exemplo n.º 5
0
void TicTacToe::update(const sf::Time& frameTime)
{
    if(m_winner == TicTacToe::NONE)
    {
        //test s'il y a un vainqueur
        for(unsigned int i=0; i<GRID_SIZE && m_winner == TicTacToe::NONE; i++)
        {
            //test horizontal
            if(m_grid[i][0] != TicTacToe::NONE && m_grid[i][0] == m_grid[i][1] && m_grid[i][1] == m_grid[i][2])
                m_winner = m_grid[i][0];

            //test vertical
            if(m_grid[0][i] != TicTacToe::NONE && m_grid[0][i] == m_grid[1][i] && m_grid[1][i] == m_grid[2][i])
                m_winner = m_grid[0][i];

            //test des diagonales
            if(m_grid[1][1] != TicTacToe::NONE && m_grid[0][0] == m_grid[1][1] && m_grid[1][1] == m_grid[2][2])
                m_winner = m_grid[1][1];

            if(m_grid[1][1] != TicTacToe::NONE && m_grid[0][2] == m_grid[1][1] && m_grid[1][1] == m_grid[2][0])
                m_winner = m_grid[1][1];
        }

        if(m_winner == TicTacToe::NONE)
        {
            //test s'il reste des coup possibles
            bool full = true;

            for(unsigned int i = 0; i< GRID_SIZE; i++)
                for(unsigned int j =0; j< GRID_SIZE; j++)
                    if(m_grid[i][j] == TicTacToe::NONE)
                        full = false;
            if(full)
            {
                m_winner = TicTacToe::TIE;
                Starter::game.m_menu.setActiveMenu(Menu::EndGame);
            }
            else if(m_winner == TicTacToe::NONE && !m_multi && m_turn == m_iaColor)
            {
                int x, y;
                do {
                    x=rand()%GRID_SIZE;
                    y=rand()%GRID_SIZE;
                } while(m_grid[y][x] != TicTacToe::NONE);
                m_grid[y][x] = m_iaColor;
                switchTurn();
            }
        }
        else
        {
            Starter::game.m_menu.setActiveMenu(Menu::EndGame);
        }

    }
}
Exemplo n.º 6
0
void LaserTrap::update(float dTime)
{
	if(m_IsOn)
	{
		m_AccTime += dTime;
		if(m_AccTime > m_Duration)
		{
			m_AccTime = 0.f;
			m_IsOn = false;
			switchTurn(m_IsOn);
		}
	}
	else
	{
		auto time = GET_GAME_MANAGER()->getTime();
		if((time.tv_sec) % MAX_INTERVAL == m_Interval - 1 )
		{
			m_IsOn = true;
			GET_SOUND_MANAGER()->createSound(SoundManager::LASERTRAP, false, getPosition());
			switchTurn(m_IsOn);
		}
	}
}
Exemplo n.º 7
0
void Position::move(const Move m) {
	// std::cerr << "Position::move(" << m.toString() << ");" << std::endl;

	// move_history.emplace_back(m);

	updateHashKey		(m, m.from());				// needs to know square where moving tower is, i.e., pre or post move
	value -= moveValue	(m, m.from());				// "

	bitb.move(m.from(), m.to(), turn);
	std::swap(tower[m.to()], tower[m.from()]);			// swap towers

	assert (bitb.isOfficer(m.to(), turn) == tower[m.to()].isOfficer());
	if (m.isOnPromotionSquare() && !tower[m.to()].isOfficer()) {	// move promotes
		tower[m.to()].promote();
		bitb.bits[turn+2] |= (1<<m.to());
	}

	if (m.isJump()) {
		unsigned int other = !turn;
		for (unsigned int j = 0; j<m.size(); j++) {		// captures
			unsigned int over = m.over(j);
			const bool iso = tower[over].isOfficer();
			tower[m.to()].push_back(tower[over].pop());	// add captured stone to turns tower
			if      ( iso && !tower[over].isOfficer()) bitb.degrade (over, other);
			else if (!iso &&  tower[over].isOfficer()) bitb.promote (over, other);
			// bitb.setGrade(over, other, tower[over].isOfficer());
			if (tower[over].empty()) {			// last stone of tower captured
				bitb.erase(over, other);
			} else if (tower[over].color() == turn) {	// color switch
				bitb.switchColor(over, turn);
			}						// if color remains same after hit, nothing to do.
		}
	}

	checkTowerKeys		(m);					// beside constructor only place where hash keys for a tower may not exist
	updateHashKey		(m, m.to());				// needs to know square where moving tower is, i.e., pre or post move
	value += moveValue	(m, m.to());				// "

	pos_stack.emplace(pos_key);
	assert(pos_key == generateKey());
	assert(value == evaluateTowers());

	switchTurn();
}
Exemplo n.º 8
0
//Handles cell select by player
void Game::OnLButtonDown(int mX, int mY) {

	//If round is currently finished or its computer turn, then dont allow to recieve input
	if (roundOver || (gameType == 1 && currentPlayer == 1)) {
		return;
	}

	//Finds cell based on mouse coordinates
    int ID = mX / 200;
    ID = ID + ((mY / 200) * 3);
 
    if (gridRows[ID] != GRID_TYPE_NONE) {
        return;
    }

    setCell(ID, currentPlayer);
	checkForWin();
	switchTurn();
}
Exemplo n.º 9
0
//vertical인 경우 바닥에, horizontal인 경우 왼쪽 벽에 붙여주시죠.
void LaserTrap::setLaser(bool isVertical, int interval)
{
	cocos2d::Rect bodyRect;
	if(isVertical)
	{
		cocos2d::Point curPos = getPosition();
		cocos2d::Size tileSize = GET_DATA_MANAGER()->getTileSize();
		cocos2d::Size moveUnit(0, tileSize.height);
		cocos2d::Point checkPos = curPos - moveUnit; //아래쪽 타일
		int stageNum = GET_STAGE_MANAGER()->getStageNum();
		int roomNum = GET_STAGE_MANAGER()->getRoomNum();
		int checkType = OT_START;

		//제대로 세팅했는지 검사
		checkType = GET_DATA_MANAGER()->getTileData(stageNum, roomNum, checkPos);
		if(checkType != OT_BLOCK)
		{
			cocos2d::log("laser set in wrong position.");
			return;
		}

		auto lower = GET_RESOURCE_MANAGER()->createSprite(ST_LASER_LOWER);
		auto upper = GET_RESOURCE_MANAGER()->createSprite(ST_LASER_UPPER);
		addChild(lower);
		addChild(upper);
		lower->setAnchorPoint(cocos2d::Point::ZERO);
		upper->setAnchorPoint(cocos2d::Point::ZERO);
		lower->setPosition(cocos2d::Point(0, 0));

		m_Laser = cocos2d::Sprite::create();
		addChild(m_Laser, -1);
		m_Laser->setAnchorPoint(cocos2d::Point::ZERO);

		checkType = OT_START;
		checkPos = curPos;
		int height = 0;
		while(true)
		{
			checkType = GET_DATA_MANAGER()->getTileData(stageNum, roomNum, checkPos);
			auto laser = GET_RESOURCE_MANAGER()->createSprite(ST_LASER_RELEASE);
			m_Laser->addChild(laser);
			laser->setPosition(cocos2d::Point(0, height));
			laser->setAnchorPoint(cocos2d::Point::ZERO);
			if(checkType == OT_BLOCK)
			{
				break;
			}
			height += tileSize.height;
			checkPos += moveUnit;
			if(height > MAX_HEIGHT)
			{
				this->release();
				return;
			}
		}

		if(checkType == OT_BLOCK)
		{
			upper->setPosition(cocos2d::Point(0, height - tileSize.height));
		}
		bodyRect = cocos2d::Rect(tileSize.width / 2, 0, LASER_WIDTH, height);
	}
	initPhysicsBody(bodyRect, PHYC_TRAP);
	m_Interval = interval - OT_LASER;
	switchTurn(m_IsOn);
}