예제 #1
0
void Exercise6()
{
	Shop_Struct Shop;
	std::string input;

	while (true)
	{
		New("6");
		std::cout << "What would you like to do?" << std::endl << std::endl
			<< "a. Change the price of an item" << std::endl
			<< "b. Buy additional stock for an item" << std::endl
			<< "c. Sell stock to gain more gold" << std::endl
			<< "d. Exit shop" << std::endl << std::endl
			<< "Input: ";
		getline(std::cin, input);

		if ((input == "a")||(input == "a."))
			while (Pricing(Shop)) {}
		if ((input == "b") || (input == "b."))
			while (Buy(Shop)) {}
		if ((input == "c") || (input == "c."))
			while (Sell(Shop)) {}
		if ((input == "d") || (input == "d."))
			break;
	}
}
예제 #2
0
/**
 * Prepare bot for action
 */
bool CCFBot::Initialize( const BotProfile *profile, int team )
{
	// extend
	BaseClass::Initialize( profile, team );

	// CF bot initialization
	m_diedLastRound = false;
	m_morale = POSITIVE;			// starting a new round makes everyone a little happy

	m_combatRange = RandomFloat( 325.0f, 425.0f );

	// set initial safe time guess for this map
	m_safeTime = 15.0f + 5.0f * GetProfile()->GetAggression();

	m_name[0] = '\000';

	ResetValues();

	m_desiredTeam = team;

	if (GetTeamNumber() <= LAST_SHARED_TEAM)
	{
		ChangeTeam(m_desiredTeam);
	}

	Buy();

	return true;
}
	Deal Selector::Buy(const long k)
	{
		if (k <= 0)
		{
			return {};
		}

		auto &memo = memo_[k];
		if (memo.num_items != -1)
		{
			return memo;
		}

		Deal best_deal{ infinity, infinity };
		for (const auto& deal : deals_)
		{
			auto cumulative = Buy(k - deal.num_items);
			if (cumulative.num_items != -1)
			{
				cumulative.num_items += deal.num_items;
				cumulative.cost += deal.cost;
			}
			else
			{
				cumulative = deal;
			}

			if (cumulative.cost < best_deal.cost)
			{
				best_deal = cumulative;
			}
		}
		return memo = best_deal;
	}
