/* This program considers all possible permutations of ordinal payoffs in 2x2 games and from this extracts * a representative game to stand for all possible permutations. As this program will show, there are 726 * 2x2 games with purely ordinal payoffs. If games are considered to be different depending on which * perspective a player is assigned to (how some games are played depends not only on the distribution of * the payoffs but on this distribution relative to the perspective assigned to each player) then there * are 1413 games (perhaps a better terminology would be to say that there are 1413 different * "perspectives") because there are 613 non-symmetric games. * * This program also catalogues all the status quo positions/perspectives that exist inside all the 2x2 * games. A sq position consists of one player taking an outcome as default and then ordinally ranking * all the the other payoffs with respect to the status quo. The player making this assessment does it for * both players. There are 729 sq perspectives. As with games, they are not evenly distributed. The TeX * file produced lists all the games that each sq position can be found in and the frequencies that they * occur with when payoffs are randomly determined. * * Pieces of the terminal output can be copied into text files and used to number games in other programs. * The TeX file that is created will form the basis of a taxonomy of all 2x2 games. * This work is licensed under the Creative Commons Attribution-Share Alike 2.5 Canada License. * This To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.5/ca/ * This or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, * This California, 94105, USA. * Written by John Simpson, Department of Philosophy, University of Alberta, 2007, 2008, 2009, 2010. * */ #include #include #include #include #include #include #include #include //#include using namespace std; //using std::vector; //using std::swap_ranges; //using std::count_if; void headsUp (vector*); void sqPosCounter(vector*, vector*, vector >*); void swapDias(vector*); void swapCols(vector*); void swapRows(vector*); void swapPlayers(vector*); void printGame(vector*); void outTexGames(vector*, vector*, vector*, vector*, vector*, vector*, vector >*, vector >*, ostream&); void outSQPositions(vector*, vector*, vector >*, vector*,ostream&); int gameIndexer(vector*, const bool, vector*); int complimentTest(vector*); int bit2pos(const int); int pos2bit(const int); void loadIndexNumbersNC(vector*); int main(void) { int numberCount=0; int copyCount=0; int tempNumber=0; int gameTyper[5][5]={{1,2,3,4,5},{2,6,7,8,9},{3,7,10,11,12},{4,8,11,13,14},{5,9,12,14,15}}; int gameTypeCount[5][5]={{0}}; string outFileName; string outFileName1; string outFileName2; outFileName="2x2texGames.tex"; ofstream outFile0(outFileName.data(), ios::out); outFileName1="SQ-stats.txt"; ofstream outFile1(outFileName1.data(), ios::out); outFileName2="2x2-SQPositions.tex"; ofstream outFile2(outFileName2.data(), ios::out); vector currentGame; //holds the 8 payoffs that make-up the game currently being considered vector gameNumbers; //holds the the lowest calculated ID number of every single game vector pureOrdinalProb; //holds the number of permutations of the game are possible for purely ordinal generation of each separate payoff vector tenCardinalProb(726,0); //holds the number of permutations of the game are possible for cardinal values with each payoff randomly generated vector games; //holds the payoffs associated with each game. Every eight values a new game starts vector gameTypes; //Identifies which game is of which type. Synchronized with the vector "games". vector sqPositionCount(729,0); //holds counts of the number of times each status quo perspective appears over total number of games vector > sqPositions; //holds the exact sq numbers that appear in each particular game vector > perspectives; vector indexNumbersNC; loadIndexNumbersNC(&indexNumbersNC); for (int i=0; i<4; i++) //0 for (int j=0; j<4; j++) //1 for (int k=0; k<4; k++) //2 for (int l=0; l<4; l++) //3 for (int m=0; m<4; m++) //4 for (int n=0; n<4; n++) //5 for (int p=0; p<4; p++) //6 for (int q=0; q<4; q++) //7 { currentGame.push_back(i); currentGame.push_back(j); currentGame.push_back(k); currentGame.push_back(l); currentGame.push_back(m); currentGame.push_back(n); currentGame.push_back(p); currentGame.push_back(q); //cout << "Given Game" << endl; //printGame(¤tGame); headsUp(¤tGame); //cout << "Post Heads Up" << endl; //printGame(¤tGame); //put the index "score" of the current game into a temporary variable for easy future reference tempNumber=((currentGame.at(0)+currentGame.at(4)*4)+ (currentGame.at(2)+currentGame.at(5)*4)*16)+ ((currentGame.at(1)+currentGame.at(6)*4)+ (currentGame.at(3)+currentGame.at(7)*4)*16)*256; int rowPayType = 0; //all the same if (count(currentGame.begin(), currentGame.begin() + 4, currentGame.at(0))==4) rowPayType = 1; else //three the same if (count(currentGame.begin(), currentGame.begin() + 4, currentGame.at(0))==3 || count(currentGame.begin(), currentGame.begin() + 4, currentGame.at(1))==3) rowPayType = 2; else //two sets of two the same if (count(currentGame.begin(), currentGame.begin() + 4, currentGame.at(0))==2 && count(currentGame.begin(), currentGame.begin() + 4, currentGame.at(1))==2 && count(currentGame.begin(), currentGame.begin() + 4, currentGame.at(2))==2) rowPayType = 3; else //nothing the same if (count(currentGame.begin(), currentGame.begin() + 4, currentGame.at(0))==1 && count(currentGame.begin(), currentGame.begin() + 4, currentGame.at(1))==1 && count(currentGame.begin(), currentGame.begin() + 4, currentGame.at(2))==1) rowPayType = 5; else //one payoff pair the same rowPayType = 4; int colPayType = 0; if (count(currentGame.begin() + 4, currentGame.end(), currentGame.at(4))==4) colPayType = 1; else if (count(currentGame.begin() + 4, currentGame.end(), currentGame.at(4))==3 || count(currentGame.begin() + 4, currentGame.end(), currentGame.at(5))==3) colPayType = 2; else if (count(currentGame.begin() + 4, currentGame.end(), currentGame.at(4))==2 && count(currentGame.begin() + 4, currentGame.end(), currentGame.at(5))==2 && count(currentGame.begin() + 4, currentGame.end(), currentGame.at(6))==2) colPayType = 3; else if (count(currentGame.begin() + 4, currentGame.end(), currentGame.at(4))==1 && count(currentGame.begin() + 4, currentGame.end(), currentGame.at(5))==1 && count(currentGame.begin() + 4, currentGame.end(), currentGame.at(6))==1) colPayType = 5; else colPayType = 4; if (count(gameNumbers.begin(), gameNumbers.end(), tempNumber)==0) { gameNumbers.push_back(tempNumber); numberCount++; pureOrdinalProb.push_back(1); for (int r=0; r<8; r++) games.push_back(currentGame.at(r)); gameTypes.push_back(gameTyper[rowPayType-1][colPayType-1]); /* //a simple printing feature to test if all the proper games are being collected and to track down discrepancies if (rowPayType==2 && colPayType==2) { cout << "RPT " << rowPayType << " CPT " << colPayType << endl; cout << gameNumbers.back() << endl; printGame(¤tGame); } */ gameTypeCount[rowPayType-1][colPayType-1]++; //cout << tempNumber << "," << complimentTest(¤tGame) << endl; //used to help identify symmetric games sqPosCounter(¤tGame, &sqPositionCount, &sqPositions); /* Error checking tool */ for (int x=0; x<(int)sqPositions.back().size(); x++) cout << sqPositions.back().at(x) << ", "; cout << endl << endl; } else { int r=0; //cout << tempNumber << " " << gameNumbers.at(r) << " " << r << endl; while (tempNumber!=gameNumbers.at(r)) { //cout << tempNumber << " " << gameNumbers.at(r) << " " << r << endl; r++; } pureOrdinalProb.at(r)++; //Adds one to the count of the number of ways this game can show up copyCount++; //cout << copyCount << endl; } tempNumber=0; currentGame.clear(); } /* This next block of code is necessary to determine the frequency of each game showing up * when each payoff is generated randomly with one of ten possible values. */ /**/ //#pragma omp parallel for firstprivate(currentGame, tempNumber) for (int i=0; i<10; i++) //0 for (int j=0; j<10; j++) //1 { cout << j << endl ; for (int k=0; k<10; k++) //2 for (int l=0; l<10; l++) //3 for (int m=0; m<10; m++) //4 for (int n=0; n<10; n++) //5 for (int p=0; p<10; p++) //6 for (int q=0; q<10; q++) //7 { currentGame.push_back(i); currentGame.push_back(j); currentGame.push_back(k); currentGame.push_back(l); currentGame.push_back(m); currentGame.push_back(n); currentGame.push_back(p); currentGame.push_back(q); //cout << "Given Game" << endl; //printGame(¤tGame); headsUp(¤tGame); //cout << "Post Heads Up" << endl; //printGame(¤tGame); //put the index "score" of the current game into a temporary variable for easy future reference tempNumber=((currentGame.at(0)+currentGame.at(4)*4)+ (currentGame.at(2)+currentGame.at(5)*4)*16)+ ((currentGame.at(1)+currentGame.at(6)*4)+ (currentGame.at(3)+currentGame.at(7)*4)*16)*256; int r=0; //cout << tempNumber << " " << gameNumbers.at(r) << " " << r << endl; while (tempNumber!=gameNumbers.at(r)) r++; #pragma omp critical (tenCardinalProb_update) { tenCardinalProb.at(r)++; } tempNumber=0; currentGame.clear(); } } /**/ cout << "There are " << numberCount << " different numbers." << endl << endl; cout << copyCount << " were duplicates and discarded." << endl << endl; cout << copyCount + numberCount << " total cases." << endl << endl; outFile1 << "There are " << numberCount << " different numbers." << endl << endl; outFile1 << copyCount << " were duplicates were discarded." << endl << endl; outFile1 << copyCount + numberCount << " total cases." << endl << endl; tempNumber=0; for (int i=0; i<(int)pureOrdinalProb.size(); i++) tempNumber=tempNumber+pureOrdinalProb.at(i); cout << "There are " << tempNumber << " cases included in the ordinal probability." << endl << endl; outFile1 << "There are " << tempNumber << " cases included in the ordinal probability." << endl << endl; tempNumber=0; for (int i=0; i<(int)tenCardinalProb.size(); i++) tempNumber=tempNumber+tenCardinalProb.at(i); cout << "There are " << tempNumber << " cases included in the cardinal[10] probability." << endl << endl; outFile1 << "There are " << tempNumber << " cases included in the cardinal[10] probability." << endl << endl; for (int i=0; i<5; i++) for (int j=0; j<5; j++) { cout << "Row Type: " << i << " Column Type: " << j << " Count: " << gameTypeCount[i][j] << endl; outFile1 << "Row Type: " << i << " Column Type: " << j << " Count: " << gameTypeCount[i][j] << endl; } //sort(gameNumbers.begin(), gameNumbers.end()); for (int i=0; i indexGame; for (int i=0; i<(int)gameNumbers.size(); i++) { for (int j=0; j<8; j++) currentGame.push_back(games.at((8*i)+j)); indexGame.push_back(gameIndexer(¤tGame, true, &indexNumbersNC)); indexGame.push_back(gameIndexer(¤tGame, false, &indexNumbersNC)); for (int j=0; j<2; j++) for (int k=0; k<3; k++) for (int l=0; l<3; l++) indexGame.push_back(indexGame.at(j)+k*1413+l*4239); sort(indexGame.begin(), indexGame.end()); //See page 111 of "C++ Standard Library" for an explanation of the next two lines vector::iterator end=unique(indexGame.begin(), indexGame.end()); indexGame.erase(end, indexGame.end()); cout << i << " "; outFile1 << i << " "; for (int j=0; j<(int)indexGame.size(); j++) { cout << indexGame.at(j) << " "; outFile1 << indexGame.at(j) << " "; } cout << "=> " << (float)tenCardinalProb.at(i)/(float)(100000000) << endl; outFile1 << "=> " << (float)tenCardinalProb.at(i)/(float)(100000000) << endl; indexGame.clear(); currentGame.clear(); } cout << endl << endl; outFile1 << endl << endl; vector< vector > allEqualPerspectives; vector equalPerspectives; for (int i=0; i<(int)gameNumbers.size(); i++) { for (int j=0; j<3; j++) for (int k=0; k<3; k++) equalPerspectives.push_back(pos2bit(i)+j*4096+k*12288); sort(equalPerspectives.begin(), equalPerspectives.end()); allEqualPerspectives.push_back(equalPerspectives); equalPerspectives.clear(); } for (int i=0; i<(int)gameNumbers.size(); i++) { for(int j=0; j<(int)allEqualPerspectives.at(i).size(); j++) cout << allEqualPerspectives.at(i).at(j) << " " ; double sqCardProb=0; for (int j=0; j<(int)sqPositions.size(); j++) for (int k=0; k<(int)sqPositions.at(j).size(); k++) if (sqPositions.at(j).at(k)==i) sqCardProb=sqCardProb + (double)tenCardinalProb.at(j); cout << " => " << sqCardProb/(double)(100000000)/8.0 << endl; outFile1 << " => " << sqCardProb/(double)(100000000)/8.0 << endl; } outTexGames(&gameNumbers, &games, &gameTypes, &pureOrdinalProb, &tenCardinalProb, &sqPositionCount, &sqPositions, &allEqualPerspectives, outFile0); outSQPositions(&pureOrdinalProb, &tenCardinalProb, &sqPositions, &sqPositionCount, outFile2); } //Converts any 2x2 game to proper ordinal form void headsUp(vector* currentGamePtr) { vector vPays(*currentGamePtr); //cout << "Pre Ordinality" << endl; //printGame(&vPays); //Game is converted to its minimum ordinal form. First for Row and then for Column. vector ordPays; for (int h=0; h<2; h++) //h=0 ROW, h=1 COLUMN { for (int i=0; i<4; i++) //Looks at four given outcome associated payoffs for the player (row/column) if (count(ordPays.begin(), ordPays.end(), vPays.at(i+(h*4)))==0) //if ordPays doesn't have the next value already then add it ordPays.push_back(vPays.at(i+(h*4))); sort(ordPays.begin(), ordPays.end()); //Orders the payoffs the player is currently receiving from smallest to largest for (int i=0; i permValues; permValues.push_back(((vPays.at(0)+vPays.at(4)*4)+ (vPays.at(2)+vPays.at(5)*4)*16)+ ((vPays.at(1)+vPays.at(6)*4)+ (vPays.at(3)+vPays.at(7)*4)*16)*256); permValues.push_back(((vPays.at(1)+vPays.at(6)*4)+ (vPays.at(3)+vPays.at(7)*4)*16)+ ((vPays.at(0)+vPays.at(4)*4)+ (vPays.at(2)+vPays.at(5)*4)*16)*256); permValues.push_back(((vPays.at(2)+vPays.at(5)*4)+ (vPays.at(0)+vPays.at(4)*4)*16)+ ((vPays.at(3)+vPays.at(7)*4)+ (vPays.at(1)+vPays.at(6)*4)*16)*256); permValues.push_back(((vPays.at(3)+vPays.at(7)*4)+ (vPays.at(1)+vPays.at(6)*4)*16)+ ((vPays.at(2)+vPays.at(5)*4)+ (vPays.at(0)+vPays.at(4)*4)*16)*256); /*Uncommenting returns to base 726 games vs. extended perspective of non-symmetric games*/ permValues.push_back(((vPays.at(4)+vPays.at(0)*4)+ (vPays.at(6)+vPays.at(1)*4)*16)+ ((vPays.at(5)+vPays.at(2)*4)+ (vPays.at(7)+vPays.at(3)*4)*16)*256); permValues.push_back(((vPays.at(5)+vPays.at(2)*4)+ (vPays.at(7)+vPays.at(3)*4)*16)+ ((vPays.at(4)+vPays.at(0)*4)+ (vPays.at(6)+vPays.at(1)*4)*16)*256); permValues.push_back(((vPays.at(6)+vPays.at(1)*4)+ (vPays.at(4)+vPays.at(0)*4)*16)+ ((vPays.at(7)+vPays.at(3)*4)+ (vPays.at(5)+vPays.at(2)*4)*16)*256); permValues.push_back(((vPays.at(7)+vPays.at(3)*4)+ (vPays.at(5)+vPays.at(2)*4)*16)+ ((vPays.at(6)+vPays.at(1)*4)+ (vPays.at(4)+vPays.at(0)*4)*16)*256); /**/ int minMut=0; int minMutLoc=0; minMut=*(min_element(permValues.begin(), permValues.end())); while (minMut!=permValues.at(minMutLoc)) minMutLoc++; switch (minMutLoc) { case 0: break; case 1: swapRows(&vPays); break; case 2: swapCols(&vPays); break; case 3: swapDias(&vPays); break; case 4: swapPlayers(&vPays); break; case 5: swapPlayers(&vPays); swapRows(&vPays); break; case 6: swapPlayers(&vPays); swapCols(&vPays); break; case 7: swapPlayers(&vPays); swapDias(&vPays); break; default: cout << "ERROR " << minMutLoc << endl; break; } currentGamePtr->clear(); *currentGamePtr = vPays; } void sqPosCounter(vector* currentGamePtr, vector* sqPositionCountPtr, vector >* sqPositionsPtr) { int pays[8]; bitset<12> bw; int gameLoadCount=0; vector sqPositions; for (int i=0; i<8; i++) pays[i]=currentGamePtr->at(i); //Determine better/worse unilateral/mutual switch values //At the same time, collect status quo payoffs //This information is used by agents to determine what kind of //game they are playing when agent::play is called in the SR6 simulation series for (int x=0; x<2; x++) for (int y=0; y<2; y++) { if (x==1) //TOP if (y==1) //TOP-LEFT { //Does row do better or worse if they switch and column stays? if (pays[0]pays[1]) //worse bw.set(1); //Does row do better or worse if column unilaterally switches? if (pays[0]pays[2]) //worse bw.set(3); //Does row do better or worse if they both switch? if (pays[0]pays[3]) //worse bw.set(5); //Does column do better or worse if they switch and row stays? if (pays[4]pays[5]) //worse bw.set(7); //Does column do better or worse if row switches and they stay? if (pays[4]pays[6]) //worse bw.set(9); //Does column do better or worse if they both switch? if (pays[4]pays[7]) //worse bw.set(11); } else //TOP-RIGHT { //Does row do better or worse if they switch and column stays? if (pays[2]pays[3]) //worse bw.set(1); //Does row do better or worse if column unilaterally switches? if (pays[2]pays[0]) //worse bw.set(3); //Does row do better or worse if they both switch? if (pays[2]pays[1]) //worse bw.set(5); //Does column do better or worse if they switch and row stays? if (pays[5]pays[4]) //worse bw.set(7); //Does column do better or worse if row switches and they stay? if (pays[5]pays[7]) //worse bw.set(9); //Does column do better or worse if they both switch? if (pays[5]pays[6]) //worse bw.set(11); } else //BOTTOM if (y==1) //BOTTOM-LEFT { //Does row do better or worse if they switch and column stays? if (pays[1]pays[0]) //worse bw.set(1); //Does row do better or worse if column unilaterally switches? if (pays[1]pays[3]) //worse bw.set(3); //Does row do better or worse if they both switch? if (pays[1]pays[2]) //worse bw.set(5); //Does column do better or worse if they switch and row stays? if (pays[6]pays[7]) //worse bw.set(7); //Does column do better or worse if row switches and they stay? if (pays[6]pays[4]) //worse bw.set(9); //Does column do better or worse if they both switch? if (pays[6]pays[5]) //worse bw.set(11); } else //BOTTOM-RIGHT { //Does row do better or worse if they switch and column stays? if (pays[3]pays[2]) //worse bw.set(1); //Does row do better or worse if column unilaterally switches? if (pays[3]pays[1]) //worse bw.set(3); //Does row do better or worse if they both switch? if (pays[3]pays[0]) //worse bw.set(5); //Does column do better or worse if they switch and row stays? if (pays[7]pays[6]) //worse bw.set(7); //Does column do better or worse if row switches and they stay? if (pays[7]pays[5]) //worse bw.set(9); //Does column do better or worse if they both switch? if (pays[7]pays[4]) //worse bw.set(11); } //ASK GAME WHAT THE BITSETS ARE FOR EACH PERSPECTIVE for (int z=0; z<2; z++) { int a, b, c, d, e, f, g, h, i, j, k, l=-1; if (z==0) //when player is "row" { a=bw[0]; //IF COLUMN stays ROW does BETTER switching b=bw[1]; //IF COLUMN stays ROW does WORSE switching c=bw[2]; //IF COLUMN switches ROW does BETTER staying d=bw[3]; //IF COLUMN switches ROW does WORSE staying e=bw[4]; //IF BOTH switch ROW does BETTER f=bw[5]; //IF BOTH switch ROW does WORSE g=bw[6]; //IF ROW stays COLUMN does BETTER switching h=bw[7]; //IF ROW stays COLUMN does WORSE switching i=bw[8]; //IF ROW switches COLUMN does BETTER staying j=bw[9]; //IF ROW switches COLUMN does WORSE staying k=bw[10]; //IF BOTH switch COLUMN does BETTER l=bw[11]; //IF BOTH switch COLUMN does WORSE } else //when player is "column" { g=bw[0]; h=bw[1]; i=bw[2]; j=bw[3]; k=bw[4]; l=bw[5]; a=bw[6]; b=bw[7]; c=bw[8]; d=bw[9]; e=bw[10]; f=bw[11]; } int choiceIndex=-1; choiceIndex = l+k*2+j*4+i*8+h*16+g*32+f*64+e*128+d*256+c*512+b*1024+a*2048; choiceIndex = bit2pos(choiceIndex); sqPositionCountPtr->at(choiceIndex)++; sqPositions.push_back(choiceIndex); gameLoadCount++; if (gameLoadCount>8) gameLoadCount=gameLoadCount; } //closes the z for-loop bw.reset(); } //closes the x and y for-loops sort(sqPositions.begin(), sqPositions.end()); sqPositionsPtr->push_back(sqPositions); /* Error Checking Tool*/ cout << "SQ ID#s in Game Number: " << sqPositionsPtr->size() << endl; for (int x=0; x<(int)sqPositions.size(); x++) cout << sqPositions.at(x) << ", "; cout << endl; for (int x=0; x<(int)sqPositionsPtr->back().size(); x++) cout << sqPositionsPtr->back().at(x) << ", "; cout << endl; /**/ sqPositions.clear(); } void swapDias(vector* vPaysPtr) { swap (vPaysPtr->at(0), vPaysPtr->at(3)); swap (vPaysPtr->at(1), vPaysPtr->at(2)); swap (vPaysPtr->at(4), vPaysPtr->at(7)); swap (vPaysPtr->at(5), vPaysPtr->at(6)); } void swapCols(vector* vPaysPtr) { swap (vPaysPtr->at(0), vPaysPtr->at(2)); swap (vPaysPtr->at(1), vPaysPtr->at(3)); swap (vPaysPtr->at(4), vPaysPtr->at(5)); swap (vPaysPtr->at(6), vPaysPtr->at(7)); } void swapRows(vector* vPaysPtr) { swap (vPaysPtr->at(0), vPaysPtr->at(1)); swap (vPaysPtr->at(2), vPaysPtr->at(3)); swap (vPaysPtr->at(4), vPaysPtr->at(6)); swap (vPaysPtr->at(5), vPaysPtr->at(7)); } void swapPlayers(vector* vPaysPtr) { swap_ranges (vPaysPtr->begin(), vPaysPtr->begin() + 4, vPaysPtr->begin() + 4); } void printGame(vector* vPaysPtr) { cout << vPaysPtr->at(0) << " " << vPaysPtr->at(4) << " " << "|" << " " << vPaysPtr->at(2) << " " << vPaysPtr->at(5) << " " << endl; cout << "----------------" << endl; cout << vPaysPtr->at(1) << " " << vPaysPtr->at(6) << " " << "|" << " " << vPaysPtr->at(3) << " " << vPaysPtr->at(7) << " " << endl; cout << endl << endl; } void outTexGames(vector* gameNumbersPtr, vector* gamesPtr, vector* gameTypesPtr, vector* pureOrdinalProbPtr, vector* tenCardinalProbPtr, vector* sqPositionCountPtr, vector >* sqPositionsPtr, vector >* allEqualPerspectivesPtr, ostream& outFile0) { int printCount=0; int maxGamesPerLine=3; outFile0 << "\\documentclass[12pt, letterpaper, draft, oneside]{book}" << endl; outFile0 << "\\usepackage[left=0.5in, right=1in, top =1in, bottom=1in]{geometry}" << endl; outFile0 << "\\pagestyle{headings}" << endl; outFile0 << "\\begin{document}" << endl << endl; outFile0 << "\\appendix" << endl; outFile0 << "\\chapter{Taxonomy of Games}" << endl; for (int j=1; j<16; j++) { outFile0 << endl << "\\section{Games of Type " << j << "} " << endl << endl; int typeCount=0; for (int i=0; i<(int)gameNumbersPtr->size(); i++) if (gameTypesPtr->at(i)==j) typeCount++; outFile0 << "Total Count of Type: " << typeCount << endl << endl ; outFile0 << "\\vspace{5 mm}" << endl << endl; outFile0 << "\\begin{center}" << endl; outFile0 << "\\hspace*{\\fill}" << endl; for (int i=0; i<(int)gameNumbersPtr->size(); i++) { if (gameTypesPtr->at(i)==j) { outFile0 << "\\parbox{.31\\linewidth}" << endl; outFile0 << "{" << endl; outFile0 << "Game " << i+1 << endl; outFile0 << "\\begin{center}" << endl; outFile0 << "\\begin{tabular}{|c|c|}" << endl; outFile0 << "\\hline" << endl; outFile0 << gamesPtr->at(i*8) << ", " << gamesPtr->at(i*8+4) << " & " << gamesPtr->at(i*8+2) << ", " << gamesPtr->at(i*8+5) << " \\\\" << endl; outFile0 << "\\hline" << endl; outFile0 << gamesPtr->at(i*8+1) << ", " << gamesPtr->at(i*8+6) << " & " << gamesPtr->at(i*8+3) << ", " << gamesPtr->at(i*8+7) << " \\\\" << endl; outFile0 << "\\hline" << endl; outFile0 << "\\end{tabular}" << endl; outFile0 << "\\par Ord\\% "<< pureOrdinalProbPtr->at(i) << "$\\rightarrow$" << (float)pureOrdinalProbPtr->at(i)/(float)(65536) << endl; outFile0 << "\\par Card\\% " << tenCardinalProbPtr->at(i) << "$\\rightarrow$" << (float)tenCardinalProbPtr->at(i)/(float)(100000000) << endl; outFile0 << "\\vspace{3 mm}" << endl << endl; int commaswitch = 0; for (int k=0; k<(int)sqPositionsPtr->at(i).size(); k++) { if (commaswitch == 1) outFile0 << ", "; outFile0 << sqPositionsPtr->at(i).at(k)+1; commaswitch=1; } outFile0 << endl << endl; outFile0 << "\\end{center}" << endl; outFile0 << "}" << endl; outFile0 << "\\hspace*{\\fill}" << endl; if ( (printCount+1)%maxGamesPerLine==0.0) outFile0 << "\\vspace{5 mm}" << endl << endl; printCount++; } } if ( (printCount+1)%maxGamesPerLine!=0.0) outFile0 << "\\vspace{5 mm}" << endl << endl; outFile0 << "\\end{center}" << endl; printCount=0; } for (int i=0; i<(int)sqPositionsPtr->size(); i++) { outFile0 << "\\begin{tabular}{|p{.22\\linewidth}|p{.38\\linewidth}|p{.29\\linewidth}|}" << endl; outFile0 << "\\hline" << endl; outFile0 << i+1 << endl; double sqOrdProb=0; double sqCardProb=0; for (int j=0; j<(int)sqPositionsPtr->size(); j++) for (int k=0; k<(int)sqPositionsPtr->at(j).size(); k++) if (sqPositionsPtr->at(j).at(k)==i) sqOrdProb = sqOrdProb + (double)pureOrdinalProbPtr->at(j); for (int j=0; j<(int)sqPositionsPtr->size(); j++) for (int k=0; k<(int)sqPositionsPtr->at(j).size(); k++) if (sqPositionsPtr->at(j).at(k)==i) sqCardProb = sqCardProb + (double)tenCardinalProbPtr->at(j); outFile0 << "\\par Ord\\% $\\rightarrow$" << sqOrdProb/(double)(65536)/8.0 << endl; outFile0 << "\\par Card\\% $\\rightarrow$" << sqCardProb/(double)(100000000)/8.0 << endl; outFile0 << " & "; for(int j=0; j<(int)allEqualPerspectivesPtr->at(i).size(); j++) outFile0 << allEqualPerspectivesPtr->at(i).at(j) << " " ; outFile0 << " & "; for (int j=0; j<(int)sqPositionsPtr->size(); j++) for (int k=0; k<(int)sqPositionsPtr->at(j).size(); k++) if (sqPositionsPtr->at(j).at(k)==i) outFile0 << j << " "; outFile0 << " \\\\" << endl; outFile0 << "\\hline" << endl; outFile0 << "\\end{tabular}" << endl << endl; } outFile0 << endl << endl << "\\end{document}"; } void outSQPositions(vector* pureOrdinalProbPtr, vector* tenCardinalProbPtr, vector >* sqPositionsPtr, vector* sqPositionsCountPtr, ostream& outFile2) { int printCount=0; int maxGamesPerLine=3; int sqPos2Bit=0; int sqPays[6]={0}; double probCountCard=0.0; double probCountOrd=0.0; outFile2 << "\\documentclass[12pt, letterpaper, draft, oneside]{book}" << endl; outFile2 << "\\usepackage[left=0.5in, right=1in, top =1in, bottom=1in]{geometry}" << endl; outFile2 << "\\pagestyle{headings}" << endl; outFile2 << "\\begin{document}" << endl << endl; outFile2 << "\\appendix" << endl; outFile2 << "\\chapter{Status Quo Position Taxonomy}" << endl; for (int i=0; i<729; i++) { sqPos2Bit=pos2bit(i); for(int n=11; n>=0; n--) { if(sqPos2Bit>=pow(2.0,n)) { sqPos2Bit=sqPos2Bit - pow(2.0,n); switch (n) { case 0: sqPays[5]=-1; break; case 1: sqPays[5]=1; break; case 2: sqPays[1]=-1; break; case 3: sqPays[1]=1; break; case 4: sqPays[3]=-1; break; case 5: sqPays[3]=1; break; case 6: sqPays[4]=-1; break; case 7: sqPays[4]=1; break; case 8: sqPays[2]=-1; break; case 9: sqPays[2]=1; break; case 10: sqPays[0]=-1; break; case 11: sqPays[0]=1; break; default: cout << "ERROR"; break; } } } outFile2 << "\\parbox{.31\\linewidth}" << endl; outFile2 << "{" << endl; outFile2 << "SQ Position " << i+1 << endl; outFile2 << "\\begin{center}" << endl; outFile2 << "\\begin{tabular}{|c|c|}" << endl; outFile2 << "\\hline" << endl; outFile2 << "\\underline{\\textbf{0}}" << ", " << "\\textbf{0}" << " & " << sqPays[2] << ", " << sqPays[3] << " \\\\" << endl; outFile2 << "\\hline" << endl; outFile2 << sqPays[0] << ", " << sqPays[1] << " & " << sqPays[4] << ", " << sqPays[5] << " \\\\" << endl; outFile2 << "\\hline" << endl; outFile2 << "\\end{tabular}" << endl << endl; outFile2 << "\\vspace{3 mm}" << endl << endl; double sqOrdProb=0; double sqCardProb=0; for (int j=0; j<(int)sqPositionsPtr->size(); j++) for (int k=0; k<(int)sqPositionsPtr->at(j).size(); k++) if (sqPositionsPtr->at(j).at(k)==i) { sqOrdProb = sqOrdProb + (double)pureOrdinalProbPtr->at(j); probCountOrd = probCountOrd + sqOrdProb; } for (int j=0; j<(int)sqPositionsPtr->size(); j++) for (int k=0; k<(int)sqPositionsPtr->at(j).size(); k++) if (sqPositionsPtr->at(j).at(k)==i) { sqCardProb = sqCardProb + (double)tenCardinalProbPtr->at(j); probCountCard = probCountCard + sqCardProb; } outFile2 << "\\par Ord\\% " << sqOrdProb << "$\\rightarrow$" << sqOrdProb/(double)(65536.0)/8.0 << endl; outFile2 << "\\par Card\\% " << sqCardProb << "$\\rightarrow$" << sqCardProb/(double)(100000000.0)/8.0 << endl << endl; outFile2 << sqPositionsCountPtr->at(i) << endl << endl << "\\vspace{3 mm}" << endl << endl; int commaswitch = 0; for (int j=0; j<(int)sqPositionsPtr->size(); j++) for (int k=0; k<(int)sqPositionsPtr->at(j).size(); k++) if (sqPositionsPtr->at(j).at(k)==i) { if (commaswitch == 1) outFile2 << ", "; outFile2 << j+1; commaswitch=1; } outFile2 << endl << endl; outFile2 << "\\end{center}" << endl; outFile2 << "}" << endl; outFile2 << "\\hspace*{\\fill}" << endl; if ( (printCount+1)%maxGamesPerLine==0.0) outFile2 << "\\vspace{5 mm}" << endl << endl; printCount++; for(int j=0; j<6; j++) sqPays[j]=0; } cout << "Sum of Ordinal Probabilities for SQs: " << probCountOrd << endl; cout << "Sum of Cardinal Probabilities for SQs: " << probCountCard << endl; outFile2 << endl << endl << "\\end{document}"; } int gameIndexer(vector* currentGamePtr, const bool rowSet, vector* indexNumbersNCPtr) { vector vPays(*currentGamePtr); int minMut=0; int gameNum=0; vector permValues; if (rowSet==true) { permValues.push_back(((vPays.at(0)+vPays.at(4)*4)+ (vPays.at(2)+vPays.at(5)*4)*16)+ ((vPays.at(1)+vPays.at(6)*4)+ (vPays.at(3)+vPays.at(7)*4)*16)*256); permValues.push_back(((vPays.at(1)+vPays.at(6)*4)+ (vPays.at(3)+vPays.at(7)*4)*16)+ ((vPays.at(0)+vPays.at(4)*4)+ (vPays.at(2)+vPays.at(5)*4)*16)*256); permValues.push_back(((vPays.at(2)+vPays.at(5)*4)+ (vPays.at(0)+vPays.at(4)*4)*16)+ ((vPays.at(3)+vPays.at(7)*4)+ (vPays.at(1)+vPays.at(6)*4)*16)*256); permValues.push_back(((vPays.at(3)+vPays.at(7)*4)+ (vPays.at(1)+vPays.at(6)*4)*16)+ ((vPays.at(2)+vPays.at(5)*4)+ (vPays.at(0)+vPays.at(4)*4)*16)*256); minMut=*(min_element(permValues.begin(), permValues.end())); } else { permValues.push_back(((vPays.at(4)+vPays.at(0)*4)+ (vPays.at(6)+vPays.at(1)*4)*16)+ ((vPays.at(5)+vPays.at(2)*4)+ (vPays.at(7)+vPays.at(3)*4)*16)*256); permValues.push_back(((vPays.at(5)+vPays.at(2)*4)+ (vPays.at(7)+vPays.at(3)*4)*16)+ ((vPays.at(4)+vPays.at(0)*4)+ (vPays.at(6)+vPays.at(1)*4)*16)*256); permValues.push_back(((vPays.at(6)+vPays.at(1)*4)+ (vPays.at(4)+vPays.at(0)*4)*16)+ ((vPays.at(7)+vPays.at(3)*4)+ (vPays.at(5)+vPays.at(2)*4)*16)*256); permValues.push_back(((vPays.at(7)+vPays.at(3)*4)+ (vPays.at(5)+vPays.at(2)*4)*16)+ ((vPays.at(6)+vPays.at(1)*4)+ (vPays.at(4)+vPays.at(0)*4)*16)*256); minMut=*(min_element(permValues.begin(), permValues.end())); } while (minMut!=indexNumbersNCPtr->at(gameNum)) gameNum++;; return gameNum; } int complimentTest(vector* currentGamePtr) { //take given game value and turn it back into vector vPays(*currentGamePtr); //cout << "Pre Ordinality" << endl; //printGame(&vPays); //Game is converted to its minimum ordinal form. First for Row and then for Column. vector ordPays; vector permValues; permValues.push_back(((vPays.at(4)+vPays.at(0)*4)+ (vPays.at(6)+vPays.at(1)*4)*16)+ ((vPays.at(5)+vPays.at(2)*4)+ (vPays.at(7)+vPays.at(3)*4)*16)*256); permValues.push_back(((vPays.at(5)+vPays.at(2)*4)+ (vPays.at(7)+vPays.at(3)*4)*16)+ ((vPays.at(4)+vPays.at(0)*4)+ (vPays.at(6)+vPays.at(1)*4)*16)*256); permValues.push_back(((vPays.at(6)+vPays.at(1)*4)+ (vPays.at(4)+vPays.at(0)*4)*16)+ ((vPays.at(7)+vPays.at(3)*4)+ (vPays.at(5)+vPays.at(2)*4)*16)*256); permValues.push_back(((vPays.at(7)+vPays.at(3)*4)+ (vPays.at(5)+vPays.at(2)*4)*16)+ ((vPays.at(6)+vPays.at(1)*4)+ (vPays.at(4)+vPays.at(0)*4)*16)*256); int minMut=0; minMut=*(min_element(permValues.begin(), permValues.end())); return minMut; } int bit2pos(const int bit) { int q1=0, q2=0, q3=0, q4=0, q5=0, q6=0; q1=bit/4; q2=bit/16; q3=bit/64; q4=bit/256; q5=bit/1024; q6=bit/4096; return bit-q1-q2*3-q3*9-q4*27-q5*81-q6*243; } int pos2bit (const int position) { int q1=0, q2=0, q3=0, q4=0, q5=0, q6=0; q1=position/3; q2=position/9; q3=position/27; q4=position/81; q5=position/243; q6=position/729; return position+q1+q2*4+q3*16+q4*64+q5*256+q6*1024; } void loadIndexNumbersNC(vector* indexNumbersNCPtr) { //Open input file with ifstream constructor ifstream gameFile( "indexNumbersNC.dat", ios::in); //exit program if input file failure if (!gameFile) { cerr << "INDEXNUMBERSNC.DAT COULD NOT BE OPENED" << endl; exit (1); } //end if int gn=-1; while (gameFile >> gn) indexNumbersNCPtr->push_back(gn); }