Ejemplo n.º 1
0
Archivo: rate.c Proyecto: yulcat/shogi
int getScore(Board board){ // Sum of pieces on the board, with danger and profit
	int maxDanger=0, profits=0, x, y, score=0;
	for(x=0; x<3; x++){
		for(y=0; y<4; y++){
			Tile tile = board.tile[x][y];
			char target = tile.occupied;
			int targetScore = typeToScore(target);
			int danger = getDanger(tile);
			score += targetScore;
			// Score from number of pieces
			if(danger > maxDanger)
				maxDanger = danger;
			int profit = getProfit(tile);
			if(profit>0)
				profits += getProfit(tile);
			// Get dangers and profits
		}
	}
	score -= maxDanger;
	if(maxDanger == 0){
		// Add profits only when there is no danger.
		score += profits/2;
		// expected profit is evaluated half of the real one.
	}
	return score;
}
Ejemplo n.º 2
0
void PurchaseEditor::addItemToList()
{
  ProductInfo pInfo;
  Azahar *myDb = new Azahar;
  myDb->setDatabase(db);
  bool ok=false;

  if (ui->editCode->text().isEmpty()) ui->editCode->setFocus();
  else if (ui->editDesc->text().isEmpty()) ui->editDesc->setFocus();
  else if (ui->editPoints->text().isEmpty()) ui->editPoints->setFocus();
  else if (ui->editCost->text().isEmpty()) ui->editCost->setFocus();
  else if (ui->editTax->text().isEmpty()) ui->editTax->setFocus();
  else if (ui->editFinalPrice->text().isEmpty()) ui->editFinalPrice->setFocus();
  else if (ui->editQty->text().isEmpty() || ui->editQty->text()=="0") ui->editQty->setFocus();
  else if ((ui->editUtility->text().isEmpty() && ui->editFinalPrice->text().isEmpty()) || ui->editFinalPrice->text().toDouble()<=ui->editCost->text().toDouble() ) ui->editFinalPrice->setFocus();
  else if (ui->groupBoxedItem->isChecked() && (ui->editItemsPerBox->text().isEmpty() || ui->editItemsPerBox->text()=="0"))  ui->editItemsPerBox->setFocus();
  else if (ui->groupBoxedItem->isChecked() && (ui->editPricePerBox->text().isEmpty() || ui->editPricePerBox->text()=="0")) ui->editPricePerBox->setFocus();
  else ok = true;

  if (ok) {
    ProductInfo info = myDb->getProductInfo( QString::number( getCode() ) );
    //FIX BUG: dont allow enter new products.. dont know why? new code on 'continue' statement.
    if (info.code == 0) { //new product
      info.code = getCode();
      info.stockqty = 0; //new product
      info.lastProviderId=1; //for now.. fixme in the future
    }
    //update p.info from the dialog
    info.desc    = getDescription();
    info.price   = getPrice();
    info.cost    = getCost();
    info.tax     = getTax1();
    info.extratax= getTax2();
    info.photo   = getPhotoBA();
    info.units   = getMeasureId();
    info.category= getCategoryId();
    info.utility = getProfit();
    info.points  = getPoints();
    info.purchaseQty = getPurchaseQty();
    info.validDiscount = productExists; //used to check if product is already on db.

    if (info.isAGroup) {
      // get each product fo the group/pack
      QStringList list = gelem.split(",");
      for (int i=0; i<list.count(); ++i) {
        QStringList tmp = list.at(i).split("/");
        if (tmp.count() == 2) { //ok 2 fields
          qulonglong  code  = tmp.at(0).toULongLong();
          pInfo = myDb->getProductInfo(QString::number(code));
          pInfo.purchaseQty = getPurchaseQty();
          pInfo.validDiscount = true; // all grouped products exists
          insertProduct(pInfo); ///inserting each product of the group
        } // correct fields
      }//for each element
    } else insertProduct(info);

    resetEdits();
    ui->editCode->setFocus();
  }
}
Ejemplo n.º 3
0
void CompanionWindow::exit()
{
    if (mModel && mModel->hasProfit(mPtr) && getProfit(mPtr) < 0)
    {
        std::vector<std::string> buttons;
        buttons.push_back("#{sCompanionWarningButtonOne}");
        buttons.push_back("#{sCompanionWarningButtonTwo}");
        mMessageBoxManager->createInteractiveMessageBox("#{sCompanionWarningMessage}", buttons);
        mMessageBoxManager->eventButtonPressed += MyGUI::newDelegate(this, &CompanionWindow::onMessageBoxButtonClicked);
    }
    else
        MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Companion);
}
Ejemplo n.º 4
0
void CraftingTreeRoot::printTree() {
	CraftingTreeVertex::print();
	QString text;
	if(!overflow.isEmpty())
		text += "Overflow:\n";
	for(auto i : overflow)
		text += Gw2ItemDB::getItemName(i.first) + " Count = " + QString::number(i.second) + "\n";
	text += "Shopping List: \n";
	auto shoppingList = getShoppingList();
	qint32 total = 0;
	for(auto iter = shoppingList.begin(); iter != shoppingList.end(); ++iter) {
		total += iter.value().second;
		text += QString::number(iter.value().first) + " " + Gw2ItemDB::getItemName(iter.key()) + " " + Gw2Currency::string(iter.value().second) + "\n";
	}
	text += "\nMarket Value: " + Gw2Currency::string(totalMarketValue) + "\n";
	text += "Listing and Transaction Fee: " + Gw2Currency::string(Listings::getTotalFees(totalMarketValue)) + "\n";
	text += "Crafting Cost Total: " + Gw2Currency::string(total) + "\n";
	text += "Profit: " + Gw2Currency::string(getProfit());
    qDebug().noquote() << text;
}
Ejemplo n.º 5
0
int main(int argc,char *argv[])
{
	int flag=0;
	char *cvalue1=NULL;
	int c;
	int Profit[2]={0,0};
	
	while((c=getopt(argc,argv,"f:"))!=-1)
	switch(c)
	{
		case 'f': 
	  			cvalue1=optarg;
				break;
	
		default:    
	  			printf("Please enter as -f <input_file> \n");
	        	return 1;
	}
	if(cvalue1==NULL)
	{
		printf("\nParameters required ");
		return 0;
	}
	getProfit(cvalue1,Profit);
	if(Profit[0]>0)
		printf("\nNet Profit(Used items)=Rs %d",Profit[0]);
	else if(Profit[0]<0)
		printf("\nNet Loss(Used items)=Rs %d",(-1*Profit[0]));
	else
		printf("\nNeither loss nor Profit(Used items)");	
	if(Profit[1]>0)
		printf("\nNet Profit(Unused items)=Rs %d",Profit[1]);
	else if(Profit[1]<0)
		printf("\nNet Loss(Unused items)=Rs %d",(-1*Profit[1]));
	else
		printf("\nNeither loss nor Profit(Unused items)");	

return 0;

}
Ejemplo n.º 6
0
void CompanionWindow::updateEncumbranceBar()
{
    if (mPtr.isEmpty())
        return;
    float capacity = mPtr.getClass().getCapacity(mPtr);
    float encumbrance = mPtr.getClass().getEncumbrance(mPtr);
    mEncumbranceBar->setValue(static_cast<int>(encumbrance), static_cast<int>(capacity));

    if (mModel && mModel->hasProfit(mPtr))
    {
        mProfitLabel->setCaptionWithReplacing("#{sProfitValue} " + MyGUI::utility::toString(getProfit(mPtr)));
    }
    else
        mProfitLabel->setCaption("");
}
Ejemplo n.º 7
0
void PurchaseEditor::addItemToList()
{
  ProductInfo pInfo;
  Azahar *myDb = new Azahar;
  myDb->setDatabase(db);
  bool ok=false;

  if (ui->editCode->text().isEmpty()) ui->editCode->setFocus();
  else if (ui->editDesc->text().isEmpty()) ui->editDesc->setFocus();
  else if (ui->editPoints->text().isEmpty()) ui->editPoints->setFocus();
  else if (ui->editCost->text().isEmpty()) ui->editCost->setFocus();
  else if (ui->editTax->text().isEmpty()) ui->editTax->setFocus();
  else if (ui->editFinalPrice->text().isEmpty()) ui->editFinalPrice->setFocus();
  else if (ui->editQty->text().isEmpty() || ui->editQty->text()=="0") ui->editQty->setFocus();
  else if ((ui->editUtility->text().isEmpty() && ui->editFinalPrice->text().isEmpty()) || ui->editFinalPrice->text().toDouble()<=ui->editCost->text().toDouble() ) ui->editFinalPrice->setFocus();
  else if (ui->groupBoxedItem->isChecked() && (ui->editItemsPerBox->text().isEmpty() || ui->editItemsPerBox->text()=="0"))  ui->editItemsPerBox->setFocus();
  else if (ui->groupBoxedItem->isChecked() && (ui->editPricePerBox->text().isEmpty() || ui->editPricePerBox->text()=="0")) ui->editPricePerBox->setFocus();
  else ok = true;

  if (ok) {
    ProductInfo info = myDb->getProductInfo(QString::number(getCode()));
    if (info.code == 0) {
      info.code = getCode();
      info.lastProviderId=1; //for now.. fixme in the future
    }
    //update p.info from the dialog
    info.desc    = getDescription();
    info.price   = getPrice();
    info.cost    = getCost();
    info.tax     = getTax1();
    //FIXME: add tax models
    //info.extratax= getTax2();
    info.photo   = getPhotoBA();
    info.units   = getMeasureId();
    info.category= getCategoryId();
    info.profit  = getProfit();
    info.points  = getPoints();
    info.stockqty= getQtyOnDb();
    info.purchaseQty = getPurchaseQty();
    double finalCount = info.purchaseQty + info.stockqty; // WHAT FOR??
    info.validDiscount = productExists; //used to check if product is already on db.
    //FIXME: NEXT 2 lines are temporal remove on 0.8 version
    //info.alphaCode = "-NA-";
    //FIXME: last providerId for an existent must be gotten from db since we dont have that field here. Provide a combobox to select one and a button to add a new one.
    //info.lastProviderId = 1;

    if (info.isAGroup) {
      // get each product fo the group/pack
      QStringList list = gelem.split(",");
      for (int i=0; i<list.count(); ++i) {
        QStringList tmp = list.at(i).split("/");
        if (tmp.count() == 2) { //ok 2 fields
          qulonglong  code  = tmp.at(0).toULongLong();
          pInfo = myDb->getProductInfo(QString::number(code));
          pInfo.purchaseQty = getPurchaseQty();
          pInfo.validDiscount = true; // all grouped products exists
          insertProduct(pInfo); ///inserting each product of the group
        } // correct fields
      }//for each element
    } else insertProduct(info);

    resetEdits();
    ui->editCode->setFocus();
  }
}