D:/temp/pokerth-0.3-src/PokerTH-0.5/src/engine/neuro_engine/NeuroPlayer.cpp

gehe zur Dokumentation dieser Datei
00001 #include "NeuroPlayer.h"
00002 #include "handinterface.h"
00003 #include "tools.h"
00004 #include "cardsvalue.h"
00005 #include <configfile.h>
00006 #include "MemBrain_inc.h"
00007 
00008 #include <fstream>
00009 
00010 
00011 using namespace std;
00012 
00013 NeuroPlayer::NeuroPlayer(ConfigFile *c, BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB)
00014 : PlayerInterface(), myConfig(c), actualHand(0), actualBoard(b), myCardsValue(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(0), myButton(mB), myActiveStatus(aS), myTurn(0), myRoundStartCash(0), sBluff(0), sBluffStatus(0)
00015 {
00016 
00017 //      for statistic development
00018 //      if(myID==0) { 
00019 //              myActiveStatus=0;
00020 //              myCash=20;
00021 //      }
00022 // 
00023 //      if(myID==1) {
00024 //              myCash=6130;
00025 //      }
00026 //      if(myID==2) {
00027 //              myCash=2850;
00028 //      }
00030         
00031         // myBestHandPosition mit -1 initialisieren
00032         int i;
00033         for(i=0; i<5; i++) {
00034                 myBestHandPosition[i] = -1;
00035         }
00036 
00037         // myAverageSets initialisieren
00038         for(i=0; i<4; i++) {
00039                 myAverageSets[i] = 0;
00040         }
00041 
00042         // myAggressive initialisieren
00043         for(i=0; i<7; i++) {
00044                 myAggressive[i] = 0;
00045         }
00046 
00047         // Dude zuweisen
00048         Tools::getRandNumber(3 , 5, 1, &myDude, 0);
00049 //      cout << "Spieler: " << myID << " Dude: " << myDude << " Cash: " << myCash << " ActiveStatus: " << myActiveStatus << " Button: " << myButton << endl;
00050 
00051         // Dude4 zuweisen
00052         int interval = 7;
00053         int count = 4;
00054 
00055         int *tempArray = new int[count];
00056         Tools::getRandNumber(0, 2*interval, count, tempArray, 0);
00057         for(i=0; i<count; i++) {
00058                 myDude4 += tempArray[i];
00059         }
00060         myDude4 = (myDude4/count)-interval;
00061 
00062         delete[] tempArray;
00063 
00064         myCardsValue = new CardsValue;
00065         m_oppSeat = -1;
00066 
00067 
00068 }
00069 
00070 
00071 NeuroPlayer::~NeuroPlayer()
00072 {
00073 }
00074 
00075 
00076 void NeuroPlayer::setHand(HandInterface* br) { actualHand = br; }
00077 
00078 
00079 void NeuroPlayer::action() 
00080 {
00081         if(m_oppSeat == -1)
00082         {
00083                 for(int i=0;i<2;i++)
00084                         if(actualHand->getPlayerArray()[i] != this)
00085                                 m_oppSeat = i;
00086         }
00087 
00088         switch(actualHand->getActualRound()) {
00089                 case 0: 
00090                         {
00091                                 preflopEngine();
00092                                 actualBoard->collectSets();
00093                                 actualHand->getGuiInterface()->refreshPot();
00094                                 break;
00095                         } 
00096                 case 1: 
00097                         {
00098                                 flopEngine();
00099                                 actualBoard->collectSets();
00100                                 actualHand->getGuiInterface()->refreshPot();
00101                                 break;
00102                         } 
00103                 case 2: 
00104                         {
00105                                 turnEngine();
00106                                 actualBoard->collectSets();
00107                                 actualHand->getGuiInterface()->refreshPot();
00108                                 break;
00109                 } 
00110                 case 3: 
00111                         {
00112                                 riverEngine();
00113                                 actualBoard->collectSets();
00114                                 actualHand->getGuiInterface()->refreshPot();
00115                                 break;
00116                 } 
00117                 default: {}
00118         }
00119 
00120         myTurn = 0;
00121 
00122         
00123         //set that i was the last active player. need this for unhighlighting groupbox
00124         actualHand->setLastPlayersTurn(myID);
00125 
00126         actualHand->getGuiInterface()->logPlayerActionMsg(myName, myAction, mySet);
00127         actualHand->getGuiInterface()->nextPlayerAnimation();
00128 
00129 
00130 }
00131 
00132 
00133 void NeuroPlayer::preflopEngine() 
00134 {
00135         
00136         //Karten sind von 0 - 51 aufgeteilt: 51 = Pik Ass!
00137         int HoleCard1_Suite = (int)((myCards[0])/13) +1 ;       //1:Caro, 2:Herz, 3:Pik, 4:Kreuz
00138         int HoleCard2_Suite = (int)((myCards[1])/13) +1 ;
00139 
00140         int HoleCard1_Value = (myCards[0]) - (((myCards[0])/13)*13) +2;
00141         int HoleCard2_Value = (myCards[1]) - (((myCards[1])/13)*13) +2;
00142 
00143         int Position = actualHand->getDealerPosition()+1;               //Neuro Player ist Position 0
00144                                                                                                                 //1 = Neuro ist Dealer(Small Blind)
00145                                                                                                                 //2 = Big Blind
00146         double OwnStake_PreFlop = (double)this->getMyCash()/(actualHand->getSmallBlind()*2);
00147         double OppunentStake_PreFlop = (double)actualHand->getPlayerArray()[m_oppSeat]->getMyCash()/(actualHand->getSmallBlind()*2);
00148         
00149         
00150 
00151         double PotSize_PreFlop = this->actualBoard->getSets()/(actualHand->getSmallBlind()*2); 
00152         
00153         int Opponent_Fold_PreFlop=0, Opponent_Check_PreFlop=0,Opponent_Call_PreFlop=0, Opponent_Raise_PreFlop=0, Opponent_ReRaise_PreFlop=0, Opponent_All_In_PreFlop=0;
00154         int OppunentAction = actualHand->getPlayerArray()[m_oppSeat]->getMyAction();    // 0 = none, 1 = fold, 2 = check, 3 = call, 4 = bet, 5 = raise, 6 = allin
00155         switch(OppunentAction)
00156         {
00157         case 1:
00158                 Opponent_Fold_PreFlop = 1;
00159                 break;
00160         case 2:
00161                 Opponent_Check_PreFlop = 1;
00162                 break;
00163         case 3:
00164                 Opponent_Call_PreFlop = 1;
00165                 break;
00166         case 4:
00167                 Opponent_Call_PreFlop = 1;      // BET == CALL Preflop ???????
00168                 break;
00169         case 5:
00170                 Opponent_Raise_PreFlop = 1;     // RAISE RERAISE!!!!!!!!
00171                 break;
00172         case 6:
00173                 Opponent_All_In_PreFlop = 1;
00174                 break;
00175         }
00176 
00177         
00178         char version[128];
00179         if(_MB_GetVersionInfo(version, 128)==MEMBRAIN_ERR)
00180         {
00181                 cout<<"Fehler _MB_GetVersionInfo";
00182                 return;
00183         }       
00184 
00185         if(_MB_LoadNet("PreFlop.mbn")==MEMBRAIN_ERR)
00186         {
00187                 cout<<"Fehler";
00188                 return;
00189         }
00190         m_inputNamesPreFlop.clear();
00191         m_inputNamesPreFlop<< "Position"<<"OwnStake_PreFlop"<<"OpponentStake_PreFlop"<<"PotSize_PreFlop"<<"Opponent_Fold_PreFlop"<<"Opponent_Check_PreFlop"<<"Opponent_Call_PreFlop"<<"Opponent_Raise_PreFlop"<<"Opponent_ReRaise_PreFlop"<<"Opponent_All-In_PreFlop"<<"HoleCard1_Value"<<"HoleCard2_Value"<<"HoldCard1_Suite"<<"HoleCard2_Suite";
00192         m_inputValuesPreFlop.clear();
00193         m_inputValuesPreFlop<< Position << OwnStake_PreFlop << OppunentStake_PreFlop << PotSize_PreFlop << Opponent_Fold_PreFlop << Opponent_Check_PreFlop << Opponent_Call_PreFlop << Opponent_Raise_PreFlop << Opponent_ReRaise_PreFlop << Opponent_All_In_PreFlop << HoleCard1_Value << HoleCard2_Value << HoleCard1_Suite << HoleCard2_Suite;
00194         //Inputneuronen setzen
00195         setPreFlopNeuons();
00196                 
00197         //Netz rechnet
00198         _MB_ThinkStep();
00199         
00200         //Gewinnerneuron ermitteln
00201         
00202         m_ActionPreFlop = getAction();
00203 
00204         logPreFlopNeurons();
00205         if(_MB_DeleteNet(_MB_GetSelectedNet())==MEMBRAIN_ERR)
00206         {
00207                 cout<<"Fehler _MB_DeleteNet";
00208                 return;
00209         }       
00210 }
00211 
00212 int NeuroPlayer::getAction()
00213 {
00214         
00215         int winnerNeuron = _MB_GetOutputWinnerNeuron();
00216         //                                              0 = fold, 1 = check, 2 = bet, 3 = call, 4 = raise, 5=ReRaise, 6 = allin
00217         int OpponentAction = actualHand->getPlayerArray()[m_oppSeat]->getMyAction();
00218         // myAction: 0 = none,  1 = fold, 2 = check, 3 = call, 4 = bet, 5 = raise, 6 = allin
00219                 
00220         if(OpponentAction==4) //Bet
00221                 OpponentAction = 3;
00222         else if(OpponentAction == 3) //Call
00223                 OpponentAction = 4;
00224         else if(OpponentAction == 6) //AllIn
00225                 OpponentAction = 7;
00226         OpponentAction--;
00227 
00228         if(actualHand->getActualRound()==0)//PreFlop -> kein Bet :-(
00229         {
00230                 winnerNeuron++;
00231                 if(winnerNeuron==1)//Fold
00232                         winnerNeuron=0;
00233                 else if(winnerNeuron==2)//check
00234                         winnerNeuron=1;
00235         }
00236         
00237         //OpponentAction hat die selbe Struktur wie unsere Neuronen!
00238         //                                         0        1       2       3      4          5         6 
00239         //                                   "fold"<<"check"<<"bet"<<"call"<<"raise"<<"reraise"<<"allin"
00240         QStringList str_Actions;
00241         str_Actions                <<"fold"<<"check"<<"bet"<<"call"<<"raise"<<"reraise"<<"allin";
00242         QStringList OpponentBetAction;
00243         OpponentBetAction  <<"fold"<<"-"        <<"-"  <<"call"<<"raise"<<"-"      <<"allin";
00244         QStringList OpponentCheckAction;
00245         OpponentCheckAction<<"fold"<<"check"<<"bet"<<"-"   <<"-"    <<"-"      <<"allin";
00246         QStringList OpponentRaiseAction;
00247         OpponentRaiseAction<<"fold"<<"-"    <<"-"  <<"call"<<"-"    <<"reraise"<<"allin";
00248         QStringList OpponentAllinAction;
00249         OpponentAllinAction<<"fold"<<"-"    <<"-"  <<"call"<<"raise"<<"reraise"<<"allin";
00250 
00251         QString myStrAction = str_Actions.at(winnerNeuron);
00252         if(actualHand->getPlayerArray()[m_oppSeat]->getMyAction()>0) //Gegner war noch auch dran
00253         {
00254                 switch(OpponentAction)
00255                 {
00256                 case 0: //fold:
00257                         break;
00258                 case 1: //check
00259                         if(!OpponentCheckAction.contains(myStrAction))
00260                                 myStrAction = getCorrectAction(myStrAction, OpponentCheckAction);
00261                         break;
00262                 case 2: //Bet
00263                         if(!OpponentBetAction.contains(myStrAction))
00264                                 myStrAction = getCorrectAction(myStrAction, OpponentBetAction);
00265                         break;
00266                 //Call gibt es nicht
00267                         break;
00268                 case 4: //Reise
00269                         if(!OpponentRaiseAction.contains(myStrAction))
00270                                 myStrAction = getCorrectAction(myStrAction, OpponentRaiseAction);
00271                         break;
00272                 //Reraise gibt es nicht                 
00273                 case 6: //AllIn
00274                         if(!OpponentRaiseAction.contains(myStrAction))
00275                                 myStrAction = getCorrectAction(myStrAction, OpponentRaiseAction);
00276                         break;
00277                 }
00278         }
00279 
00280         int tempHighestSet = 0;
00281         switch (actualHand->getActualRound()) 
00282         {
00283 
00284                 case 0: {tempHighestSet = actualHand->getPreflop()->getHighestSet();}
00285                 break;
00286                 case 1: {tempHighestSet = actualHand->getFlop()->getHighestSet();}
00287                 break;
00288                 case 2: {tempHighestSet = actualHand->getTurn()->getHighestSet();}
00289                 break;
00290                 case 3: {tempHighestSet = actualHand->getRiver()->getHighestSet();}
00291                 break;
00292                 default: {}     
00293         }
00294 
00295         switch(str_Actions.indexOf(myStrAction))
00296         {
00297         case 0: //fold
00298                 myAction = 1;
00299                 break;
00300         case 1: //check
00301                 myAction = 2;
00302                 break;
00303         case 2: //Bet
00304                 myAction = 4;
00305                 setMySet((int)(actualBoard->getPot()/2)); // immer 1/2 Potsize???????????????????????????????????
00306                 break;
00307         case 3: //Call
00308                 myAction = 3;
00309                 setMySet(tempHighestSet - getMySet());
00310                 mySet;
00311                 break;
00312         case 4: //Reise
00313                 myAction = 5;
00314                 setMySet(actualHand->getSmallBlind()*2*3);
00315                 break;
00316         case 5:
00317                 //ReReise
00318                 myAction = 5;
00319                 setMySet(actualHand->getSmallBlind()*2*3);
00320                 break;
00321         case 6: //AllIn
00322                 myAction = 6;
00323                 setMySet(getMyCash());
00324                 setMyCash(0);
00325                 break;
00326         }
00327 
00328         switch (actualHand->getActualRound()) 
00329         {
00330 
00331                 case 0: {actualHand->getPreflop()->setHighestSet(getMySet());}
00332                 break;
00333                 case 1: {actualHand->getFlop()->setHighestSet( getMySet());}
00334                 break;
00335                 case 2: {actualHand->getTurn()->setHighestSet( getMySet());}
00336                 break;
00337                 case 3: {actualHand->getRiver()->setHighestSet(getMySet());}
00338                 break;
00339                 default: {}     
00340         }
00341         return str_Actions.indexOf(myStrAction);
00342 }
00343 
00344 QString NeuroPlayer::getCorrectAction(QString myStrAction, QStringList OpponentActionList)
00345 {
00346         //Wenn das Netz einen Spielfehler verursacht -> z.B. auf ein Raise mit einem Check antwortet
00347         //wird hier das dem Gewinnerneuron am nächstliegende aber mögliche Neuon ausgewählt.
00348 
00349         actualHand->getGuiInterface()->logMessage("Netz fehler");
00350         double  winnerValue = 0.0;
00351         QString retAction;
00352         for(int i=0;i<OpponentActionList.count();i++)
00353         {
00354                 if(OpponentActionList.at(i)!="-")
00355                 {
00356                         int zz = i;     //zz wird veraendert!
00357                         double value;
00358                         _MB_GetOutputOut(zz, &value);
00359                         if(value>winnerValue)
00360                         {
00361                                 winnerValue = value;
00362                                 retAction = OpponentActionList.at(i);
00363                         }
00364                 }
00365         }
00366         return retAction;
00367 }
00368 
00369 void NeuroPlayer::setPreFlopNeuons()
00370 {
00371         //Inputneuronen setzen
00372         for(int i=0;i<_MB_GetInputCount();i++)
00373         {       
00374                 char name[128];
00375                 int idx = i;
00376                 if(_MB_GetInputName(idx, name, 128)==MEMBRAIN_ERR)
00377                 {
00378                         cout<<"Fehler _MB_GetInputName";
00379                         return;
00380                 }
00381                 if(m_inputNamesPreFlop.contains(name))
00382                 {       
00383                         idx = i;
00384                         _MB_ApplyInputAct(idx, m_inputValuesPreFlop.at(m_inputNamesPreFlop.indexOf(name)));
00385                 }
00386         }
00387 }
00388 
00389 void NeuroPlayer::logPreFlopNeurons()
00390 {
00391         QTextStream stream;
00392         QFile file("./preFlop.csv");
00393         if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
00394                 return;
00395         
00396         stream.setDevice(&file);
00397         //in der Erste Zeile werden die Namen der Input/Outputneuronen werwartet
00398         stream<<m_inputNamesPreFlop.at(0);
00399         for(int z=1;z<m_inputNamesPreFlop.count();z++)
00400                 stream<<","<<m_inputNamesPreFlop.at(z);
00401         
00402 stream<<",Fold_PreFlop"<<",Check_PreFlop"<<",Call_PreFlop"<<",Raise_PreFlop"<<",ReRaise_PreFlop"<<",All-In_PreFlop";
00403 stream<<endl;
00404 
00405         //EingabeNeuronen
00406         stream<<m_inputValuesPreFlop.at(0);
00407         for(int z=1;z<m_inputValuesPreFlop.count();z++)
00408                 stream<<","<<m_inputValuesPreFlop.at(z);
00409         //Ausgabe Neuronen!
00410         for(int z=0;z<7;z++)
00411         {
00412                 if(m_ActionPreFlop == z)
00413                         stream<<","<<1;
00414                 else
00415                         stream<<","<<0;
00416 
00417                 if(z==1)        //Da PreFlop kein Bet möglich ist!
00418                         z++;
00419         }
00420         stream<<endl;
00421 }
00422 
00423 
00424 void NeuroPlayer::flopEngine() 
00425 {
00426         double OwnStake_PostFlop = this->getMyCash()/(actualHand->getSmallBlind()*2);
00427         double OpponentStake_PostFlop = actualHand->getPlayerArray()[m_oppSeat]->getMyCash()/(actualHand->getSmallBlind()*2);
00428         double PotSize_PostFlop = (this->actualBoard->getPot() + this->actualBoard->getSets())/(actualHand->getSmallBlind()*2);
00429 
00430         
00431         int Opponent_Fold_PostFlop=0, Opponent_Check_PostFlop=0,Opponent_Call_PostFlop=0, Opponent_Raise_PostFlop=0, Opponent_Bet_PostFlop=0,Opponent_ReRaise_PostFlop=0, Opponent_All_In_PostFlop=0;
00432         int OppunentAction = actualHand->getPlayerArray()[m_oppSeat]->getMyAction();    // 0 = none, 1 = fold, 2 = check, 3 = call, 4 = bet, 5 = raise, 6 = allin
00433         switch(OppunentAction) // myAction: 0 = none, 1 = fold, 2 = check, 3 = call, 4 = bet, 5 = raise, 6 = allin
00434         {
00435         case 1:
00436                 Opponent_Fold_PostFlop = 1;
00437                 break;
00438         case 2:
00439                 Opponent_Check_PostFlop = 1;
00440                 break;
00441         case 3:
00442                 Opponent_Call_PostFlop = 1;
00443                 break;
00444         case 4:
00445                 Opponent_Bet_PostFlop = 1;      
00446                 break;
00447         case 5:
00448                 Opponent_Raise_PostFlop = 1;    // RAISE RERAISE!!!!!!!!
00449                 break;
00450         case 6:
00451                 Opponent_All_In_PostFlop = 1;
00452                 break;
00453         }
00454 
00455         int Own_Fold_PreFlop=0,Own_Check_PreFlop=0,Own_Call_PreFlop=0,Own_Raise_PreFlop=0,Own_ReRaise_PreFlop=0,Own_All_In_PreFlop=0;
00456         switch(m_ActionPreFlop)
00457         {
00458         case 0: //fold
00459                 Own_Fold_PreFlop = 1;
00460                 break;
00461         case 1: //check
00462                 Own_Check_PreFlop = 1;
00463                 break;
00464         case 2: //Bet
00465                 //gibt es Preflop nicht
00466                 break;
00467         case 3: //Call
00468                 Own_Call_PreFlop = 1;
00469                 break;
00470         case 4: //Reise
00471                 Own_Raise_PreFlop = 1;
00472                 break;
00473         case 5:
00474                 //ReReise
00475                 Own_ReRaise_PreFlop = 1;
00476                 break;
00477         case 6: //AllIn
00478                 Own_All_In_PreFlop = 1;
00479                 break;
00480         }
00481         
00482         int CommCard1_Value = (actualBoard->getFlopCard1()) - (((actualBoard->getFlopCard1())/13)*13) +2;
00483         int CommCard2_Value = (actualBoard->getFlopCard2()) - (((actualBoard->getFlopCard2())/13)*13) +2;
00484         int CommCard3_Value = (actualBoard->getFlopCard3()) - (((actualBoard->getFlopCard3())/13)*13) +2;
00485         int CommCard1_Suite = (int)((actualBoard->getFlopCard1())/13) +1;
00486         int CommCard2_Suite = (int)((actualBoard->getFlopCard2())/13) +1;
00487         int CommCard3_Suite = (int)((actualBoard->getFlopCard3())/13) +1;
00488         
00489 
00490         m_inputNamesPostFlop.clear();
00491         m_inputNamesPostFlop<< "OwnStake_PostFlop"<<"OpponentStake_PostFlop"<<"PotSize_PostFlop"<<"Opponent_Fold_PostFlop"<<"Opponent_Check_PostFlop"<<"Opponent_Bet_PostFlop"<<"Opponent_Call_PostFlop"<<"Opponent_Raise_PostFlop"<<"Opponent_ReRaise_PostFlop"<<"Opponent_All-In_PostFlop"<<"CommCard1_Value"<<"CommCard2_Value"<<"CommCard3_Value"<<"CommCard1_Suite"<<"CommCard2_Suite"<<"CommCard3_Suite"<<"Own_Fold_PreFlop"<<"Own_Check_PreFlop"<<"Own_Call_PreFlop"<<"Own_Raise_PreFlop"<<"Own_ReRaise_PreFlop"<<"Own_All-In_PreFlop";
00492         m_inputValuesPostFlop.clear();
00493         m_inputValuesPostFlop<< OwnStake_PostFlop << OpponentStake_PostFlop << PotSize_PostFlop << Opponent_Fold_PostFlop << Opponent_Check_PostFlop << Opponent_Bet_PostFlop << Opponent_Call_PostFlop << Opponent_Raise_PostFlop << Opponent_ReRaise_PostFlop << Opponent_All_In_PostFlop << CommCard1_Value << CommCard2_Value << CommCard3_Value << CommCard1_Suite << CommCard2_Suite << CommCard3_Suite << Own_Fold_PreFlop << Own_Check_PreFlop <<Own_Call_PreFlop  <<Own_Raise_PreFlop  << Own_ReRaise_PreFlop << Own_All_In_PreFlop;
00494 
00495         if(_MB_LoadNet("PostFlop.mbn")==MEMBRAIN_ERR)
00496         {
00497                 cout<<"Fehler";
00498                 return;
00499         }
00500         //Weil PokerTH Bug: Position nach dem Flop -> Position tauschen
00501         m_inputValuesPreFlop[0] = m_inputValuesPreFlop.at(0) == 1 ? 2:1;
00502         
00503         setPreFlopNeuons();
00504         setPostFlopNeurons();
00505 
00506         _MB_ThinkStep();
00507         //Gewinnerneuron ermitteln
00508         
00509         m_ActionPostFlop = getAction();
00510         logPostFlopNeurons();
00511         if(_MB_DeleteNet(_MB_GetSelectedNet())==MEMBRAIN_ERR)
00512         {
00513                 cout<<"Fehler _MB_DeleteNet";
00514                 return;
00515         }
00516         
00517 }
00518 
00519 void NeuroPlayer::setPostFlopNeurons()
00520 {
00521         int seted = 0;
00522         //Inputneuronen setzen
00523         for(int i=0;i<_MB_GetInputCount();i++)
00524         {       
00525                 char name[128];
00526                 int idx = i;
00527                 if(_MB_GetInputName(idx, name, 128)==MEMBRAIN_ERR)
00528                 {
00529                         cout<<"Fehler _MB_GetInputName";
00530                         return;
00531                 }
00532                 if(m_inputNamesPostFlop.contains(name))
00533                 {       
00534                         idx = i;
00535                         _MB_ApplyInputAct(idx, m_inputValuesPostFlop.at(m_inputNamesPostFlop.indexOf(name)));
00536                         seted++;
00537                 }
00538         }
00539         if(seted != m_inputNamesPostFlop.count())
00540                 cout<<"Fehler!! Es wurden nicht alles PostFlopNeuonen verarbeitet!!!!!!!"<<endl;
00541 }
00542 
00543 void NeuroPlayer::logPostFlopNeurons()
00544 {
00545         
00546         QTextStream stream;
00547         QFile file("./postFlop.csv");
00548         if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
00549                 return;
00550         
00551         stream.setDevice(&file);
00552         //in der Erste Zeile werden die Namen der Input/Outputneuronen werwartet
00553         stream<<m_inputNamesPreFlop.at(0);
00554         for(int z=1;z<m_inputNamesPreFlop.count();z++)
00555                 stream<<","<<m_inputNamesPreFlop.at(z);
00556         for(int z=0;z<m_inputNamesPostFlop.count();z++)
00557                 stream<<","<<m_inputNamesPostFlop.at(z);
00558         stream<<",Fold_PostFlop"<<",Check_PostFlop"<<",Bet_PostFlop"<<",Call_PostFlop"<<",Raise_PostFlop"<<",ReRaise_PostFlop"<<",All-In_PostFlop";
00559         stream<<endl;
00560 
00561         //EingabeNeuronen
00562         stream<<m_inputValuesPreFlop.at(0);
00563         for(int z=1;z<m_inputValuesPreFlop.count();z++)
00564                 stream<<","<<m_inputValuesPreFlop.at(z);
00565 
00566         for(int z=0;z<m_inputValuesPostFlop.count();z++)
00567                 stream<<","<<m_inputValuesPostFlop.at(z);
00568 
00569         //Ausgabe Neuronen werden mit 0 aufgefüllt!!!!
00570         for(int z=0;z<7;z++)
00571         {
00572                 if(m_ActionPostFlop == z)
00573                         stream<<","<<1;
00574                 else
00575                         stream<<","<<0;
00576         }
00577         stream<<endl;
00578         file.close();
00579 }
00580 
00581 
00582 void NeuroPlayer::turnEngine() 
00583 {
00584         double OwnStake_PostTurn = this->getMyCash()/(actualHand->getSmallBlind()*2);
00585         double OpponentStake_PostTurn = actualHand->getPlayerArray()[m_oppSeat]->getMyCash()/(actualHand->getSmallBlind()*2);
00586         double PotSize_PostTurn = (this->actualBoard->getPot()+this->actualBoard->getSets())/(actualHand->getSmallBlind()*2);
00587 
00588         int Opponent_Fold_PostTurn=0, Opponent_Check_PostTurn=0,Opponent_Call_PostTurn=0, Opponent_Raise_PostTurn=0, Opponent_Bet_PostTurn=0,Opponent_ReRaise_PostTurn=0, Opponent_All_In_PostTurn=0;
00589         int OppunentAction = actualHand->getPlayerArray()[m_oppSeat]->getMyAction();    // 0 = none, 1 = fold, 2 = check, 3 = call, 4 = bet, 5 = raise, 6 = allin
00590         switch(OppunentAction) // myAction: 0 = none, 1 = fold, 2 = check, 3 = call, 4 = bet, 5 = raise, 6 = allin
00591         {
00592         case 1:
00593                 Opponent_Fold_PostTurn = 1;
00594                 break;
00595         case 2:
00596                 Opponent_Check_PostTurn = 1;
00597                 break;
00598         case 3:
00599                 Opponent_Call_PostTurn = 1;
00600                 break;
00601         case 4:
00602                 Opponent_Bet_PostTurn = 1;      
00603                 break;
00604         case 5:
00605                 Opponent_Raise_PostTurn = 1;    // RAISE RERAISE!!!!!!!!
00606                 break;
00607         case 6:
00608                 Opponent_All_In_PostTurn = 1;
00609                 break;
00610         }
00611         int Own_Fold_PostFlop=0,Own_Check_PostFlop=0,Own_Bet_PostFlop=0,Own_Call_PostFlop=0,Own_Raise_PostFlop=0,Own_ReRaise_PostFlop=0,Own_All_In_PostFlop=0;
00612         switch(m_ActionPostFlop)
00613         {
00614         case 0: //fold
00615                 Own_Fold_PostFlop = 1;
00616                 break;
00617         case 1: //check
00618                 Own_Check_PostFlop = 1;
00619                 break;
00620         case 2: //Bet
00621                 Own_Bet_PostFlop = 1;
00622                 break;
00623         case 3: //Call
00624                 Own_Call_PostFlop = 1;
00625                 break;
00626         case 4: //Reise
00627                 Own_Raise_PostFlop = 1;
00628                 break;
00629         case 5: //ReReise
00630                 Own_ReRaise_PostFlop = 1;
00631                 break;
00632         case 6: //AllIn
00633                 Own_All_In_PostFlop = 1;
00634                 break;
00635         }
00636 
00637         int CommCard4_Value = (actualBoard->getTurnCard()) - (((actualBoard->getTurnCard())/13)*13) +2;
00638         int CommCard4_Suite = (int)((actualBoard->getTurnCard())/13) +1;
00639 
00640         m_inputNamesTurn.clear();
00641         m_inputNamesTurn<<"OwnStake_PostTurn"<<"OpponentStake_PostTurn"<<"PotSize_PostTurn"<<"Opponent_Fold_PostTurn"<<"Opponent_Check_PostTurn"<<"Opponent_Bet_PostTurn"<<"Opponent_Call_PostTurn"<<"Opponent_Raise_PostTurn"<<"Opponent_ReRaise_PostTurn"<<"Opponent_All-In_PostTurn"<<"CommCard4_Value"<<"CommCard4_Suite"<<"Own_Fold_PostFlop"<<"Own_Check_PostFlop"<<"Own_Bet_PostFlop"<<"Own_Call_PostFlop"<<"Own_Raise_PostFlop"<<"Own_ReRaise_PostFlop"<<"Own_All-In_PostFlop"; 
00642         m_inputValuesTurn.clear();
00643         m_inputValuesTurn<<OwnStake_PostTurn << OpponentStake_PostTurn << PotSize_PostTurn << Opponent_Fold_PostTurn << Opponent_Check_PostTurn << Opponent_Bet_PostTurn << Opponent_Call_PostTurn << Opponent_Raise_PostTurn << Opponent_ReRaise_PostTurn << Opponent_All_In_PostTurn << CommCard4_Value << CommCard4_Suite<< Own_Fold_PostFlop << Own_Check_PostFlop << Own_Bet_PostFlop << Own_Call_PostFlop << Own_Raise_PostFlop << Own_ReRaise_PostFlop << Own_All_In_PostFlop;
00644         
00645         if(_MB_LoadNet("PostTurn.mbn")==MEMBRAIN_ERR)
00646         {
00647                 cout<<"Fehler";
00648                 return;
00649         }
00650         setPreFlopNeuons();
00651         setPostFlopNeurons();
00652         setTurnNeurons();
00653 
00654         _MB_ThinkStep();
00655         //Gewinnerneuron ermitteln
00656         
00657         m_ActionTurn = getAction();
00658 
00659         logTurnNeurons();
00660         if(_MB_DeleteNet(_MB_GetSelectedNet())==MEMBRAIN_ERR)
00661         {
00662                 cout<<"Fehler _MB_DeleteNet";
00663                 return;
00664         }
00665         
00666 }
00667 
00668 void NeuroPlayer::setTurnNeurons()
00669 {
00670         int seted=0;
00671         //Inputneuronen setzen
00672         for(int i=0;i<_MB_GetInputCount();i++)
00673         {       
00674                 char name[128];
00675                 int idx = i;
00676                 if(_MB_GetInputName(idx, name, 128)==MEMBRAIN_ERR)
00677                 {
00678                         cout<<"Fehler _MB_GetInputName";
00679                         return;
00680                 }
00681                 if(m_inputNamesTurn.contains(name))
00682                 {       
00683                         idx = i;
00684                         _MB_ApplyInputAct(idx, m_inputValuesTurn.at(m_inputNamesTurn.indexOf(name)));
00685                         seted++;
00686                 }
00687         }
00688         if(seted != m_inputNamesTurn.count())
00689                 cout<<"Fehler!! Es wurden nicht alles TurnNeuonen verarbeitet!!!!!!!"<<endl;
00690 }
00691 
00692 void NeuroPlayer::logTurnNeurons()
00693 {
00694         QTextStream stream;
00695         QFile file("./postTurn.csv");
00696         if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
00697                 return;
00698         
00699         stream.setDevice(&file);
00700         //in der Erste Zeile werden die Namen der Input/Outputneuronen werwartet
00701         stream<<m_inputNamesPreFlop.at(0);
00702         for(int z=1;z<m_inputNamesPreFlop.count();z++)
00703                 stream<<","<<m_inputNamesPreFlop.at(z);
00704         for(int z=0;z<m_inputNamesPostFlop.count();z++)
00705                 stream<<","<<m_inputNamesPostFlop.at(z);
00706         for(int z=0;z<m_inputNamesTurn.count();z++)
00707                 stream<<","<<m_inputNamesTurn.at(z);
00708         
00709         stream<<",Fold_PostTurn"<<",Check_PostTurn"<<",Bet_PostTurn"<<",Call_PostTurn"<<",Raise_PostTurn"<<",ReRaise_PostTurn"<<",All-In_PostTurn";
00710         stream<<endl;
00711 
00712         //EingabeNeuronen
00713         stream<<m_inputValuesPreFlop.at(0);
00714         for(int z=1;z<m_inputValuesPreFlop.count();z++)
00715                 stream<<","<<m_inputValuesPreFlop.at(z);
00716 
00717         for(int z=0;z<m_inputValuesPostFlop.count();z++)
00718                 stream<<","<<m_inputValuesPostFlop.at(z);
00719 
00720         for(int z=0;z<m_inputValuesTurn.count();z++)
00721                 stream<<","<<m_inputValuesTurn.at(z);
00722 
00723 
00724         //Ausgabe Neuronen!!!!
00725         for(int z=0;z<7;z++)
00726         {
00727                 if(m_ActionTurn == z)
00728                         stream<<","<<1;
00729                 else
00730                         stream<<","<<0;
00731         }
00732         stream<<endl;
00733         file.close();
00734 }
00735 
00736 
00737 void NeuroPlayer::riverEngine() 
00738 {
00739         double OwnStake_PostRiver = this->getMyCash()/(actualHand->getSmallBlind()*2);
00740         double OpponentStake_PostRiver = actualHand->getPlayerArray()[m_oppSeat]->getMyCash()/(actualHand->getSmallBlind()*2);
00741         double PotSize_PostRiver = (this->actualBoard->getPot()+this->actualBoard->getSets())/(actualHand->getSmallBlind()*2);
00742 
00743         int Opponent_Fold_PostRiver=0, Opponent_Check_PostRiver=0,Opponent_Call_PostRiver=0, Opponent_Raise_PostRiver=0, Opponent_Bet_PostRiver=0,Opponent_ReRaise_PostRiver=0, Opponent_All_In_PostRiver=0;
00744         int OppunentAction = actualHand->getPlayerArray()[m_oppSeat]->getMyAction();    // 0 = none, 1 = fold, 2 = check, 3 = call, 4 = bet, 5 = raise, 6 = allin
00745         switch(OppunentAction) // myAction: 0 = none, 1 = fold, 2 = check, 3 = call, 4 = bet, 5 = raise, 6 = allin
00746         {
00747         case 1:
00748                 Opponent_Fold_PostRiver = 1;
00749                 break;
00750         case 2:
00751                 Opponent_Check_PostRiver = 1;
00752                 break;
00753         case 3:
00754                 Opponent_Call_PostRiver = 1;
00755                 break;
00756         case 4:
00757                 Opponent_Bet_PostRiver = 1;     
00758                 break;
00759         case 5:
00760                 Opponent_Raise_PostRiver = 1;   // RAISE RERAISE!!!!!!!!
00761                 break;
00762         case 6:
00763                 Opponent_All_In_PostRiver = 1;
00764                 break;
00765         }
00766         int Own_Fold_PostTurn=0,Own_Check_PostTurn=0,Own_Bet_PostTurn=0,Own_Call_PostTurn=0,Own_Raise_PostTurn=0,Own_ReRaise_PostTurn=0,Own_All_In_PostTurn=0; 
00767         switch(m_ActionTurn)
00768         {
00769         case 0: //fold
00770                 Own_Fold_PostTurn = 1;
00771                 break;
00772         case 1: //check
00773                 Own_Check_PostTurn = 1;
00774                 break;
00775         case 2: //Bet
00776                 Own_Bet_PostTurn = 1;
00777                 break;
00778         case 3: //Call
00779                 Own_Call_PostTurn = 1;
00780                 break;
00781         case 4: //Reise
00782                 Own_Raise_PostTurn = 1;
00783                 break;
00784         case 5: //ReReise
00785                 Own_ReRaise_PostTurn = 1;
00786                 break;
00787         case 6: //AllIn
00788                 Own_All_In_PostTurn = 1;
00789                 break;
00790         }
00791 
00792         int CommCard5_Value = (actualBoard->getRiverCard()) - (((actualBoard->getRiverCard())/13)*13) +2;
00793         int CommCard5_Suite = (int)((actualBoard->getRiverCard())/13) +1;
00794 
00795         m_inputNamesTurn.clear();
00796         m_inputNamesTurn<<"OwnStake_PostRiver"<<"OpponentStake_PostRiver"<<"PotSize_PostRiver"<<"Opponent_Fold_PostRiver"<<"Opponent_Check_PostRiver"<<"Opponent_Bet_PostRiver"<<"Opponent_Call_PostRiver"<<"Opponent_Raise_PostRiver"<<"Opponent_ReRaise_PostRiver"<<"Opponent_All-In_PostRiver"<<"CommCard5_Value"<<"CommCard5_Suite"<<"Own_Fold_PostTurn"<<"Own_Check_PostTurn"<<"Own_Bet_PostTurn"<<"Own_Call_PostTurn"<<"Own_Raise_PostTurn"<<"Own_ReRaise_PostTurn"<<"Own_All-In_PostTurn"; 
00797         m_inputValuesTurn.clear();
00798         m_inputValuesTurn<<OwnStake_PostRiver << OpponentStake_PostRiver << PotSize_PostRiver << Opponent_Fold_PostRiver << Opponent_Check_PostRiver << Opponent_Bet_PostRiver << Opponent_Call_PostRiver << Opponent_Raise_PostRiver << Opponent_ReRaise_PostRiver << Opponent_All_In_PostRiver << CommCard5_Value << CommCard5_Suite << Own_Fold_PostTurn << Own_Check_PostTurn << Own_Bet_PostTurn << Own_Call_PostTurn << Own_Raise_PostTurn << Own_ReRaise_PostTurn << Own_All_In_PostTurn; 
00799         if(_MB_LoadNet("PostRiver.mbn")==MEMBRAIN_ERR)
00800         {
00801                 cout<<"Fehler";
00802                 return;
00803         }
00804         setPreFlopNeuons();
00805         setPostFlopNeurons();
00806         setTurnNeurons();
00807         setRiverNeurons();
00808 
00809         _MB_ThinkStep();
00810         //Gewinnerneuron ermitteln
00811         
00812         m_ActionRiver = getAction();
00813 
00814         logRiverNeurons();
00815         if(_MB_DeleteNet(_MB_GetSelectedNet())==MEMBRAIN_ERR)
00816         {
00817                 cout<<"Fehler _MB_DeleteNet";
00818                 return;
00819         }
00820 }
00821 
00822 void NeuroPlayer::setRiverNeurons()
00823 {
00824         int seted=0;
00825         //Inputneuronen setzen
00826         for(int i=0;i<_MB_GetInputCount();i++)
00827         {       
00828                 char name[128];
00829                 int idx = i;
00830                 if(_MB_GetInputName(idx, name, 128)==MEMBRAIN_ERR)
00831                 {
00832                         cout<<"Fehler _MB_GetInputName";
00833                         return;
00834                 }
00835                 if(m_inputNamesRiver.contains(name))
00836                 {       
00837                         idx = i;
00838                         _MB_ApplyInputAct(idx, m_inputValuesRiver.at(m_inputNamesRiver.indexOf(name)));
00839                         seted++;
00840                 }
00841         }
00842         if(seted!=m_inputNamesRiver.count())
00843                 cout<<"Fehler!! Es wurden nicht alles RiverNeuonen verarbeitet!!!!!!!"<<endl;
00844 
00845 }
00846 
00847 void NeuroPlayer::logRiverNeurons()
00848 {
00849         QTextStream stream;
00850         QFile file("./postRiver.csv");
00851         if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
00852                 return;
00853         
00854         stream.setDevice(&file);
00855         //in der Erste Zeile werden die Namen der Input/Outputneuronen werwartet
00856         stream<<m_inputNamesPreFlop.at(0);
00857         for(int z=1;z<m_inputNamesPreFlop.count();z++)
00858                 stream<<","<<m_inputNamesPreFlop.at(z);
00859         for(int z=0;z<m_inputNamesPostFlop.count();z++)
00860                 stream<<","<<m_inputNamesPostFlop.at(z);
00861         for(int z=0;z<m_inputNamesTurn.count();z++)
00862                 stream<<","<<m_inputNamesTurn.at(z);
00863         for(int z=0;z<m_inputNamesRiver.count();z++)
00864                 stream<<","<<m_inputNamesRiver.at(z);
00865         
00866         stream<<",Fold_PostRiver"<<",Check_PostRiver"<<",Bet_PostRiver"<<",Call_PostRiver"<<",Raise_PostRiver"<<",ReRaise_PostRiver"<<",All-In_PostRiver";
00867         stream<<endl;
00868 
00869         //EingabeNeuronen
00870         stream<<m_inputValuesPreFlop.at(0);
00871         for(int z=1;z<m_inputValuesPreFlop.count();z++)
00872                 stream<<","<<m_inputValuesPreFlop.at(z);
00873 
00874         for(int z=0;z<m_inputValuesPostFlop.count();z++)
00875                 stream<<","<<m_inputValuesPostFlop.at(z);
00876 
00877         for(int z=0;z<m_inputValuesTurn.count();z++)
00878                 stream<<","<<m_inputValuesTurn.at(z);
00879 
00880         for(int z=0;z<m_inputValuesRiver.count();z++)
00881                 stream<<","<<m_inputValuesRiver.at(z);
00882 
00883 
00884         //Ausgabe Neuronen werden mit 0 aufgefüllt!!!!
00885         for(int z=0;z<7;z++)
00886         {
00887                 if(m_ActionRiver == z)
00888                         stream<<","<<1;
00889                 else
00890                         stream<<","<<0;
00891         }
00892         stream<<endl;
00893         file.close();
00894 
00895 }
00896 
00897 void NeuroPlayer::setNetSessionData(boost::shared_ptr<SessionData> session)
00898 {
00899         myNetSessionData = session;
00900 }
00901 
00902 boost::shared_ptr<SessionData> NeuroPlayer::getNetSessionData()
00903 {
00904         return myNetSessionData;
00905 }
00906 
00907 

Erzeugt am Sun Nov 11 17:33:12 2007 für PokerTH von  doxygen 1.5.3