Monopoly Code

Completed to certain point and stuck

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 14444 Views - Last Post: 01 July 2008 - 03:16 AM Rate Topic: -----

#1 Valkarie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-July 07

Monopoly Code

Posted 25 July 2007 - 06:24 AM

PLEASE HELP!!!
Smile I think I fried my brain with what little I have come up with, lol I need some ideas as to finishing the rest and if the code I currently have written out will work?



#include <iostream>
#include <iomanip>
#include <conio.h>

#include <fstream>

#include <string>
#include "dice.h"

using namespace std;

const int MAX_BOARD	= 40;	//Maximum possible number of square on board
const int MAX_CARD	= 25;	//Maximum possible number of cards in deck

enum squareKind	{S_NOP, S_GO, S_ISJAIL, S_TOJAIL, S_PROP,	//Specifies square types
				 S_UTIL, S_RR, S_CHANCE, S_CHEST};			
enum cardKind	{C_NOP, C_ABS, C_REL, C_UTIL, C_RR, C_JAIL};//Specifies card types
enum gameMode	{GAME, SIM};								//Specifies program modes
enum deckType	{CHANCE, CHEST};							//Specifies card decks

struct square_t {				//Describes information on each square
	enum squareKind		sKind;
	string				sLabel;
};

struct card_t {					//Describes possible information on each card
	int				cNum;		//cNum only described in ABS or REL cards
	enum cardKind	cKind;		
	string			cLabel;
};

struct board_t {				//Describes information related to entire board.
	int				locateGo;			//Position of the Go square.
	int				locateJail;			//Position of the Jail square.
	int				boardSize;			//Number of squares on the board.
	int				totalChance;		//Number of Chance cards in the Chance deck.
	int				totalChest;			//Number of Chest cards in Community Chest deck
	struct square_t	squares[MAX_BOARD];	//Array contains info on each square
	struct card_t	chance[MAX_CARD];	//Array contains info on each Chance card
	struct card_t	chest[MAX_CARD];	//Array contains info on each Chest card
};

struct player_t {			   //Describes statistics related to player movement
	bool	inJail;						//True if player in Jail; false otherwise
	int		lastBrdPosition;			//Player's position on board
	int		lastChanceDrawn;			//Chance card to be picked up next
	int		lastChestDrawn;				//Chest card to be picked up next
	int		countJailTn;				//Number of consecutive turns spent in Jail
	int		countDouble;				//Number of consecutive doubles rolled
	int		countFreq[MAX_BOARD];		//Array contains frequency of each square (Sim Mode)
};

//Functions described completely at function definitions
// (.. come up with this on your own ..)

int main(int argc, char * argv[]) {
	int				menuChoice;		//User's input; chooses between Game and Sim
	enum gameMode	modeChoice; 	//User's mode choice converted to enum gameMode
	board_t			gameBoard;		//Board info
	player_t		playerStats;	//Player's statistics

	//Load board data
	gameBoard = getBoard(gameBoard, argv);

	//Initialize player statistics relevant to both Game and Sim modes
	playerStats.inJail			= false;
 	playerStats.lastBrdPosition	= gameBoard.locateGo;
	playerStats.lastChanceDrawn	= 0;
	playerStats.lastChestDrawn	= 0;
 	playerStats.countJailTn		= 0;
	playerStats.countDouble		= 0;
	
	//Print menu
	cout << "MENU" << endl;
	cout << "----" << endl;
	cout << "1. Game Mode" << endl;
	cout << "2. Simulation Mode" << endl;
	
	try {
		do {
			//Input menuChoice
			cout << endl << "Enter Menu Choice: ";
			cin  >> menuChoice;

			if(cin.eof())
				throw menuChoice;

			if (menuChoice != 1 && menuChoice != 2)
				cout << "Invalid Choice." << endl;
			else {
				//Convert menuChoice to enum gameMode
				if (menuChoice == 1)
					modeChoice = GAME;
				else if (menuChoice == 2)
					modeChoice = SIM;
			}
		} while (menuChoice != 1 && menuChoice != 2);

		cout << "Let the game begin." << endl;

		if	(modeChoice == GAME)	  //Play Game
			doGame(gameBoard, playerStats, modeChoice);
		else if (modeChoice == SIM)	  //Perform Simulation
			doSim(gameBoard, playerStats, modeChoice);
	}
	catch(...) {
		//EOF encountered somewhere in program
		cout << "\nEnd of file reached." << endl;
	}

	getch();
	return 0;
}

// (.. the rest of the functions ?..)



From this point on im lost or my brain is just fried I dont even know if what I have will work?

Is This A Good Question/Topic? 0
  • +

Replies To: Monopoly Code

#2 mattman059  Icon User is offline

  • Epic Awesomeness
  • member icon

Reputation: 15
  • View blog
  • Posts: 538
  • Joined: 23-October 06

Re: Monopoly Code

Posted 25 July 2007 - 11:11 AM

