got problem with my code

hi, I'm writing a Card war Game. but i got problem when i try to compile the main function.

Here is my Code:
card.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include<iostream>
#include<vector>
#include<algorithm>
#include <cassert>
#include "Card.h"
#include "Random.h"

using namespace std;

Card::Card()
:rank(1),suit(spade)
{
}

Card::Card(suits su,unsigned int numberOfRank)
: rank(numberOfRank), suit(su)
{
}

Card::Card(const Card& orig)
: rank(orig.rank), suit(orig.suit)
{
}

Card::~Card()
{
}
Card& Card::operator = (const Card& other){
	if(this != &other)
		{
			rank = other.rank;
			suit = other.suit;
		}
	return *this;
}

unsigned int Card::getRank() const{
	return rank;
}


void Card::setRank(unsigned int numberOfRank){
	assert((numberOfRank > 0 ) && (numberOfRank <= max_ranks));
	rank = numberOfRank;
}

suits Card::getSuit()const{
	return suit;
}

void Card::setSuit(suits su){
	suit = su;
}

void Card:: insertCard(ostream& out)const{
	switch(rank)
	{
		case 1: out<<"A";break;
		case 11: out<<"J";break;
		case 12: out<<"Q";break;
		case 13: out<<"K"; break;
	default:
	out<<rank; break;
	}

	switch(suit)
	{
		case diamond: out<<"D)";break;
		case club: out<<"C)";break;
		case heart: out<<"H)";break;
		case spade: out<<"S)";break;
	}
}

ostream& operator<<(ostream& out, const Card& aCard)
{
	aCard.insertCard(out);
	return out;
}
//make a deck of cards
Deck::Deck()
{
	for(int i = 1; i<= max_ranks; i++)
	{
		Card c1(diamond,i);
		Card c2(spade,i);
		Card c3(heart,i);
		Card c4(club, i);
		cards.push_back(c1);
		cards.push_back(c2);
		cards.push_back(c3);
		cards.push_back(c4);
	}
}

Deck::Deck(const Deck& orig)
{
	operator = (orig);
}
Deck::~Deck()
{
}

Deck& Deck::operator = (const Deck& other)
{
	if(this != &other)
	{
		cards = other.cards;
	}
	return *this;
}

void Deck:: shuffle(){
	random_shuffle(cards.begin(),cards.end());
}

bool Deck:: isEmpty()const{
	return(cards.size()==0);
}

Card Deck::deal(){
	assert(!isEmpty());
	Card retval(spade,1);

	if(!isEmpty())
	{
		retval = cards.back();
		cards.pop_back();
	}
	return retval;
}

Player::Player(){
	myPoint = 0;
}

Player::Player(Deck& aDeck)
:myPoint(0)
{
	for(int i = 0; i<hand_size; i++)
	{
		assert(!aDeck.isEmpty());
		myPoker.push_back(aDeck.deal());
	}
}

Player::Player(const Player& orig)
: myPoker(orig.myPoker), myPoint(orig.myPoint)
{
}

Player::~Player()
{
}

Player& Player::operator = (const Player& rhs){
	if(this!= &rhs)
	{
		myPoker = rhs.myPoker;
		myPoint = rhs.myPoint;
	}
	return *this;
}

Card Player::deal(){
	assert(myPoker.size()>0);
	randomInteger randomizer;
	int removePoker = randomizer(myPoker.size());

	Card draw_card = myPoker[removePoker];
	myPoker[removePoker] = myPoker.back();
	myPoker.pop_back();
	return draw_card;
}

Card Player::nextCard(){
	Card c(myPoker.front());
	return c;
}

int Player::myPokerSize(){
	return myPoker.size();
}
void Player::addCard(Card card){
	myPoker.push_back(card);
}
int Player::point()
{
	return myPoint;
}

/*void Player::battle(Player player1, Player player2){
	if (player1.
//}*/
void Player:: replaceCard(Deck& aDeck){
	assert(!aDeck.isEmpty());
	myPoker.push_back(aDeck.deal());
}


card.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef CARDS_H
#define CARDS_H

#include <iostream>
#include <vector>
#include <deque>

using namespace std;

enum suits{diamond, club, heart, spade};

const unsigned int max_ranks = 13;

