Пример #1
0
void Dijkstra::pushChild(char id, const Element& parentNode, Visited& visited, Priority& priority, Graph &network,double startTime) {
	double cost= findCost(id,parentNode,network,startTime); // get the cost of the node...from the unique function

	if (visited.find(id) == visited.end()) { // Element is not in visited map -> add it
		//visited.insert(std::pair<char,Element>(id,Element(id,cost,parentNode.id))); - we are going to check if visited later
		Element newnode;
		newnode.id=id;newnode.cost=cost;newnode.parent=parentNode.id;
		newnode.parents.push_back(parentNode.id);
		priority.push(newnode);
	}
	else { // if the current cost is less than or equal to the elements cost then we may need to update the map
		if (cost == visited.at(id).cost){ // we have found the node at the same cost... we need to put it as a parent as well
			visited[id].parents.push_back(parentNode.id);
		}
		else if (cost < visited.at(id).cost){ // need to look at node again
			visited[id].cost=cost;
			priority.push(visited[id]);
		}
	}
}
Пример #2
0
void MonopolyGame::handleReaction() {
	/* This state is called when a player lands on a board space.
	 *  If the property is owned, pay the appropriate rent.
	 *  If unowned, present the title, and ask to purchase.
	 *  Pay tax if required.
	 *  If the player passed go, collect $200
	 *  If a card is drawn, move phase may be called again, and then immediately set back to REACT_PHASE.
	 */
	int pLoc = m_playerList[m_playersTurn].get_location();

	// First lets ensure our player hasn't rolled 3 doubles.
	if( m_doublesRollCounter >= 3 ) {
		m_doublesRollCounter = 0;
		m_playerList[m_playersTurn].set_inJail( true );
		m_turnState = TurnState::POST_TURN;
	}
	// Now check if the property the player is currently on is owned
	//  but someone other than the current player and the propery is not mortgaged.
	else if( m_propertyList[pLoc].get_isOwned() &&
		m_propertyList[pLoc].get_ownedBy() != m_playersTurn &&
		m_propertyList[pLoc].get_propertyValue() != PropertyValue::VAL_MORTGAGED ) {

		int rentDue = findCost( m_propertyList[pLoc] );
		if( m_playerList[m_playersTurn].get_money() < rentDue ) {
			m_turnState = TurnState::POST_TURN;
		}
		else {

			// Get the player's wallet size, and subtract the property value from it.
			rentDue -= m_playerList[m_playersTurn].get_money();
			m_playerList[m_playersTurn].set_money( rentDue );
		}

	}
	else if( !m_propertyList[pLoc].get_isOwned() ) {
		// Buy a free property.
	}
}