Testing13/prisoner.cpp
// I think this function should be run in parallel.
// I've used "pass by pointer" instead of "pass by reference" because I thik that's what the kernel function
// calls used.
// Input: pOne and pTwo
// Output: pOneScoreChange and pTwoScoreChange
// was void tournament(player& pOne, player& pTwo, unsigned int& pOneScoreChange, unsigned int& pTwoScoreChange)
I think this function should be run in parallel.
I've used "pass by pointer" instead of "pass by reference" because I thik that's what the kernel function
calls used.
Input: pOne and pTwo
Output: pOneScoreChange and pTwoScoreChange
was void tournament(player& pOne, player& pTwo, unsigned int& pOneScoreChange, unsigned int& pTwoScoreChange)
I think this function should be run in parallel . I ' ve used " pass by pointer " instead of " pass by reference " because I thik that ' s what the kernel function calls used . Input : pOne and pTwo Output : pOneScoreChange and pTwoScoreChange was void tournament ( player& pOne player& pTwo unsigned int& pOneScoreChange unsigned int& pTwoScoreChange )
void tournament(player* pOne, player* pTwo, unsigned int* pOneScoreChange, unsigned int* pTwoScoreChange)
{
	const int payoff[2][2] = {{3,0},{5,1}};
	int play_counter;
	unsigned int pOneIndex;
	unsigned int pTwoIndex;
	unsigned int pOneMask;
	unsigned int pTwoMask;;
	unsigned int pOneMove;
	unsigned int pTwoMove;
	unsigned int past_temp;
	(*pOneScoreChange) = 0;
	(*pTwoScoreChange) = 0;
	pOneIndex = pOne->past_behavior;
	pTwoIndex = pTwo->past_behavior;
	for(play_counter=0;play_counter<TOURNAMENT_LENGTH;play_counter++){
	pOneMask = 0x00000001;
	pTwoMask = 0x00000001;
	if(pOneIndex < 32){
		pOneMask = pOneMask << pOneIndex;
		pOneMove = pOneMask & (pOne->strategy_first);
	} else {
		pOneMask = pOneMask << (pOneIndex - 32);
		pOneMove = pOneMask & (pOne->strategy_second);
	}
	if(pOneMove) pOneMove = 1;
	if(pTwoIndex < 32){
		pTwoMask = pTwoMask << pTwoIndex;
		pTwoMove = pTwoMask & (pTwo->strategy_first);
	} else {
		pTwoMask = pTwoMask << (pTwoIndex - 32);
		pTwoMove = pTwoMask & (pTwo->strategy_second);
	}
	if(pTwoMove) pTwoMove = 1;
	(*pOneScoreChange) += payoff[pOneMove][pTwoMove];
	(*pTwoScoreChange) += payoff[pTwoMove][pOneMove];
	pOneIndex = pOneIndex & 0x0000001B;
	pOneIndex = pOneIndex << 1;
	if(pOneMove) pOneIndex = pOneIndex | 0x00000001;
	if(pTwoMove) pOneIndex = pOneIndex | 0x00000008;
	pTwoIndex = pTwoIndex & 0x0000001B;
	pTwoIndex = pTwoIndex << 1;
	if(pTwoMove) pTwoIndex = pTwoIndex | 0x00000001;
	if(pOneMove) pTwoIndex = pTwoIndex | 0x00000008;
	}
}
void tournament ( player * pOne , player * pTwo , unsigned int * pOneScoreChange , unsigned int * pTwoScoreChange ) { const int payoff [ 2 ] [ 2 ] = { { 3 , 0 } , { 5 , 1 } } ; int play_counter ; unsigned int pOneIndex ; unsigned int pTwoIndex ; unsigned int pOneMask ; unsigned int pTwoMask ; ; unsigned int pOneMove ; unsigned int pTwoMove ; unsigned int past_temp ; ( * pOneScoreChange ) = 0 ; ( * pTwoScoreChange ) = 0 ; pOneIndex = pOne -> past_behavior ; pTwoIndex = pTwo -> past_behavior ; for ( play_counter = 0 ; play_counter < TOURNAMENT_LENGTH ; play_counter ++ ) { pOneMask = 0x00000001 ; pTwoMask = 0x00000001 ; if ( pOneIndex < 32 ) { pOneMask = pOneMask << pOneIndex ; pOneMove = pOneMask & ( pOne -> strategy_first ) ; } else { pOneMask = pOneMask << ( pOneIndex - 32 ) ; pOneMove = pOneMask & ( pOne -> strategy_second ) ; } if ( pOneMove ) pOneMove = 1 ; if ( pTwoIndex < 32 ) { pTwoMask = pTwoMask << pTwoIndex ; pTwoMove = pTwoMask & ( pTwo -> strategy_first ) ; } else { pTwoMask = pTwoMask << ( pTwoIndex - 32 ) ; pTwoMove = pTwoMask & ( pTwo -> strategy_second ) ; } if ( pTwoMove ) pTwoMove = 1 ; ( * pOneScoreChange ) += payoff [ pOneMove ] [ pTwoMove ] ; ( * pTwoScoreChange ) += payoff [ pTwoMove ] [ pOneMove ] ; pOneIndex = pOneIndex & 0x0000001B ; pOneIndex = pOneIndex << 1 ; if ( pOneMove ) pOneIndex = pOneIndex | 0x00000001 ; if ( pTwoMove ) pOneIndex = pOneIndex | 0x00000008 ; pTwoIndex = pTwoIndex & 0x0000001B ; pTwoIndex = pTwoIndex << 1 ; if ( pTwoMove ) pTwoIndex = pTwoIndex | 0x00000001 ; if ( pOneMove ) pTwoIndex = pTwoIndex | 0x00000008 ; } }
I think this function should be run in parallel.
I think this function should be run in parallel .
// determine moves by 'indexing' into the bit array /*
		// print statements for tracing / debugging
		cout << "pOneMove = " << pOneMove << endl;
		cout << "pTwoMove = " << pTwoMove << endl;
		cout << "pOneIndex = " << pOneIndex << endl;
		cout << "pTwoIndex = " << pTwoIndex << endl;
	*/ // update scores // update past behaviors // 1 hex in binary is 0001, B hex in binary is 1011 //   so the last six bits are 011011 //   and that means that the following line zeros out the //   third and sixth bits // shifts the bits over so the old bits 5,4,2,1 are moved  //   to positions 6,5,3,2 // records the player's (pOne) move in the first bit // records the opponent's (pTwo) move in the fourth bit // Similarly for pTwo