a few things would help us help you..first off, tell us what you're trying to do...pin point any particular parts of your code that are giving you trouble..also i noticed that you included a file called "dice.h" but that information is not given in your code...supply us with all of this and im sure someone will try to help.
Was This Post Helpful? 0
  • +
  • -

#3 gogole  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 131
  • Joined: 17-July 07

Re: Monopoly Code

Posted 26 July 2007 - 07:30 AM

will check your code and get back to u.
Was This Post Helpful? 0
  • +
  • -

#4 Valkarie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-July 07

Re: Monopoly Code

Posted 31 July 2007 - 10:43 AM

Here is some of the dice info I came up with....I need a way to wrap this up and run it.


#include "dice.h" #define RAND_INT(l,h) (((int)(random() * ((double)(h)-(l)+1))) + (l)) static unsigned int SEED = 93186752; static double random () { /* The following parameters are recommended settings based on research uncomment the one you want. */ static unsigned int a = 1588635695, m = 4294967291U, q = 2, r = 1117695901; /* static unsigned int a = 1223106847, m = 4294967291U, q = 3, r = 625646750;*/ /* static unsigned int a = 279470273, m = 4294967291U, q = 15, r = 102913196;*/ /* static unsigned int a = 1583458089, m = 2147483647, q = 1, r = 564025558; */ /* static unsigned int a = 784588716, m = 2147483647, q = 2, r = 578306215; */ /* static unsigned int a = 16807, m = 2147483647, q = 127773, r = 2836; */ /* static unsigned int a = 950706376, m = 2147483647, q = 2, r = 246070895; */ SEED = a*(SEED % q) - r*(SEED / q); return ((double)SEED / (double)m); } int roll_die() { return RAND_INT(1,6); }
Was This Post Helpful? 0
  • +
  • -

#5 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Monopoly Code

Posted 31 July 2007 - 11:13 AM

you've still not specified what the problem is? do you need to simulate a dice roll? Are you getting errors?
Was This Post Helpful? 0
  • +
  • -

#6 Valkarie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-July 07

Re: Monopoly Code

Posted 31 July 2007 - 11:46 AM

Okay my problem is I can write all this out but I have no idea how to piece it all together so that it will compile. I am so lost. Its like I have all these puzzle pieces and im not sure how they fit together. Every time I try to get this thing to work i get an error. All I need is to put it together and compile.
Was This Post Helpful? 0
  • +
  • -

#7 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Monopoly Code

Posted 31 July 2007 - 12:08 PM

Let's start by seeing you full code, and the actual error messages you are receiving.
Was This Post Helpful? 0
  • +
  • -

#8 Valkarie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-July 07

Re: Monopoly Code

Posted 02 August 2007 - 10:08 AM

I put notes next to all my code as to what I want it to do but the program is not working with the way I have it set up I need to know what is wrong.

Ive hit a brick wall and just need some direction.
Was This Post Helpful? 0
  • +
  • -

#9 cow_bruiser89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-August 07

Re: Monopoly Code

Posted 03 August 2007 - 06:08 AM

haha wow .. this program looks hard! O_o this must be for a c++ class, am i right? cause like LoL it almost looks like your teacher wrote it haha (no offense, no offense .. but your comments say your missing functions and prototypes)!! but ya .. your teacher must be a total prick :)

but ok anyways here's what i'd do:
- based on the code, it looks like you gotta make a real monopoly game. so first define a Player class, and create bw 2 and 12 Players in the doGame and doSim functions at the bottom of main. so something like:

class Player
{
private:
string playerType; // ie is the player the dog? is he the car? etc.
unsigned int currentLoc; // ie Player's current location on the board
unsigned int money; // ie amount of money in Player's bank
public:
void setType(string); // set the Player's type (ie dog car etc.)
void move(unsigned int); // move the Player around the board

float spendMoney(unsigned int); // spend the Player's money (ie on property etc)
float takeMoney(unsigned int); // obtain money from game

string getType(); // return playerType
unsigned int getLoc(); // return currentLoc
unsigned int getMoney(); // return money
};

so write functions to do all those things in the Player class.

- second, write another class for the chance and community chest decks. something like:

class Deck
{
private:
unsigned int cardNum; // ie which card am i looking at in the deck
string cardText; // ie what does the card say?
public:
performCardAction(Player); // ie do whatever the card says
// remember, sometimes the card changes the Player's state
// ie, he moves around the board, takes money away from Player etc

unsigned int getCardNum(); // get the cardNum var
string getCardText(); // return the card's text
};

this way, you can use the same class for both the chance and community chest. (ie saving a lot of time! :-P)

so now that you have Player (ie he can use money, move around the board etc) and Card (you can draw the
Cards from each deck), it should be really simple to put it together. don't worry if it looks hard at fist. just use
the class prototypes written above, and write the functions - trust me, if you do that the program will work.

good luck!
Was This Post Helpful? 0
  • +
  • -

#10 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Monopoly Code

Posted 03 August 2007 - 07:17 AM

