/* this will be replaced with something more sophisticated later */ void ActionSelector::preflopSelector(int potSize, bool myButton, const std::vector<std::string> &boardCards, const std::vector<std::string> &holeCards, const std::string &myDiscard, const ActionSelector::LegalAction &legalAction, ActionSelector::ActionInfo &actionInfo, float equity) { // open with the top 75% of hands on the button, and with top 50% otherwise int raise=0, adjustRaise, noise, toCall; toCall = legalAction.callMin; float discount = myButton ? 0.09 : 0; float potOdds = (float)toCall/(toCall+potSize); // generate betting noise noise = (rand() % 3 - 1); bool canRaise=legalAction.raiseMax>0, isAllin=legalAction.raiseMax==0, mustCall=legalAction.callMin>0;; if (canRaise > 0 && equity-discount > 0.5){ int bucket = (int)(20*equity)-9; raise = std::max(7, 7 + (bucket + noise)*8); adjustRaise = std::max(std::min(raise,legalAction.raiseMax), legalAction.raiseMin); std::cout << "ActionSelector:L108 (equity, bucket, noise, raise, adjRaise): " << equity << " " <<bucket << " " << noise << " " << raise << " " << adjustRaise << std::endl; } // for now no re-raising pre-flop more than our normal raise if (raise && (raise == adjustRaise)){ //can raise/bet without any problem if (legalAction.actionType == CHECK_BET) Bet(actionInfo,raise); else Raise(actionInfo,raise); } else { if (isAllin) { if (equity > 0.59) Call(actionInfo); //only call all-in if have top hands else Fold(actionInfo); } else if (mustCall){ if (equity > potOdds+0.05) Call(actionInfo); // call if cheap enough to call else Fold(actionInfo); } else { Check(actionInfo); } } }
bool Value::DoFold() { bool bAnyFold = false; // // Fold all of the children first // int count = m_pchildren.GetCount(); for (int index = 0; index < count; index++) { if (m_pchildren[index]->DoFold()) { bAnyFold = true; } } // // Now fold this node // TRef<Value> pvalueFold = Fold(); if (pvalueFold) { if (pvalueFold != this) { ChangeTo(pvalueFold); } return true; } return bAnyFold; }
GroupCell *GroupCell::FoldAll(bool all) { GroupCell *result = this; if (IsFoldable() && !m_hiddenTree) { Fold(); if (m_hiddenTree) m_hiddenTree->FoldAll(true); } else result = NULL; if (all && m_next) return dynamic_cast<GroupCell*>(m_next)->FoldAll(true); else return result; }
double measure_l_nocomm() { int oversample= measure_sync_oversample(); for (int i=0; i<10;i++) Sync(); /* Warm things up ;-) */ double time_clockA = bsp_dtime(); for (int i=0; i < oversample; i++) Sync(); time_clockA = bsp_dtime(); double time_clockB; Fold( &time_clockA,&time_clockB,sizeof(double), BSP_OPFUN dbl_min); return (time_clockB / oversample); }
bool GetFingerprint(OBBase* pOb, vector<unsigned int>&fp, int nbits) { OBMol* pmol = dynamic_cast<OBMol*>(pOb); unsigned int o=0; unsigned int m=0; unsigned int i=0; unsigned int n=0; if(!pmol) return false; //Read patterns file if it has not been done already if(smartsStrings.empty()) ReadPatternFile(_patternsfile, smartsStrings); //Make fp size the smallest power of two to contain the patterns //unsigned int n=Getbitsperint(); //while(n<smartsStrings.size())n*=2; //fp.resize(n/Getbitsperint()); fp.resize(16); for(n=0;n<smartsStrings.size();++n) { OBSmartsPattern sp; sp.Init(smartsStrings[n]); if(sp.Match(*pmol)) { m=sp.GetUMapList().size(); //m=sp.NumMatches(); o=n*8; for(i=0;i<8;++i) { if(i<m) {SetBit(fp, o+i); //cout << "1"; } //cout << endl; } } } if(nbits) Fold(fp, nbits); return true; };
// Compute the features of specified charsamp and feedforward the // specified nets bool ConvNetCharClassifier::RunNets(CharSamp *char_samp) { if (char_net_ == NULL) { fprintf(stderr, "Cube ERROR (ConvNetCharClassifier::RunNets): " "NeuralNet is NULL\n"); return false; } int feat_cnt = char_net_->in_cnt(); int class_cnt = char_set_->ClassCount(); // allocate i/p and o/p buffers if needed if (net_input_ == NULL) { net_input_ = new float[feat_cnt]; if (net_input_ == NULL) { fprintf(stderr, "Cube ERROR (ConvNetCharClassifier::RunNets): " "unable to allocate memory for input nodes\n"); return false; } net_output_ = new float[class_cnt]; if (net_output_ == NULL) { fprintf(stderr, "Cube ERROR (ConvNetCharClassifier::RunNets): " "unable to allocate memory for output nodes\n"); return false; } } // compute input features if (feat_extract_->ComputeFeatures(char_samp, net_input_) == false) { fprintf(stderr, "Cube ERROR (ConvNetCharClassifier::RunNets): " "unable to compute features\n"); return false; } if (char_net_ != NULL) { if (char_net_->FeedForward(net_input_, net_output_) == false) { fprintf(stderr, "Cube ERROR (ConvNetCharClassifier::RunNets): " "unable to run feed-forward\n"); return false; } } else { return false; } Fold(); return true; }
void GamePlay::CpuFold(int CpuHandValue) { Poker a; if (cpucash > 0) { if (CpuHandValue < 5) { cpubet = 0; cpucash = cpucash - cpubet; pot = pot + cpubet; a.tablecards(deck, 10); //thirdhand(); Fold(); } } }
// compute the features of specified charsamp and // feedforward the specified nets bool HybridNeuralNetCharClassifier::RunNets(CharSamp *char_samp) { int feat_cnt = feat_extract_->FeatureCnt(); int class_cnt = char_set_->ClassCount(); // allocate i/p and o/p buffers if needed if (net_input_ == NULL) { net_input_ = new float[feat_cnt]; if (net_input_ == NULL) { return false; } net_output_ = new float[class_cnt]; if (net_output_ == NULL) { return false; } } // compute input features if (feat_extract_->ComputeFeatures(char_samp, net_input_) == false) { return false; } // go thru all the nets memset(net_output_, 0, class_cnt * sizeof(*net_output_)); float *inputs = net_input_; for (int net_idx = 0; net_idx < nets_.size(); net_idx++) { // run each net vector<float> net_out(class_cnt, 0.0); if (!nets_[net_idx]->FeedForward(inputs, &net_out[0])) { return false; } // add the output values for (int class_idx = 0; class_idx < class_cnt; class_idx++) { net_output_[class_idx] += (net_out[class_idx] * net_wgts_[net_idx]); } // increment inputs pointer inputs += nets_[net_idx]->in_cnt(); } Fold(); return true; }
int measure_sync_oversample() { int oversample; static double oversample_scale; double tA, tB; if(oversample_scale < 0) { bsp_dtime(); for(int i=0;i<500;i++) ; tA = bsp_dtime(); Fold(&tA,&tB,sizeof(double), BSP_OPFUN dbl_max); oversample_scale = (1.0/tB)/(L_OVERSAMPLE/500.0); } oversample= max((int)(L_OVERSAMPLE*oversample_scale), MIN_SAMPLE); return oversample; }
bool fingerprint2::GetFingerprint(OBBase* pOb, vector<unsigned int>&fp, int nbits) { OBMol* pmol = dynamic_cast<OBMol*>(pOb); if(!pmol) return false; fp.resize(1024/Getbitsperint()); fragset.clear();//needed because now only one instance of fp class ringset.clear(); //identify fragments starting at every atom OBAtom *patom; vector<OBNodeBase*>::iterator i; for (patom = pmol->BeginAtom(i);patom;patom = pmol->NextAtom(i)) { if(patom->GetAtomicNum() == OBElements::Hydrogen) continue; vector<int> curfrag; vector<int> levels(pmol->NumAtoms()); getFragments(levels, curfrag, 1, patom, NULL); } // TRACE("%s %d frags before; ",pmol->GetTitle(),fragset.size()); //Ensure that each chemically identical fragment is present only in a single DoRings(); DoReverses(); SetItr itr; _ss.str(""); for(itr=fragset.begin();itr!=fragset.end();++itr) { //Use hash of fragment to set a bit in the fingerprint int hash = CalcHash(*itr); SetBit(fp,hash); if(!(Flags() & FPT_NOINFO)) PrintFpt(*itr,hash); } if(nbits) Fold(fp, nbits); // TRACE("%d after\n",fragset.size()); return true; }
double measure_l_alltoall() { int oversample= measure_sync_oversample(); int junk[P]; PushReg(junk,sizeof(int)*P); Sync(); for (int i=0; i<10;i++) Sync(); /* Warm things up ;-) */ double time_clockA = bsp_dtime(), time_clockB; for (int i=0; i < oversample; i++) { for(int j= 0; j < P; ++j) HpPut(j,&junk[j],&junk, j*sizeof(int), sizeof(int)); Sync(); } time_clockA = bsp_dtime(); Fold( &time_clockA,&time_clockB,sizeof(double), BSP_OPFUN dbl_min); PopReg(junk); return (time_clockB / oversample); }
double measure_l_localshift() { int right, oversample= measure_sync_oversample(); int junk; PushReg(&junk,sizeof(int)); Sync(); for (int i=0; i<10;i++) Sync(); /* Warm things up ;-) */ right = (Pid+1)%(P); double time_clockA = bsp_dtime(), time_clockB; for (int i=0; i < oversample; i++) { HpPut(right,&junk,&junk,0,sizeof(int)); Sync(); } time_clockA = bsp_dtime(); Fold( &time_clockA,&time_clockB,sizeof(double), BSP_OPFUN dbl_min); PopReg(&junk); return (time_clockB / oversample); }
void LamentStress<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { Teuchos::RCP<lament::matParams<ScalarT>> matp = Teuchos::rcp(new lament::matParams<ScalarT>()); // Get the old state data Albany::MDArray oldDefGrad = (*workset.stateArrayPtr)[defGradName]; Albany::MDArray oldStress = (*workset.stateArrayPtr)[stressName]; int numStateVariables = (int)(this->lamentMaterialModelStateVariableNames.size()); // \todo Get actual time step for calls to LAMENT materials. double deltaT = 1.0; vector<ScalarT> strainRate(6); // symmetric tensor vector<ScalarT> spin(3); // skew-symmetric tensor vector<ScalarT> defGrad(9); // symmetric tensor vector<ScalarT> leftStretch(6); // symmetric tensor vector<ScalarT> rotation(9); // full tensor vector<double> stressOld(6); // symmetric tensor vector<ScalarT> stressNew(6); // symmetric tensor vector<double> stateOld(numStateVariables); // a single scalar for each state variable vector<double> stateNew(numStateVariables); // a single scalar for each state variable // \todo Set up scratch space for material models using getNumScratchVars() and setScratchPtr(). // Create the matParams structure, which is passed to Lament matp->nelements = 1; matp->dt = deltaT; matp->time = 0.0; matp->strain_rate = &strainRate[0]; matp->spin = &spin[0]; matp->deformation_gradient = &defGrad[0]; matp->left_stretch = &leftStretch[0]; matp->rotation = &rotation[0]; matp->state_old = &stateOld[0]; matp->state_new = &stateNew[0]; matp->stress_old = &stressOld[0]; matp->stress_new = &stressNew[0]; // matp->dt_mat = std::numeric_limits<double>::max(); // matParams that still need to be added: // matp->temp_old (temperature) // matp->temp_new // matp->sound_speed_old // matp->sound_speed_new // matp->volume // scratch pointer // function pointers (lots to be done here) for (int cell=0; cell < (int)workset.numCells; ++cell) { for (int qp=0; qp < (int)numQPs; ++qp) { // std::cout << "QP: " << qp << std::endl; // Fill the following entries in matParams for call to LAMENT // // nelements - number of elements // dt - time step, this one is tough because Albany does not currently have a concept of time step for implicit integration // time - current time, again Albany does not currently have a concept of time for implicit integration // strain_rate - what Sierra calls the rate of deformation, it is the symmetric part of the velocity gradient // spin - anti-symmetric part of the velocity gradient // left_stretch - found as V in the polar decomposition of the deformation gradient F = VR // rotation - found as R in the polar decomposition of the deformation gradient F = VR // state_old - material state data for previous time step (material dependent, none for lament::Elastic) // state_new - material state data for current time step (material dependent, none for lament::Elastic) // stress_old - stress at previous time step // stress_new - stress at current time step, filled by material model // // The total deformation gradient is available as field data // // The velocity gradient is not available but can be computed at the logarithm of the incremental deformation gradient divided by deltaT // The incremental deformation gradient is computed as F_new F_old^-1 // JTO: here is how I think this will go (of course the first two lines won't work as is...) // Intrepid2::Tensor<RealType> F = newDefGrad; // Intrepid2::Tensor<RealType> Fn = oldDefGrad; // Intrepid2::Tensor<RealType> f = F*Intrepid2::inverse(Fn); // Intrepid2::Tensor<RealType> V; // Intrepid2::Tensor<RealType> R; // boost::tie(V,R) = Intrepid2::polar_left(F); // Intrepid2::Tensor<RealType> Vinc; // Intrepid2::Tensor<RealType> Rinc; // Intrepid2::Tensor<RealType> logVinc; // boost::tie(Vinc,Rinc,logVinc) = Intrepid2::polar_left_logV(f) // Intrepid2::Tensor<RealType> logRinc = Intrepid2::log_rotation(Rinc); // Intrepid2::Tensor<RealType> logf = Intrepid2::bch(logVinc,logRinc); // Intrepid2::Tensor<RealType> L = (1.0/deltaT)*logf; // Intrepid2::Tensor<RealType> D = Intrepid2::sym(L); // Intrepid2::Tensor<RealType> W = Intrepid2::skew(L); // and then fill data into the vectors below // new deformation gradient (the current deformation gradient as computed in the current configuration) Intrepid2::Tensor<ScalarT> Fnew( 3, defGradField,cell,qp,0,0); // old deformation gradient (deformation gradient at previous load step) Intrepid2::Tensor<ScalarT> Fold( oldDefGrad(cell,qp,0,0), oldDefGrad(cell,qp,0,1), oldDefGrad(cell,qp,0,2), oldDefGrad(cell,qp,1,0), oldDefGrad(cell,qp,1,1), oldDefGrad(cell,qp,1,2), oldDefGrad(cell,qp,2,0), oldDefGrad(cell,qp,2,1), oldDefGrad(cell,qp,2,2) ); // incremental deformation gradient Intrepid2::Tensor<ScalarT> Finc = Fnew * Intrepid2::inverse(Fold); // DEBUGGING // //if(cell==0 && qp==0){ // std::cout << "Fnew(0,0) " << Fnew(0,0) << endl; // std::cout << "Fnew(1,0) " << Fnew(1,0) << endl; // std::cout << "Fnew(2,0) " << Fnew(2,0) << endl; // std::cout << "Fnew(0,1) " << Fnew(0,1) << endl; // std::cout << "Fnew(1,1) " << Fnew(1,1) << endl; // std::cout << "Fnew(2,1) " << Fnew(2,1) << endl; // std::cout << "Fnew(0,2) " << Fnew(0,2) << endl; // std::cout << "Fnew(1,2) " << Fnew(1,2) << endl; // std::cout << "Fnew(2,2) " << Fnew(2,2) << endl; //} // END DEBUGGING // // left stretch V, and rotation R, from left polar decomposition of new deformation gradient Intrepid2::Tensor<ScalarT> V(3), R(3), U(3); boost::tie(V,R) = Intrepid2::polar_left(Fnew); //V = R * U * transpose(R); // DEBUGGING // //if(cell==0 && qp==0){ // std::cout << "U(0,0) " << U(0,0) << endl; // std::cout << "U(1,0) " << U(1,0) << endl; // std::cout << "U(2,0) " << U(2,0) << endl; // std::cout << "U(0,1) " << U(0,1) << endl; // std::cout << "U(1,1) " << U(1,1) << endl; // std::cout << "U(2,1) " << U(2,1) << endl; // std::cout << "U(0,2) " << U(0,2) << endl; // std::cout << "U(1,2) " << U(1,2) << endl; // std::cout << "U(2,2) " << U(2,2) << endl; // std::cout << "========\n"; // std::cout << "V(0,0) " << V(0,0) << endl; // std::cout << "V(1,0) " << V(1,0) << endl; // std::cout << "V(2,0) " << V(2,0) << endl; // std::cout << "V(0,1) " << V(0,1) << endl; // std::cout << "V(1,1) " << V(1,1) << endl; // std::cout << "V(2,1) " << V(2,1) << endl; // std::cout << "V(0,2) " << V(0,2) << endl; // std::cout << "V(1,2) " << V(1,2) << endl; // std::cout << "V(2,2) " << V(2,2) << endl; // std::cout << "========\n"; // std::cout << "R(0,0) " << R(0,0) << endl; // std::cout << "R(1,0) " << R(1,0) << endl; // std::cout << "R(2,0) " << R(2,0) << endl; // std::cout << "R(0,1) " << R(0,1) << endl; // std::cout << "R(1,1) " << R(1,1) << endl; // std::cout << "R(2,1) " << R(2,1) << endl; // std::cout << "R(0,2) " << R(0,2) << endl; // std::cout << "R(1,2) " << R(1,2) << endl; // std::cout << "R(2,2) " << R(2,2) << endl; //} // END DEBUGGING // // incremental left stretch Vinc, incremental rotation Rinc, and log of incremental left stretch, logVinc Intrepid2::Tensor<ScalarT> Uinc(3), Vinc(3), Rinc(3), logVinc(3); //boost::tie(Vinc,Rinc,logVinc) = Intrepid2::polar_left_logV(Finc); boost::tie(Vinc,Rinc) = Intrepid2::polar_left(Finc); //Vinc = Rinc * Uinc * transpose(Rinc); logVinc = Intrepid2::log(Vinc); // log of incremental rotation Intrepid2::Tensor<ScalarT> logRinc = Intrepid2::log_rotation(Rinc); // log of incremental deformation gradient Intrepid2::Tensor<ScalarT> logFinc = Intrepid2::bch(logVinc, logRinc); // velocity gradient Intrepid2::Tensor<ScalarT> L = (1.0/deltaT)*logFinc; // strain rate (a.k.a rate of deformation) Intrepid2::Tensor<ScalarT> D = Intrepid2::sym(L); // spin Intrepid2::Tensor<ScalarT> W = Intrepid2::skew(L); // load everything into the Lament data structure strainRate[0] = ( D(0,0) ); strainRate[1] = ( D(1,1) ); strainRate[2] = ( D(2,2) ); strainRate[3] = ( D(0,1) ); strainRate[4] = ( D(1,2) ); strainRate[5] = ( D(2,0) ); spin[0] = ( W(0,1) ); spin[1] = ( W(1,2) ); spin[2] = ( W(2,0) ); leftStretch[0] = ( V(0,0) ); leftStretch[1] = ( V(1,1) ); leftStretch[2] = ( V(2,2) ); leftStretch[3] = ( V(0,1) ); leftStretch[4] = ( V(1,2) ); leftStretch[5] = ( V(2,0) ); rotation[0] = ( R(0,0) ); rotation[1] = ( R(1,1) ); rotation[2] = ( R(2,2) ); rotation[3] = ( R(0,1) ); rotation[4] = ( R(1,2) ); rotation[5] = ( R(2,0) ); rotation[6] = ( R(1,0) ); rotation[7] = ( R(2,1) ); rotation[8] = ( R(0,2) ); defGrad[0] = ( Fnew(0,0) ); defGrad[1] = ( Fnew(1,1) ); defGrad[2] = ( Fnew(2,2) ); defGrad[3] = ( Fnew(0,1) ); defGrad[4] = ( Fnew(1,2) ); defGrad[5] = ( Fnew(2,0) ); defGrad[6] = ( Fnew(1,0) ); defGrad[7] = ( Fnew(2,1) ); defGrad[8] = ( Fnew(0,2) ); stressOld[0] = oldStress(cell,qp,0,0); stressOld[1] = oldStress(cell,qp,1,1); stressOld[2] = oldStress(cell,qp,2,2); stressOld[3] = oldStress(cell,qp,0,1); stressOld[4] = oldStress(cell,qp,1,2); stressOld[5] = oldStress(cell,qp,2,0); // copy data from the state manager to the LAMENT data structure for(int iVar=0 ; iVar<numStateVariables ; iVar++){ const std::string& variableName = this->lamentMaterialModelStateVariableNames[iVar]+"_old"; Albany::MDArray stateVar = (*workset.stateArrayPtr)[variableName]; stateOld[iVar] = stateVar(cell,qp); } // Make a call to the LAMENT material model to initialize the load step this->lamentMaterialModel->loadStepInit(matp.get()); // Get the stress from the LAMENT material // std::cout << "about to call lament->getStress()" << std::endl; this->lamentMaterialModel->getStress(matp.get()); // std::cout << "after calling lament->getStress() 2" << std::endl; // rotate to get the Cauchy Stress Intrepid2::Tensor<ScalarT> lameStress( stressNew[0], stressNew[3], stressNew[5], stressNew[3], stressNew[1], stressNew[4], stressNew[5], stressNew[4], stressNew[2] ); Intrepid2::Tensor<ScalarT> cauchy = R * lameStress * transpose(R); // DEBUGGING // //if(cell==0 && qp==0){ // std::cout << "check strainRate[0] " << strainRate[0] << endl; // std::cout << "check strainRate[1] " << strainRate[1] << endl; // std::cout << "check strainRate[2] " << strainRate[2] << endl; // std::cout << "check strainRate[3] " << strainRate[3] << endl; // std::cout << "check strainRate[4] " << strainRate[4] << endl; // std::cout << "check strainRate[5] " << strainRate[5] << endl; //} // END DEBUGGING // // Copy the new stress into the stress field for (int i(0); i < 3; ++i) for (int j(0); j < 3; ++j) stressField(cell,qp,i,j) = cauchy(i,j); // stressField(cell,qp,0,0) = stressNew[0]; // stressField(cell,qp,1,1) = stressNew[1]; // stressField(cell,qp,2,2) = stressNew[2]; // stressField(cell,qp,0,1) = stressNew[3]; // stressField(cell,qp,1,2) = stressNew[4]; // stressField(cell,qp,2,0) = stressNew[5]; // stressField(cell,qp,1,0) = stressNew[3]; // stressField(cell,qp,2,1) = stressNew[4]; // stressField(cell,qp,0,2) = stressNew[5]; // copy state_new data from the LAMENT data structure to the corresponding state variable field for(int iVar=0 ; iVar<numStateVariables ; iVar++) this->lamentMaterialModelStateVariableFields[iVar](cell,qp) = stateNew[iVar]; // DEBUGGING // //if(cell==0 && qp==0){ // std::cout << "stress(0,0) " << this->stressField(cell,qp,0,0) << endl; // std::cout << "stress(1,1) " << this->stressField(cell,qp,1,1) << endl; // std::cout << "stress(2,2) " << this->stressField(cell,qp,2,2) << endl; // std::cout << "stress(0,1) " << this->stressField(cell,qp,0,1) << endl; // std::cout << "stress(1,2) " << this->stressField(cell,qp,1,2) << endl; // std::cout << "stress(0,2) " << this->stressField(cell,qp,0,2) << endl; // std::cout << "stress(1,0) " << this->stressField(cell,qp,1,0) << endl; // std::cout << "stress(2,1) " << this->stressField(cell,qp,2,1) << endl; // std::cout << "stress(2,0) " << this->stressField(cell,qp,2,0) << endl; // //} // // END DEBUGGING // } } }
/* this will be replaced with something more sophisticated later */ void ActionSelector::evalMagic(int potSize, bool myButton, const std::vector<std::string> &boardCards, const std::vector<std::string> &holeCards, const std::string &myDiscard, const ActionSelector::LegalAction &legalAction, ActionSelector::ActionInfo &actionInfo, float equity){ int coin = rand() % 3; //LOL int callMin = legalAction.callMin; if (coin == 1 && equity > 0.8){ if (legalAction.raiseMax > 0){ if (legalAction.actionType == CHECK_BET) Bet(actionInfo, legalAction.raiseMax); else Raise(actionInfo, legalAction.raiseMax); } else { std::cout << "ActionSelector.cpp:L78 Calling All-in" << std::endl; Call(actionInfo); } //std::cout << "raising to " << actionInfo.betAmount << std::endl; return; } // compute pot odds and either call or fold float potOdds = (float)callMin/(callMin+potSize); bool canRaise=legalAction.raiseMax>0, isAllin=legalAction.raiseMax==0, mustCall=legalAction.callMin>0; // raise with the worst and best cards in our range if (equity>0.62){ std::cout << "myPotOdds: " << callMin << "/" << (callMin+potSize) << ":" << potOdds << " vs. equity: " << equity << std::endl; if (legalAction.raiseMax > 0){ float oppEquity=1-equity; int newPotSize=callMin+potSize; int raise=(int)((newPotSize*equity/oppEquity)) + callMin; // int raise=(int)((newPotSize*equity/oppEquity)) + callMin; int numBoardCards = boardCards.size(); if (numBoardCards >= 3) raise = 7; //7std::max(raise, 100); // so we actually can make money if (numBoardCards >= 4 && equity > 0.7) raise = std::max(raise, 200); if (numBoardCards >= 5 && equity > 0.85) raise = std::max(raise, 300); int betAmt= std::max(std::min(raise,legalAction.raiseMax), legalAction.raiseMin); std::cout << "betAmt: " << betAmt << " vs. raise: " << raise << "(raiseMin, max) " << legalAction.raiseMin << ", " << legalAction.raiseMax << std::endl; if (betAmt){ actionInfo.action= (legalAction.actionType == CHECK_BET) ? BET : RAISE; actionInfo.betAmount=betAmt; } else { actionInfo.action = (legalAction.actionType == CHECK_BET) ? CHECK : FOLD; actionInfo.betAmount=0; }//end if(betAmt) } else { if ((legalAction.callMin > 100 && equity < 0.65)) Fold(actionInfo); else Call(actionInfo); } //end if(raisMax > 0) }else{ std::cout << "myPotOdds: " << callMin << "/" << (callMin+potSize) << ":" << potOdds << " vs. equity: " << equity << std::endl; float roundDiscount=0; int numBoardCards = boardCards.size(); // Discount our equity, so we are less willing to call with low equity on later streets (especially the river) if (numBoardCards == 5){ roundDiscount=0.2; } if (legalAction.callMin > 0){ if (numBoardCards>=3 && equity < 0.55){ // fold if our equity is bad by the turn Fold(actionInfo); }else if (equity-roundDiscount>(potOdds)+0.04){ //less likely to call if we are down Call(actionInfo); } else { Fold(actionInfo); } } else { Check(actionInfo); } } }
//game menu int GamePlay::menu()//side menu { char *menu_list[MaxNo_Menu] = { "Check", "Bet 10", "Bet 50", "All In", "Fold" }; int i, xpos[MaxNo_Menu] = { 15, 30, 45, 60, 75 }, ypos = 53; // list the menu for (i = 0; i< MaxNo_Menu; ++i) { Aesthetics a; a.gotoxy(xpos[i], ypos); a.textattr(3); printf("%s", menu_list[i]); } // make menu available to choose i = 0; // set i to 0 to start menu at the begining while (1) { Aesthetics a; a.gotoxy(xpos[i], ypos);// set cursor position a.textattr(11); // this sets menu item to green text printf("%s", menu_list[i]); // print out highlighted item in new color /* note : 72 -> UP button 75 -> RIGHT button 77 -> LEFT button 80 -> DOWN button */ //getting key information switch switch (_getch()) { //right case 75: if (i>0) { Aesthetics a; a.gotoxy(xpos[i], ypos);//set cursor position passing in i a.textattr(3); // set text color passing in color printf("%s", menu_list[i]); // print the menu item out in new color --i;//up key subtract from i } else { Aesthetics a; a.gotoxy(xpos[i], ypos);// set cursor position passing in i a.textattr(3); // reset text color printf("%s", menu_list[i]);//print the menu item out in new color i = 3;//set i to 2 to start menu from bottom } break; //left case 77: if (i< MaxNo_Menu - 1) { Aesthetics a; a.gotoxy(xpos[i], ypos);//set cursor position passing in i a.textattr(3);//set text color printf("%s", menu_list[i]);//print the menu item out in new color ++i;// down key add to i } else { Aesthetics a; a.gotoxy(xpos[i], ypos);// set cursor position passing in i a.textattr(3); // reset text color printf("%s", menu_list[i]);//print the menu item out in new color i = 0;//set i to 0 to restart menu } break; //enter case 13: if (i == 0) { return 0; } /*system("cls"); hand.push_back(deck[3]); choosecard(deck,hand);*/ if (i == 1) { return 10; } if (i == 2) { return 50; } if (i == 3) { //cd.tablecards(deck, 10); return 100; AltGame(); } if (i == 4) { Fold(); return 0; } break; } } }
void LameStressBase<EvalT, Traits>:: calcStressRealType(PHX::MDField<RealType,Cell,QuadPoint,Dim,Dim>& stressFieldRef, PHX::MDField<RealType,Cell,QuadPoint,Dim,Dim>& defGradFieldRef, typename Traits::EvalData workset, Teuchos::RCP<LameMatParams>& matp) { // Get the old state data Albany::MDArray oldDefGrad = (*workset.stateArrayPtr)[defGradName]; Albany::MDArray oldStress = (*workset.stateArrayPtr)[stressName]; int numStateVariables = (int)(this->lameMaterialModelStateVariableNames.size()); // Pointers used for filling the matParams structure double* strainRatePtr = matp->strain_rate; double* spinPtr = matp->spin; double* leftStretchPtr = matp->left_stretch; double* rotationPtr = matp->rotation; double* stateOldPtr = matp->state_old; double* stressOldPtr = matp->stress_old; double deltaT = matp->dt; for (int cell=0; cell < (int)workset.numCells; ++cell) { for (int qp=0; qp < (int)numQPs; ++qp) { // Fill the following entries in matParams for call to LAME // // nelements - number of elements // dt - time step, this one is tough because Albany does not currently have a concept of time step for implicit integration // time - current time, again Albany does not currently have a concept of time for implicit integration // strain_rate - what Sierra calls the rate of deformation, it is the symmetric part of the velocity gradient // spin - anti-symmetric part of the velocity gradient // left_stretch - found as V in the polar decomposition of the deformation gradient F = VR // rotation - found as R in the polar decomposition of the deformation gradient F = VR // state_old - material state data for previous time step (material dependent, none for lame(nt)::Elastic) // state_new - material state data for current time step (material dependent, none for lame(nt)::Elastic) // stress_old - stress at previous time step // stress_new - stress at current time step, filled by material model // // The total deformation gradient is available as field data // // The velocity gradient is not available but can be computed at the logarithm of the incremental deformation gradient divided by deltaT // The incremental deformation gradient is computed as F_new F_old^-1 // JTO: here is how I think this will go (of course the first two lines won't work as is...) // Intrepid::Tensor<RealType> F = newDefGrad; // Intrepid::Tensor<RealType> Fn = oldDefGrad; // Intrepid::Tensor<RealType> f = F*Intrepid::inverse(Fn); // Intrepid::Tensor<RealType> V; // Intrepid::Tensor<RealType> R; // boost::tie(V,R) = Intrepid::polar_left(F); // Intrepid::Tensor<RealType> Vinc; // Intrepid::Tensor<RealType> Rinc; // Intrepid::Tensor<RealType> logVinc; // boost::tie(Vinc,Rinc,logVinc) = Intrepid::polar_left_logV(f) // Intrepid::Tensor<RealType> logRinc = Intrepid::log_rotation(Rinc); // Intrepid::Tensor<RealType> logf = Intrepid::bch(logVinc,logRinc); // Intrepid::Tensor<RealType> L = (1.0/deltaT)*logf; // Intrepid::Tensor<RealType> D = Intrepid::sym(L); // Intrepid::Tensor<RealType> W = Intrepid::skew(L); // and then fill data into the vectors below // new deformation gradient (the current deformation gradient as computed in the current configuration) Intrepid::Tensor<RealType> Fnew( defGradFieldRef(cell,qp,0,0), defGradFieldRef(cell,qp,0,1), defGradFieldRef(cell,qp,0,2), defGradFieldRef(cell,qp,1,0), defGradFieldRef(cell,qp,1,1), defGradFieldRef(cell,qp,1,2), defGradFieldRef(cell,qp,2,0), defGradFieldRef(cell,qp,2,1), defGradFieldRef(cell,qp,2,2) ); // old deformation gradient (deformation gradient at previous load step) Intrepid::Tensor<RealType> Fold( oldDefGrad(cell,qp,0,0), oldDefGrad(cell,qp,0,1), oldDefGrad(cell,qp,0,2), oldDefGrad(cell,qp,1,0), oldDefGrad(cell,qp,1,1), oldDefGrad(cell,qp,1,2), oldDefGrad(cell,qp,2,0), oldDefGrad(cell,qp,2,1), oldDefGrad(cell,qp,2,2) ); // incremental deformation gradient Intrepid::Tensor<RealType> Finc = Fnew * Intrepid::inverse(Fold); // left stretch V, and rotation R, from left polar decomposition of new deformation gradient Intrepid::Tensor<RealType> V(3), R(3); boost::tie(V,R) = Intrepid::polar_left_eig(Fnew); // incremental left stretch Vinc, incremental rotation Rinc, and log of incremental left stretch, logVinc Intrepid::Tensor<RealType> Vinc(3), Rinc(3), logVinc(3); boost::tie(Vinc,Rinc,logVinc) = Intrepid::polar_left_logV_lame(Finc); // log of incremental rotation Intrepid::Tensor<RealType> logRinc = Intrepid::log_rotation(Rinc); // log of incremental deformation gradient Intrepid::Tensor<RealType> logFinc = Intrepid::bch(logVinc, logRinc); // velocity gradient Intrepid::Tensor<RealType> L = RealType(1.0/deltaT)*logFinc; // strain rate (a.k.a rate of deformation) Intrepid::Tensor<RealType> D = Intrepid::sym(L); // spin Intrepid::Tensor<RealType> W = Intrepid::skew(L); // load everything into the Lame data structure strainRatePtr[0] = ( D(0,0) ); strainRatePtr[1] = ( D(1,1) ); strainRatePtr[2] = ( D(2,2) ); strainRatePtr[3] = ( D(0,1) ); strainRatePtr[4] = ( D(1,2) ); strainRatePtr[5] = ( D(0,2) ); spinPtr[0] = ( W(0,1) ); spinPtr[1] = ( W(1,2) ); spinPtr[2] = ( W(0,2) ); leftStretchPtr[0] = ( V(0,0) ); leftStretchPtr[1] = ( V(1,1) ); leftStretchPtr[2] = ( V(2,2) ); leftStretchPtr[3] = ( V(0,1) ); leftStretchPtr[4] = ( V(1,2) ); leftStretchPtr[5] = ( V(0,2) ); rotationPtr[0] = ( R(0,0) ); rotationPtr[1] = ( R(1,1) ); rotationPtr[2] = ( R(2,2) ); rotationPtr[3] = ( R(0,1) ); rotationPtr[4] = ( R(1,2) ); rotationPtr[5] = ( R(0,2) ); rotationPtr[6] = ( R(1,0) ); rotationPtr[7] = ( R(2,1) ); rotationPtr[8] = ( R(2,0) ); stressOldPtr[0] = oldStress(cell,qp,0,0); stressOldPtr[1] = oldStress(cell,qp,1,1); stressOldPtr[2] = oldStress(cell,qp,2,2); stressOldPtr[3] = oldStress(cell,qp,0,1); stressOldPtr[4] = oldStress(cell,qp,1,2); stressOldPtr[5] = oldStress(cell,qp,0,2); // increment the pointers strainRatePtr += 6; spinPtr += 3; leftStretchPtr += 6; rotationPtr += 9; stressOldPtr += 6; // copy data from the state manager to the LAME data structure for(int iVar=0 ; iVar<numStateVariables ; iVar++, stateOldPtr++){ //std::string& variableName = this->lameMaterialModelStateVariableNames[iVar]; //const Intrepid::FieldContainer<RealType>& stateVar = *oldState[variableName]; const std::string& variableName = this->lameMaterialModelStateVariableNames[iVar]+"_old"; Albany::MDArray stateVar = (*workset.stateArrayPtr)[variableName]; *stateOldPtr = stateVar(cell,qp); } } } // Make a call to the LAME material model to initialize the load step this->lameMaterialModel->loadStepInit(matp.get()); // Get the stress from the LAME material this->lameMaterialModel->getStress(matp.get()); double* stressNewPtr = matp->stress_new; // Post-process data from Lame call for (int cell=0; cell < workset.numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { // Copy the new stress into the stress field stressFieldRef(cell,qp,0,0) = stressNewPtr[0]; stressFieldRef(cell,qp,1,1) = stressNewPtr[1]; stressFieldRef(cell,qp,2,2) = stressNewPtr[2]; stressFieldRef(cell,qp,0,1) = stressNewPtr[3]; stressFieldRef(cell,qp,1,2) = stressNewPtr[4]; stressFieldRef(cell,qp,0,2) = stressNewPtr[5]; stressFieldRef(cell,qp,1,0) = stressNewPtr[3]; stressFieldRef(cell,qp,2,1) = stressNewPtr[4]; stressFieldRef(cell,qp,2,0) = stressNewPtr[5]; stressNewPtr += 6; } } // !!!!! When should this be done??? double* stateNewPtr = matp->state_new; for (int cell=0; cell < workset.numCells; ++cell) { for (int qp=0; qp < numQPs; ++qp) { // copy state_new data from the LAME data structure to the corresponding state variable field for(int iVar=0 ; iVar<numStateVariables ; iVar++, stateNewPtr++) this->lameMaterialModelStateVariableFields[iVar](cell,qp) = *stateNewPtr; } } }
void NewtonianFluidModel<EvalT, Traits>:: computeState(typename Traits::EvalData workset, std::map<std::string, Teuchos::RCP<PHX::MDField<ScalarT>>> dep_fields, std::map<std::string, Teuchos::RCP<PHX::MDField<ScalarT>>> eval_fields) { std::string F_string = (*field_name_map_)["F"]; std::string cauchy_string = (*field_name_map_)["Cauchy_Stress"]; // extract dependent MDFields PHX::MDField<ScalarT> def_grad = *dep_fields[F_string]; PHX::MDField<ScalarT> delta_time = *dep_fields["Delta Time"]; // extract evaluated MDFields PHX::MDField<ScalarT> stress = *eval_fields[cauchy_string]; // get State Variables Albany::MDArray def_grad_old = (*workset.stateArrayPtr)[F_string + "_old"]; // pressure is hard coded as 1 for now // this is likely not general enough :) ScalarT p = 1; // time increment ScalarT dt = delta_time(0); // containers Intrepid2::Tensor<ScalarT> Fnew(num_dims_); Intrepid2::Tensor<ScalarT> Fold(num_dims_); Intrepid2::Tensor<ScalarT> Finc(num_dims_); Intrepid2::Tensor<ScalarT> L(num_dims_); Intrepid2::Tensor<ScalarT> D(num_dims_); Intrepid2::Tensor<ScalarT> sigma(num_dims_); Intrepid2::Tensor<ScalarT> I(Intrepid2::eye<ScalarT>(num_dims_)); for (int cell(0); cell < workset.numCells; ++cell) { for (int pt(0); pt < num_pts_; ++pt) { // should only be the first time step if ( dt == 0 ) { for (int i=0; i < num_dims_; ++i) for (int j=0; j < num_dims_; ++j) stress(cell,pt,i,j) = 0.0; } else { // old deformation gradient for (int i=0; i < num_dims_; ++i) for (int j=0; j < num_dims_; ++j) Fold(i,j) = ScalarT(def_grad_old(cell,pt,i,j)); // current deformation gradient Fnew.fill(def_grad,cell,pt,0,0); // incremental deformation gradient Finc = Fnew * Intrepid2::inverse(Fold); // velocity gradient L = (1.0/dt) * Intrepid2::log(Finc); // strain rate (a.k.a rate of deformation) D = Intrepid2::sym(L); // stress tensor sigma = -p*I + 2.0*mu_*( D - (2.0/3.0)*Intrepid2::trace(D)*I); // update stress state for (int i=0; i < num_dims_; ++i) for (int j=0; j < num_dims_; ++j) stress(cell,pt,i,j) = sigma(i,j); } } } }
int quad2 (int dim, double a, double b, int (*func)(), double *prec, int n, double *f, double *scratch) { double error, dy, yo, aux; register int j,k; #ifdef MAINFRAME register int i; #else int i; #endif int jump, already; static int zero=0; void *memset(), *memcpy(); if(dim<1) return(-2); if(n>NQUAD2) n=NQUAD2; /* Scaling */ yo=(b+a)/2; dy=(b-a)/2; if((*func)(yo+dy*x[0],fold)) return(-3); memcpy(fw(0),fold,dim*sizeof(double)); for(k=0;k<dim;k++) Fold(k)*=dy*W1; for(jump=1,i=1;i<NQUAD2;i++) jump*=2; for(i=1;i<n;i++) /* for each quadrature rule */ { error=0; memset(f,zero,dim*sizeof(double)); /* put 0 over F[i] */ /* Calculate the integrated distribution */ jump/=2; for(j=0,already=1;j<M[NQUAD2-1];j+=jump) /* for each quadrature point */ { if(already) already=0; else /* point to be calculated */ { if((*func)(yo+dy*x[j],fw(j))) return(-3); if((*func)(yo-dy*x[j],faux)) return(-3); for(k=0;k<dim;k++) Fw(j,k)+=Faux(k); already=1; } for(k=0;k<dim;k++) F(k)+=dy*W(i,j/jump)*Fw(j,k); } /* Distributions comparison */ for(k=0;k<dim;k++) { aux=fabs(F(k)); aux=(aux>1E-100 ? fabs(F(k)-Fold(k))/aux : fabs(F(k)-Fold(k)) ); if(aux>error) error=aux; } if(error<(*prec)) break; memcpy(fold,f,dim*sizeof(double)); /* copy F[i] to Fold[i] */ } (*prec)=error; if(i==n) return(-1); return(0); }