Código fuente simple de C++ Landlords, los Landlords simples no requieren interfaz de usuario, siempre que las cartas se puedan repartir, el propietario se determine aleatoriamente y las cartas estén dispuestas en orden de tamaño.

#include

#include

#include

#include

enum em_CardClass_t

{

_CC_hearts = 0, // Corazones

_CC_Spade, // Picas

_CC_Clubs, // Flores de ciruelo

_CC_Diamonds, // Bloques

_CC_King // Reyes grandes y pequeños

};

struct st_Card_t

{

em_CardClass_t _emCardClass;

UINT _uCardIndex; // Cuando _emCardClass es _CC_King, el valor válido es

// _emCardClass es not_ Cuando CC_King, valores válidos

};

usando el espacio de nombres std;

void InitCard(vector& vtCard)

{

st_Card_t tarjeta;

for( UINT i=0; i<_CC_King; i++ )

{

card._emCardClass = (em_CardClass_t)i;

for( UINT j=1; j<14; j++ )

{

card._uCardIndex = j;

vtCard.push_back(tarjeta);

}

}

card._emCardClass = _CC_King;

card._uCardIndex = 1;

vtCard.push_back(tarjeta);

card._uCardIndex = 2;

vtCard.push_back(tarjeta);

}

//Distribuir tarjetas

void DealCard(vector& vtCard, vector& vtPlayer1,

vector& vtPlayer2, vector& vtPlayer3)

{

srand( (unsigned)time( NULL ) );

for( int i = 0; i < 51 ; i++ )

{

int iCard = rand() % vtCard.size();

cambiar( i % 3 )

{

caso 0:

vtPlayer1.push_back(vtCard[iCard]);

ruptura;

caso 1:

vtPlayer2.push_back(vtCard[iCard]);

romper;

predeterminado:

vtPlayer3.push_back(vtCard[iCard]);

romper;

}

if( iCard != vtCard.size()-1 )

{

vtCard[iCard] = vtCard[vtCard.size()-1];

}

vtCard.pop_back();

}

}

// Oferta

p>

int Bid(vector& vtCard, vector& vtPlayer1,

vector& vtPlayer2, vector& vtPlayer3)

{

srand( (unsigned)time( NULL ) );

int iBider = rand() % 3 // El postor es el propietario

vector* pPlayer = NULL;

cambiar( iBider )

{

caso 0:

pPlayer = &vtPlayer1;

descanso;

caso 1:

pPlayer = &vtPlayer2;

descanso;

predeterminado:

pPlayer = &vtPlayer3;

break;

}

for( UINT i = 0; i < vtCard.size(); i++ )

{

pPlayer->push_back(vtCard[i]);

}

devolver iBider;

}

//La carta completa (dispuesta en orden de corazones, espadas, tréboles, diamantes y reyes pequeños, y el mismo palo está ordenado de pequeño a grande)

anular SortCard(vector& vtPlayer)

{

st_Card_t tmp;

for( UINT i=0; i

{

for( UINT j=i+1; j

{

if( vtPlayer[i]. _emCardClass < vtPlayer[j]._emCardClass )

{

continuar;

}

si( vtPlayer[i]._emCardClass = = vtPlayer[j]._emCardClass &&

vtPlayer[i]._uCardIndex < vtPlayer[j]._uCardIndex )

{

continuar;

}

tmp = vtPlayer[i];

vtPlayer[i] = vtPlayer[j];

vtPlayer[j] = tmp;

}

}

}

void PrintPlayerCard(const string& sPlayerName,

vector const& vtPlayer)

{

cout << sPlayerName << " cards:" << endl;

for( UINT i=0; i< vtPlayer.size (); i++ )

{

cambiar( vtPlayer[i]._emCardClass )

{

caso _CC_hearts:

cout << "Corazón";

romper;

caso _CC_Spade:

cout << "Spade";

ruptura;

caso _CC_Clubs:

cout << "梅花";

ruptura;

caso _CC_Diamonds:

p>

cout << "Bloquear";

romper;

predeterminado:

cout << "Rey";

bre

ak;

}

cout << vtPlayer[i]._uCardIndex<< " ";

}

cout << endl << endl;

}

void main()

{

vector vtCard;

vector vtPlayer1;

vector vtPlayer2;

vector vtPlayer3;

InitCard(vtCard);

DealCard(vtCard, vtPlayer1, vtPlayer2, vtPlayer3);

int iBider = Oferta(vtCard, vtPlayer1, vtPlayer2, vtPlayer3);

SortCard(vtPlayer1);

SortCard(vtPlayer2);

SortCard(vtPlayer3);

PrintPlayerCard("Player1", vtPlayer1);

PrintPlayerCard("Player2", vtPlayer2 );

PrintPlayerCard("Player3", vtPlayer3);

cout <<"El propietario es Player"<< iBider+1 << endl << endl;

}