View PostValkarie, on 2 Aug, 2007 - 01:08 PM, said:

I put notes next to all my code as to what I want it to do but the program is not working with the way I have it set up I need to know what is wrong.

Ive hit a brick wall and just need some direction.

We'd be happy to provide direction - you have been prompted several times to post the error messages you are receiving. If you do so, we can help.
Was This Post Helpful? 0
  • +
  • -

#11 LurkingInYourClassroom  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-August 07

Re: Monopoly Code

Posted 03 August 2007 - 03:12 PM

The reason your code doesnt work is simple...
Our Teacher Thomas Mikulski Gave you that source as a hint for your first projects, he wants you to write and complete the monopoly code by creating the functions using that Hint code you so cleaverly disguised as your own...

You have it completely wrong, he doesnt want you to make a monopoly game... Just wants you to simulate the movement of the character around a board.

Ill give you a hint though. after creating the project file in Visual Studio you can compile it to the point that there are 3 errors.
# functions, doGame, doSim, and getBoard are not done.
Mikulski wants you to write the functions that use the structs he created to build the board then run a game that asks the player if he wants to move again or not, also a simulation that will do anywhere from 1 - 1million rolls then print a table of what the player lands on.

Also he provided you 3 other files, these had a number at the top, a type and a tag on each line, he wants you to write a function to read data from these files... Hence your #include <fstream>, But considering this isnt your source im doubting you knew what that #include <fstream> was for.
its also likely reason why you havent provided the other three files for chance, chest and squares.

Doesnt this messageboard have rules against cheating? This is pure theft of source.

The teacher is Pissed... He already knows about this attempt to have others do your work and you better hope he doesnt find out who the person behind your codename is Valkarie.

Oh and one final thing, The teacher only gave this assignement to one class, meaning you are closer to being caught then you think.
if you really need help he encourages you to contact him at his office hours between 7-8 PM at Carabou Coffee in troy Michigan, or through his e-mail at tMikulsk@umich.edu or tmikulski@iadtdetroit.com.

I mean come on he goes out of his way to e-mail us and ask us if we need help at least you could of went to him before pawning off his work as your own to these unsuspecting people.

This post has been edited by LurkingInYourClassroom: 03 August 2007 - 03:36 PM

Was This Post Helpful? 0
  • +
  • -

#12 LurkingInYourClassroom  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-August 07

Re: Monopoly Code

Posted 03 August 2007 - 03:26 PM

View PostValkarie, on 31 Jul, 2007 - 10:43 AM, said:

Here is some of the dice info I came up with....I need a way to wrap this up and run it.


#include "dice.h" #define RAND_INT(l,h) (((int)(random() * ((double)(h)-(l)+1))) + (l)) static unsigned int SEED = 93186752; static double random () { /* The following parameters are recommended settings based on research uncomment the one you want. */ static unsigned int a = 1588635695, m = 4294967291U, q = 2, r = 1117695901; /* static unsigned int a = 1223106847, m = 4294967291U, q = 3, r = 625646750;*/ /* static unsigned int a = 279470273, m = 4294967291U, q = 15, r = 102913196;*/ /* static unsigned int a = 1583458089, m = 2147483647, q = 1, r = 564025558; */ /* static unsigned int a = 784588716, m = 2147483647, q = 2, r = 578306215; */ /* static unsigned int a = 16807, m = 2147483647, q = 127773, r = 2836; */ /* static unsigned int a = 950706376, m = 2147483647, q = 2, r = 246070895; */ SEED = a*(SEED % q) - r*(SEED / q); return ((double)SEED / (double)m); } int roll_die() { return RAND_INT(1,6); }


The dice information here will turn up the same result everytime you play. The teacher gave us this so he can compare his monopoly program and ours to see if we written it right. This information is nowhere near random and no work is needed on this file, to actually roll the die you need to add a int Diceroll1 = roll_die(); and a int Diceroll2 = roll_die(); then add them together to judge how far you move or if you have doubles
Was This Post Helpful? 0
  • +
  • -

#13 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Monopoly Code

Posted 03 August 2007 - 06:03 PM

We do in fact have rules against cheating...that is one of the reasons that we have prompted the user for additional information - to help him/her through the process. We usually refuse to provide code for academic assignments without effort, and remove code given against those policies as we catch it. the site strives to be a resource for students, not a source of cheating.
Was This Post Helpful? 0
  • +
  • -

#14 Valkarie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-July 07

Re: Monopoly Code

Posted 04 August 2007 - 11:22 AM

Apoligize and wish all other students luck. I had no intention of wanting someone to write the code for me. I only wanted direction since the code i was writing out didnt look anything like the code the instuctor wanted. I withdraw from this project since it is assumed that I will cheat. I also apoligize for any other misunderstanding.

Best wishes to other students.
Was This Post Helpful? 0
  • +
  • -

#15 nwneville  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 01-July 08

Re: Monopoly Code

Posted 01 July 2008 - 03:08 AM

where is the rest of the function
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2