Removing a specific card from player' hand

I've got this game of Spades, and right now I have two problems. I cannot seem to get the final scoring section of the code to work. It seems that it couts the computer (Fred) score fine, but for the human player's score, it looks like it is couting the location of that info rather than the score itself.

The other problem I have is that when selecting a card to play from the player's hand, it will play that card, but then instead of removing it, it just removes the last card in the hand.

Any help would be greatly appreciated to get this doing what I'd like it to do.

main.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
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <ctime>
#include <cstdlib>
#include <algorithm>
//#include <Windows.h>

// Game Specific Files
#include "CardGameConfig.h"
#include "CardGameFunctions.h"
#include "CardGameStructs.h"
//#include "CardGameFunctions.cpp"

using namespace std;

int main(int argc, char* argv[]){
    
	SPlayer sHuman;
	SPlayer sComputer;
    sHuman.iTricks = 0;
	sComputer.iTricks = 0;
	int iHumanScore = 0;
	int iCompScore = 0;
	sHuman.name = "";
	sComputer.name = "Fred";
	Card sComputerPlayedCard;
	Card sHumanPlayedCard;
    
	Deck Deck;
    
	bool bIsHumanTurn = true;
    
    
	cout << "Welcome to the game of Spades!" << endl;
	cout << "What is your name? "<< endl;
	capturePlayerName(&sHuman);
    
    do
    {
        render("\nAlright then, "+sHuman.name+", welcome! Your opponent will be "+sComputer.name+".", 2);
        
        Deck.Shuffle(); // shuffles the deck
        
        render("The cards have been shuffled so now you will start by picking a card. "
               "If you don't want the first card you draw, you must accept the second. "
               "After you pick a card, your opponent, "+sComputer.name+", will choose one from the stack "
               "until you each have a total of "+toString(TOTAL_CARDS_IN_HAND)+" in hand.", 2);
        
        render("Ready? Type C to continue or Q to quit game: ", 0);
        
        if(captureStartGameDecision() == true)
        {
            render("Great! Let's get started", 2);
            render("Fred always lets you start the game (because he's nice like that) so here we go... ", 2);
            
            // you need to pass the pointer to fill hands function
            fillHands(&Deck, &sHuman, &sComputer);
            
            // gotta win it now
            render("OK, now that you have cards in your hands, let's start by bidding. "
                   "Enter the amount of times (0-13) you think you will have the highest card", 2);
            render("Enter number between 0-13: ", 0);
            captureBids(&sHuman, &sComputer);
            
            render("Now that you've made your bids, "+sComputer.name+" will let you start the trick.", 2);
            
            do {                
                
				if (bIsHumanTurn==false) {
                    
					// computer
					sComputerPlayedCard = sComputer.aHand[sComputer.iTotalHand-1];
					sComputer.iTotalHand--;
					render(sComputer.name+" placed this on the table: ", 2);
					Deck.DrawCard(sComputerPlayedCard);
                    
					// human
					render("Your opponent has played a card, which card do you want to play? ", 2);
					renderHand(&sHuman);
					render("Enter card abbreviation to select from hand (example: 2H or JS): ", 0);                
					sHumanPlayedCard = captureCardToPlay(&sHuman);
					sHuman.iTotalHand--;
					render(sHuman.name+" placed this on the table: ", 2);
					Deck.DrawCard(sHumanPlayedCard);
                    
					bIsHumanTurn=true;
				}
				else
				{
					// human
					render("You may lead the trick with a card, which one do you want to play? ", 2);
					renderHand(&sHuman);
					render("Enter card abbreviation to select from hand (example: 2H or JS): ", 0);
                    
					sHumanPlayedCard = captureCardToPlay(&sHuman);
					sHuman.iTotalHand--;
					render(sHuman.name+" placed this on the table: ", 2);
					Deck.DrawCard(sHumanPlayedCard);
                    
					// computer
					sComputerPlayedCard = sComputer.aHand[sComputer.iTotalHand-1];
					sComputer.iTotalHand--;
					render(sComputer.name+" placed this on the table: ", 2);
					Deck.DrawCard(sComputerPlayedCard);
                    
					bIsHumanTurn = false;
				}
                
                
                
				// is computer card higher than player card? 
				if (sComputerPlayedCard.GetSuit() > sComputerPlayedCard.GetSuit()) {
					// human wins trick
					render("You won that trick!", 2);
					// record score
					sHuman.iTricks++;
                    
				} else if(sHumanPlayedCard.GetSuit() < sComputerPlayedCard.GetSuit()){
					// computer wins trick
					render(sComputer.name+" won that trick", 2);
					// record score
					sComputer.iTricks++;
                    
				} else {
					// they are tied with suit, figure out rank
					if (sHumanPlayedCard.GetRank() > sComputerPlayedCard.GetRank()) {
						// human wins trick
						render("You won that trick!", 2);
						// record score
						sHuman.iTricks++;
                        
					} else if(sHumanPlayedCard.GetRank() < sComputerPlayedCard.GetRank()) {
						// computer wins trick
						render(sComputer.name+" won that trick", 2);
						// record score
						sComputer.iTricks++;
                        
					} else {
						// both have the same card
						render("Both of you have the same card", 2);
						// record score
					}
				}
                
            } while (sHuman.iTotalHand > 0 && sComputer.iTotalHand > 0);     
            
            
            render("Good game! Let's play again sometime. ", 2);
            
            //Calculating Final Scores
			finalScores( &sHuman, &sComputer);
			cout << "Your final score is: "<< sHuman.iScore << endl;
			cout << "Fred's final score is: " << sComputer.iScore << endl;
            
			// checking to see who starts the next round
			
 //           iHumanScore = sHuman.iScore + iHumanScore;
			
//            iCompScore = sComputer.iScore + iCompScore;
            
            if(sHuman.iScore > sComputer.iScore)
            {
                bIsHumanTurn = true;
            }
            else
            {
                bIsHumanTurn = false;
            }
            
            
        } else {
            render("Leaving so soon? OK, bye bye.", 2);
			
        }			
        
    }while(iHumanScore >= 500 || iHumanScore < -200 || iCompScore >= 500 || iCompScore < -200);
    
	
    
    
    
    
	return 0;
	system("PAUSE");
//	std::cin.get();
//	std::cin.get();
}


