![]() |
|
#1
|
|||
|
|||
Need help with a simple "dragon" game.I'm trying to write a simple "dragon" game for a school project.
The game i want to arrive at involves a user 'U' and the computer player 'P'. P and U know are crossing a bridge when a dragon appears. There is a troll watching them, who will give them coins depending on their joint behavior when the dragon appears. If they both do nothing, the troll will think they are nice, animal lovers, and will give them each 10 coins. If they both draw their swords on the dragon, the troll will think they are stressed out and over-reacting, and give them 5 coin each. However, if the P draws its sword and the U does nothing, the troll will think that the P is very brave and that U is a coward, and give P 20 coins, and U nothing. Similarly, if U draws its sword and P does nothing, then the U will seem brave and get 20 coins, and P will get nothing. Here is a summary: Reaction to Dragon amount of coins received (the outcomes are explained below): both P and U do nothing P gets 10, U gets 10 (positive outcome) both P and U draw their swords P gets 5, U gets 5 (negative outcome) P draws sword, U does nothing P gets 20, U gets 0 (positive outcome) P does nothing, U draws sword P gets 0, U gets 20 (negative outcome) So far, this seems like a pretty easy program to make, but my teacher said that it had to be more complicated, and so now I decided the computer player wants to maximize the number of coins it gets over repeated games. It will follow a particular strategy. For the first game, it does whatever it wants: nothing or draws its sword. But after that, the computer will make its next decision depending on the joint outcome of the game just played. When both the user and computer act peace loving (do nothing), both get 10 coins each. This is a good reward and so the computer will decide to repeat its decision to do nothing in the next game. However, an even bigger reward occurs if the computer decided to draw its sword (20 coins) and the user decided to act peace loving (did nothing and got 0 coins)). When this situation occurs, the computer will repeat its decision to draw its sword on the very next game. The computer will switch its output only if a negative outcome happens, for example, if the user drew its sword, and the computer did nothing, which would give the computer 0 points and the user 20 points. In this case, in the next game the computer would draw its sword. If both draw their swords, I am also considering that a negative output for the computer, so next game it will do nothing. This is kinda what I want the program to look like: How many games do you want to play? 3 {user enters 3} Game 1. I’ve made my decision. What is your decision? : S {user enters S for sword} My decision: sword. Your decision: sword I have 5 coins. You have 5 coins. Game 2. I’ve made my decision. What is your decision? : N {user enters N for nothing} My decision: nothing. Your decision: nothing I have 15 coins. You have 15 coins. {updates the total coins} Game 3 I made my decision. What is your decision? : S My decision: nothing. Your decision: sword I have 15 coins. You have 35 coins. End of games. Obviously, to be fair, the computer must set its decision first. I will post what I have so far as soon as I have time. |
|
#2
|
|||
|
|||
Re: Need help with a simple "dragon" game.This is what I have so far...
CPP / C++ / C Code:
So that's what I have, and as you can see in my comment near the bottom, I'm not sure how to do that part. Also, any other things that you could point out that might help would be awesome. Thanks! |
|
#3
|
||||
|
||||
Re: Need help with a simple "dragon" game.Tell us what compiler you have that actually builds this code, for it contains many issues -- I'll start with a few:
where is this statement? CPP / C++ / C Code:
CPP / C++ / C Code:
This block of code: CPP / C++ / C Code:
Questions/points to consider: 1. in each condition, are we comparing or assigning? 2. misuse of characters in the conditions. 3. how is the additives being assigned to the ccoin/ucoin variables? 4. looks like two statements per condition, but what is necessary to ensure this happens logically? I'll stop here, for now. Post again (with updated code) after correcting the aforementioned issues. However, should you get stuck with something, please post another reply. EDIT: Oh, here's my visual studio results trying to compile: Code:
__________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! Last edited by TurboPT : 01-Dec-2007 at 20:21.
|
|
#4
|
|||
|
|||
Re: Need help with a simple "dragon" game.Ok, so I think I fixed a few things: (i'm working with Dev-C++ by the way)
1- I added the apostrophe's around the variable names for 'cdec' and 'udec'. 2- I also change the = to == in the "if" statements and so on. 3- I also corrected the parts with ccoin + 5, because I needed to equate each statement to the new ccoin and ucoin. 4- I added a "result" char, so that the computer can tell whether or not to change it's choice in the next game. I'm not sure if I'm doing it right though, because the computer needs to use the "result" at the bottom to decide whether to change, so that part has to work good. There might be some other changes that I forgot about too. Here's what I have... CPP / C++ / C Code:
So my questions are... -Is that the proper way to go about doing the "result" thing? -Do I have to define k, e, b, and a? -And also, how do I make the program restart or make the user try again if he/she did not enter N or S? (near the bottom I have the cout for it...) |
|
#5
|
||||
|
||||
Re: Need help with a simple "dragon" game.Quote:
Quote:
But instead of ambiguous variable names like these, why not use names like ok, excellent, bad, good? Or better yet, make the #defines or consts. Quote:
__________________
Cow: You're a lawyer too? Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase! |
|
#6
|
||||
|
||||
Re: Need help with a simple "dragon" game.Quote:
Code:
1. In the first error, contains 'redefinition'. That's because you have now declared cdec as both a string AND a char. Which do you want? To assign the character S to cdev is what you have now. CPP / C++ / C Code:
CPP / C++ / C Code:
2. endl is not associated with cin -- that goes with cout. 3. Waltp already responded to this question: Quote:
Code:
I'll stop here, again, for now. Post again (with updated code) after fixing the newer issues. Should you get stuck with something, post another reply. __________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#7
|
|||
|
|||
Re: Need help with a simple "dragon" game.K my program works now!!! There is one problem though, the computer never switches to 'N', it always stays at 'S' no matter what the outcome is. It must be a problem with the last 'if' statement, but i can't get it to work. Here is what I have again...
CPP / C++ / C Code:
Don't know why it won't change... |
|
#8
|
|||
|
|||
Re: Need help with a simple "dragon" game.Quote:
...maybe: dragon_game.cpp:37:19: warning: multi-character character constant dragon_game.cpp: In function `int main(int, char**)': dragon_game.cpp:37: warning: comparison is always false due to limited range of data type dragon_game.cpp:37: warning: statement has no effect dragon_game.cpp:43:19: warning: character constant too long for its type dragon_game.cpp:43: warning: comparison is always false due to limited range of data type dragon_game.cpp:43: warning: statement has no effect dragon_game.cpp:49:19: warning: multi-character character constant dragon_game.cpp:49: warning: comparison is always false due to limited range of data type dragon_game.cpp:49: warning: statement has no effect dragon_game.cpp:55:19: warning: multi-character character constant dragon_game.cpp:55: warning: comparison is always false due to limited range of data type dragon_game.cpp:55: warning: statement has no effect dragon_game.cpp:62:20: warning: character constant too long for its type dragon_game.cpp:62: warning: comparison is always false due to limited range of data type dragon_game.cpp:62:35: warning: multi-character character constant dragon_game.cpp:63: warning: statement has no effect dragon_game.cpp:65: warning: statement has no effect dragon_game.cpp:20: warning: unused variable 'ok' dragon_game.cpp:20: warning: unused variable 'excellent' dragon_game.cpp:20: warning: unused variable 'good' dragon_game.cpp:20: warning: unused variable 'bad' dragon_game.cpp: At global scope: dragon_game.cpp:18: warning: unused parameter 'argc' dragon_game.cpp:18: warning: unused parameter 'argv' [/code] ...has something to do with it? Pay particular attention to the statements that say "is always false" and "statement has no effect." The fact that this stuff even compiled amazes me... :davis: |
|
#9
|
||||
|
||||
Re: Need help with a simple "dragon" game.... Davis, just for curiosity, which compiler do you have? My Visual Studio actually reports two errors, where yours claims them as warnings:
Code:
Quote:
Quote:
__________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#10
|
|||
|
|||
Re: Need help with a simple "dragon" game.Quote:
GCC...don't remember what version and I'm not at that machine right now. I often switch between various versions of GCC based on what I'm doing in a given day. Some of my targets won't compile with the 4.x versions, so I tend to use 3.4.x a lot in those situations. I *think* that it was 4.1...but can't be too sure. Perhaps I'll check in the morning tomorrow and reply then? :davis: |
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| "Linker Error" problem with C++ | The Great Dane | CPP / C++ Forum | 2 | 10-Nov-2007 16:55 |
| Computer Game Design HELP NEEDED! | dcallito | CPP / C++ Forum | 3 | 01-Jun-2007 12:29 |
| HELP!!!!HELP!!!! Design a game call “Games of Guessing” HELP!!!! | tianurn | CPP / C++ Forum | 1 | 26-Mar-2007 15:38 |
| question on old game! | vwinterceptor | Computer Software Forum - Games | 5 | 07-Jun-2004 20:54 |
| Tips for game troubleshooting | pcxgamer | Computer Software Forum - Games | 0 | 02-Jan-2004 05:27 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The