class Card{
	public:
	//default
	Card();
	//copy constructor
	Card(const Card& orig);
	//explict value con
	Card(suits su, unsigned int numberOfRank);

	~Card();
	//copy assingment oper
	Card& operator = (const Card& rhs);

	unsigned int getRank()const;
	suits getSuit() const;


	void setSuit(suits su);
	void setRank(unsigned int numberOfRank);

	void insertCard(ostream& out)const;
	
	private:
	suits suit;
	unsigned int rank;
};
	ostream& operator <<(ostream& out, const Card& aCard);
	
class Deck{
	public:
	Deck();
	
	Deck(const Deck& orig);

	~Deck();
//copy assignment operator
	Deck& operator = (const Deck& other);

	bool isEmpty() const;

	void shuffle();
	
	Card deal();

	private:
	vector<Card> cards;
};

class Player{
	public:
	
	Player();
	Player(Deck& aDeck);
	
	Player(const Player& orig);

	~Player();

	Player& operator = (const Player& other);

	Card deal();
	
	Card nextCard();

	void addPoint(int point);
	void addCard(Card card);
	void battle();

	int point();
	int myPokerSize();
	
	

	void replaceCard(Deck& aDeck);
	deque<Card> player1Container;
	deque<Card> player2Container;

//	private:
	 deque<Card> myPoker;

	int myPoint;
	
	static const int hand_size = 3;
};
#endif 


and my main function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include "Card.h"
#include "Random.h"
#include "time.h"
#include <fstream>

using namespace std;

int main(){
	srand(time(NULL));	
	Deck theDeck;
	theDeck.shuffle();
	
	Player Player1;
	Player Player2;
	
	for( int i = 0; i< 52; i++){
		if (i%2 == 0)
		{
			Player1.addCard(theDeck.deal());
		}
		else
			Player2.addCard(theDeck.deal());
	}
		cout<<"Player1 has Poker: "<<Player1.myPokerSize()<<endl;
		cout<<"Player2 has Poker: "<<Player2.myPokerSize()<<endl;

	bool finish = false;
	int tieCounter = 0;
	int battleNumber = 1;
	while(!finish)
	{
	
	battleNumber ++;
	cout<<(Player1.myPoker).at(0).getRank()<<endl;
	
	cout<<(Player2.myPoker).at(0).getRank()<<endl;
	
	if	((Player1.myPoker).at(0).getRank() == (Player1.myPoker).at(0).getRank())
		{
		cout<<"Game Tie\n"<<endl;
		tieCounter++;
		}
		
	else if ((Player1.myPoker).at(0).getRank() > (Player2.myPoker).at(0).getRank())
	{
		(Player1.myPoker).insert((Player1.myPoker).end(), (Player2.myPoker).at(0));
		(Player1.myPoker).insert((Player1.myPoker).end(), (Player1.myPoker).at(0));
		(Player1.myPoker).erase((Player1.myPoker).begin());	
		(Player2.myPoker).erase((Player2.myPoker).begin());	
		cout<<"Player1 won the Battle\n"<<endl;
		cout<<"player1 has cards"<<Player1.myPokerSize()<<endl;
	}
	
	
	else
	{
		(Player2.myPoker).insert((Player2.myPoker).end(), (Player1.myPoker).at(0));
		(Player2.myPoker).insert((Player2.myPoker).end(), (Player2.myPoker).at(0));
		(Player2.myPoker).erase((Player2.myPoker).begin());	
		(Player1.myPoker).erase((Player1.myPoker).begin());	
		cout<<"Player2 won the Battle\n"<<endl;
		cout<<"player2 has cards"<<Player2.myPokerSize()<<endl;
	}
		
	finish = (Player1.myPokerSize() < 0 || Player2.myPokerSize()<0);
	finish = true;
}
	return 0;
}


my problem is the compiler should keep compare the card until the one of player has no card. but actually it only compile once and just into the if equal statement even though two cards are not equal.

Can anybody tells me how can I keep compile this program until the one player has no card

thanks for helping me.
Line 70 finish is always true.
I change to the false , then it compile it with a infinitely loop.

Any body please help me !

Thanks
Delete line 70 altogether.
i just try that. but still infinitely loop.
Topic archived. No new replies allowed.