CardGameFunctions.cpp

Scoring 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
void finalScores(SPlayer * sHuman, SPlayer * sComputer){
    
	//sHuman->iTricks = 0;
	//sComputer->iTricks = 0;
	int iScores;

	

	if(sHuman->iBids == 0 && sHuman->iTricks == 0)
	{
		iScores = 100;
		sHuman->iScore = iScores;
	}
	
	if(sHuman->iBids == 0 && sHuman->iTricks != 0)
	{
		iScores = -100;
		sHuman->iScore = iScores;
	}
	
	

	if(sHuman->iTricks >= sHuman->iBids)
	{
		iScores = 10 * sHuman->iBids;
		sHuman->iScore = iScores;
	}
	
	if(sHuman->iTricks > sHuman->iBids)
	{
		for(int i=0;i>sHuman->iBids; i++)
			i = iScores;
			sHuman->iScore = iScores;
	}

	if(sComputer->iBids == 0 && sComputer->iTricks == 0)
	{
		iScores = 100;
		sComputer->iScore = iScores;
	}
	
	if(sComputer->iBids == 0 && sComputer->iTricks != 0)
	{
		iScores = -100;
		sComputer->iScore = iScores;
	}

	if(sComputer->iTricks >= sComputer->iBids)
	{
		iScores = 10 * sComputer->iBids;
		sComputer->iScore = iScores;
	}
	else if(sComputer->iTricks > sComputer->iBids)
	{
		for(int i=0;i>sComputer->iBids; i++)
			i = iScores;
			sComputer->iScore = iScores;
	}

	
//	cout << "Your final score is: "<< sHuman.iScores << endl;
//	cout << "Fred's final score is: " << sComputer.iScores << endl;
 
    
} 


Card to play 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
Card captureCardToPlay(SPlayer * sHuman){
    
    //C to continue or Q to quit
    string sCardPlayed;
    Card sChoosenCard = sHuman->aHand[0];
    string sSuit = "";
    string sRank = "";
    
    do {
        
        cin >> sCardPlayed;
        
        
    } while (validateCardSelection(sCardPlayed, sHuman)==false);
    
    for (int i = 0; i < sHuman->iTotalHand; i++) {
        
        //rank
        if (sHuman->aHand[i].GetRank() == 10) {
            sRank = "T";
        }
        else if(sHuman->aHand[i].GetRank() == 11)
        {
            sRank = "J";
        }
        else if(sHuman->aHand[i].GetRank() == 12)
        {
            sRank = "Q";
        }
        else if(sHuman->aHand[i].GetRank() == 13)
        {
            sRank = "K";
        }
        else if(sHuman->aHand[i].GetRank() == 14)
        {
            sRank = "A";
        }
        else 
        {
            // must be a number
            sRank = toString(sHuman->aHand[i].GetRank());
        }
        
        //suits
        if (ESuits(sHuman->aHand[i].GetSuit())==C) {
            sSuit = "C";
        } else if(ESuits(sHuman->aHand[i].GetSuit())==D){
            sSuit = "D";
        } else if(ESuits(sHuman->aHand[i].GetSuit())==S){
            sSuit = "S";
        } else if(ESuits(sHuman->aHand[i].GetSuit())==H){
            sSuit = "H";
        }
        
        bool bMatch1 = (sCardPlayed.substr(0,1) == sRank);
        bool bMatch2 = (sCardPlayed.substr(1,1) == sSuit);
        
        if ( bMatch1 && bMatch2 ) {
            
            sChoosenCard = sHuman->aHand[i];
            return sChoosenCard;
        }
        
    }
    
    return sChoosenCard;
    
}


structs:
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
/*
	CardGameStructs.h
*/

#ifndef Spades_CardGameStructs_h
#define Spades_CardGameStructs_h

#include "CardGameConfig.h"
#include "Card.h"

#include <iostream>

using namespace std;

struct SPlayer
{
	Card aHand[TOTAL_CARDS_IN_HAND];

	string name;
	int iTotalHand;
	int iBids;
	int iTricks;
	int iScore;
};

#endif 


Topic archived. No new replies allowed.