예제 #4
0
//-----------------------------------------------------------------------------
// Button click handlers
//-----------------------------------------------------------------------------
void CResupplyControlPanel::OnCommand( const char *command )
{
	if (!Q_strnicmp(command, "BuyAmmo", 8))
	{
		Buy(RESUPPLY_BUY_AMMO);
	}
	else if (!Q_strnicmp(command, "BuyHealth", 10))
	{
		Buy(RESUPPLY_BUY_HEALTH);
	}
	else if (!Q_strnicmp(command, "BuyGrenades", 12))
	{
		Buy(RESUPPLY_BUY_GRENADES);
	}
	else if (!Q_strnicmp(command, "BuyAll", 7))
	{
		Buy(RESUPPLY_BUY_ALL);
	}
	else
	{
		BaseClass::OnCommand(command);
	}
}
예제 #5
0
bool CommonBuy(SUser *p_user, CVendibleData::SData *p_data, uint32 count, uint32 path)
{
    // 每日限购
    if (p_data->daily_limit_count > 0 && GetDailyCount(p_user, p_data->id) + count > p_data->daily_limit_count)
        return false;
    // 历史限购
    if (p_data->history_limit_count > 0 && GetHistoryCount(p_user, p_data->id) + count > p_data->history_limit_count)
        return false;

    if (!Buy(p_user, p_data, count, path))
        return false;

    // 添加购买记录
    AddBuyCount(p_user, p_data, count);
    return true;
}
예제 #6
0
//	反手
TradeRecordCollection TradeFacility::Reverse()
{
	int nSlot = m_nPosition.nSlot;
	TradeRecordCollection trs;

	if(nSlot == 0) return trs;

	trs.push_back(Close());

	if(nSlot > 0)
	{
		trs.push_back(Sell(abs(nSlot)));
	}
	else
	{
		trs.push_back(Buy(abs(nSlot)));
	}

	return trs;
}
예제 #7
0
HRESULT __stdcall Trader::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
	HRESULT hr = S_OK;
	
	switch(dispidMember)
	{
		case 0:
			pVarResult->vt = VT_I4;
			pVarResult->intVal = m_stock;
			break;

		case 1:
			VariantChangeType(&pDispParams->rgvarg[1], &pDispParams->rgvarg[1], 0, VT_I4);
			VariantChangeType(&pDispParams->rgvarg[0], &pDispParams->rgvarg[0], 0, VT_R4);
			hr = Buy(pDispParams->rgvarg[1].intVal, pDispParams->rgvarg[0].fltVal);
			break;

		case 2:
			VariantChangeType(&pDispParams->rgvarg[1], &pDispParams->rgvarg[1], 0, VT_I4);
			VariantChangeType(&pDispParams->rgvarg[0], &pDispParams->rgvarg[0], 0, VT_R4);
			hr = Sell(pDispParams->rgvarg[1].intVal, pDispParams->rgvarg[0].fltVal);
			break;

		case 3:
			pVarResult->vt = VT_I4;
			pVarResult->intVal = m_count;
			break;

		case 4:
			pVarResult->vt = VT_R8;
			pVarResult->dblVal = m_stock * m_rate + m_balance;
			break;

		default:
			hr = DISP_E_MEMBERNOTFOUND;
	}
	
	return hr;
}
예제 #8
0
파일: main.cpp 프로젝트: ashkan2200/FDM
void MMS(vector<myData> & F_out, vector<myData> & Ftt_out, FDM::baseSolver& sol, const vector<myData>& u,int step,double t, void * args){
    double x = 0;
    double y = 0;
    double z = 0;
    
    int LN_X = sol.X_LayerNumber();
    int LN_Y = sol.Y_LayerNumber();
    int LN_Z = sol.Z_LayerNumber();
    
    int Nx,Ny,Nz;
    int index = 0;
    for (int lz = 0; lz < LN_Z; lz++) {
        for (int ly = 0; ly < LN_Y; ly++) {
            for (int lx = 0; lx < LN_X; lx++) {
                
                index = idx(lx, ly, lz);
                Nx = u[index].Nx();
                Ny = u[index].Ny();
                Nz = u[index].Nz();
                
                myData ux(Nx,Ny,Nz);
                myData uy(Nx,Ny,Nz);
                myData uz(Nx,Ny,Nz);
                
                myData Bux(Nx,Ny,Nz);
                myData Buy(Nx,Ny,Nz);
                myData Buz(Nx,Ny,Nz);
                
                for (int k = 0; k < Nz; k++) {
                    z = sol.Z(k,lz);
                    for (int j = 0; j < Ny; j++) {
                        y = sol.Y(j,ly);
                        for (int i = 0; i < Nx; i++) {
                            x = sol.X(i,lx);
                            
                            
                            F_out[index](i,j,k)     =  8*M_PI*M_PI*cos(2*M_PI*t)*cos(2*M_PI*x)*cos(2*M_PI*y)*cos(2*M_PI*z);
                            Ftt_out[index](i,j,k)   = -4*M_PI*M_PI*F_out[index](i,j,k);
                            
                            ux(i,j,k)               = -2*M_PI*cos(2*M_PI*t)*sin(2*M_PI*x)*cos(2*M_PI*y)*cos(2*M_PI*z);//ux boundary
                            uy(i,j,k)               = -2*M_PI*cos(2*M_PI*t)*cos(2*M_PI*x)*sin(2*M_PI*y)*cos(2*M_PI*z);//uy
                            uz(i,j,k)               = -2*M_PI*cos(2*M_PI*t)*cos(2*M_PI*x)*cos(2*M_PI*y)*sin(2*M_PI*z);//uz
                        }
                    }
                }
                
                //Bux setup
                if (lx == 0) {
                    for (int k = 0; k < Nz; k++) {
                        for (int j = 0; j < Ny; j++) {
                            Bux(0,j,k) = -1;
                        }
                    }
                }
                
                if (lx == LN_X - 1) {
                    for (int k = 0; k < Nz; k++) {
                        for (int j = 0; j < Ny; j++) {
                            Bux(Nx - 1,j,k) = 1;
                        }
                    }
                }
                //
                
                ///Buy setup
                if (ly == 0) {
                    for (int k = 0; k < Nz; k++) {
                        for (int i = 0; i < Nx; i++) {
                            Buy(i,0,k) = -1;
                        }
                    }
                }
                
                if (ly == LN_Y - 1) {
                    for (int k = 0; k < Nz; k++) {
                        for (int i = 0; i < Nx; i++) {
                            Buy(i,Ny - 1,k) = 1;
                        }
                    }
                }
                //
                
                //Buz setup
                if (lz == 0) {
                    for (int j = 0; j < Ny; j++) {
                        for (int i = 0; i < Nx; i++) {
                            Buz(i,j,0) = -1;
                        }
                    }
                }
                
                if (lz == LN_Z - 1) {
                    for (int j = 0; j < Ny; j++) {
                        for (int i = 0; i < Nx; i++) {
                            Buz(i,j,Nz - 1) = 1;
                        }
                    }
                }
                //
                
                F_out[index] += sol.H_INV()*(Bux*ux + Buy*uy + Buz*uz);
            }
        }
    }
}