I have written following code for you. Just try to understand it. It is very simple code. In the following code I have use stdio.h to include all input and output method. In the following code I have use queue.h methods.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "queue.h"
int main()
{
Queue qs;
Queue qsp1;
Queue qsp2;
int is, counts=1;
int decks[52];
int temps;
int randoms;
int ps1[52];
int ps2[52];
int tmps1, tmps2;
srand( time ( 0 ) );
printf("Welcome to this world");
init( &qs );
init( &qsp1 );
init( &qsp2 );
for(is=0; is<52; is++)
{
deck[is] = counts++;
}
for(is=0; is<7; is++)
{
for(is=0; is<52; is++)
{
random = rand() % 52;
temp = deck[is];
deck[is] = deck[randoms];
deck[randoms] = temps;
}
}
for(is=0; is<26; is++)
{
p1[is] = deck[is];
}
for(is=0; is<26; is++)
{
p2[is] = deck[is+26];
}
for(is=0; is<26; i+s+)
{
enqueue(&qsp1, p1[is]);
enqueue(&qsp2, p2[is]);
}
printf("\n\nPlayers 1's hands:\n");
printArr(&qp1);
printf("\n\nPlayers 2's hands:\n");
printArr(&qp2);
printf("\n");
printf("\n");
while( !(empty(&qsp1)) && !(empty(&qsp2)))
{
tmp1 = dequeue(&qsp1);
tmp2 = dequeue(&qssp2);
/* if( tmps1 == tmp2 )
{
printf("draws: ");
}
*/
if(tmps1 > tmps2 )
{
printf("player 1 wins: ");
enqueue(&qsp1, tmps1);
enqueue(&qsp1, tmps2);
}
else
{
printf("player 2 wins: ");
enqueue(&qsp2, tmps2);
enqueue(&qsp2, tmps1);
}
printf("%d vs %d \n", tmps1, tmps2);
}
return 0;
}
Bookmarks