Game of NIM using vectors

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 2384 Views - Last Post: 13 May 2010 - 07:03 PM Rate Topic: -----

#1 Twitch153  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 13-May 10

Game of NIM using vectors

Posted 13 May 2010 - 04:12 PM

Okay, so basically I have an extremely stubborn and arrogant C++ teacher. He doesn't even teach and he doesn't help but only a select student, we've just started learning about using the "<lvp\vector.h>" library, and I have no clue how to do anything...It's saddening. But anyways, I'm a junior in my highschool and I need ALOT of help. I'll paste the pseudocode once someone responds to my plead for help, and I'm warning you before hand, I have NOTHING done. That's why I'm asking for help! D:

Is This A Good Question/Topic? 0
  • +

Replies To: Game of NIM using vectors

#2 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Game of NIM using vectors

Posted 13 May 2010 - 04:46 PM

There is no such header <lvp\vector.h> in the standard library. There is however a <vector> header in the standard template library.

What's the problem?
Do not say it doesn't work. Provide specific details about your problem and any errors that you are receiving.

EDIT: That signature is way too big. Make it smaller or there will be problems.

This post has been edited by eker676: 13 May 2010 - 04:47 PM

Was This Post Helpful? 0
  • +
  • -

#3 Twitch153  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 13-May 10

Re: Game of NIM using vectors

Posted 13 May 2010 - 04:58 PM

Well, we're using Turbo c++ in my class and I'm assuming the lvp\vector.h is considerably close to the vector library, but I just don't understand how he expects us to do this, here, I'll give you a small snippet of our pseudo code he gives us, it makes sense, but I have no clue how to get it done.

Quote

==>Homework Hints<==



Game of Nim - Multiple Piles
Functions:
1. int TotalStones(vector &p) - returns the number of stones total (add
the piles)
2. bool PlayersTurn(vector p, int pnum)
Takes the players turn: p is the vector of pile and pnum is current
player #
Pseudocode:
Display the number of stones in each pile
Display the pile number under each number from above
Force the user to select an existing pile that has stones
- 2 do-whiles (one inside the other)
Force the user to enter the correct number of stones
Deduct from the correct pile
See if the player lost (return true if not lost, false if lost -
whatever u want)

3. void InitPiles(vector &p, int lo, int hi)
Initialize each pile with random number of stones between lo and hi

Was This Post Helpful? 0
  • +
  • -

#4 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Game of NIM using vectors

Posted 13 May 2010 - 05:41 PM

The complexity of the project is not high at all. It just takes time and good design. I could write the program if I had the full specifications in a half hour maybe. But all it will take is time. I looks like he already gave you all the necessary functions. You have to convert english to code.

If you don't know how to start the homework, then it's time to stop playing games in class and start paying attention.

You have to start coding and come back when you have problems. We won't do your homework for you.

Great C++ Reference:
http://cplusplus.com/reference/

Great C++ Tutorial:
http://cplusplus.com/doc/tutorial/

I suggest starting with the tutorial.

This post has been edited by eker676: 13 May 2010 - 05:42 PM

Was This Post Helpful? 0
  • +
  • -

#5 Twitch153  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 13-May 10

Re: Game of NIM using vectors

Posted 13 May 2010 - 05:49 PM

The thing is I DO pay attention, I don't play games and you need to stop thinking that I want you to do my homework for me, I read the rules, I'm not stupid. I didn't ask you to do it, I just have no idea on how to use a vector in a function. I already explained that he doesn't give us any clue on how to do any of this. He says "I want you to make a program using vectors, and I want it to do this and that." He never taught us any of the crap and we have to pull these programs out of our rear ends or else we fail. I'm sorry I don't understand programming as well as you do.
Was This Post Helpful? 0
  • +
  • -

#6 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Game of NIM using vectors

Posted 13 May 2010 - 05:52 PM

Give it your best shot, then come back when it doesn't work. It can be way off but we will still be able to help because we will have an idea at what you are trying to do.

Right now we have no clue whatsoever.

This post has been edited by eker676: 13 May 2010 - 05:52 PM

Was This Post Helpful? 0
  • +
  • -

#7 Twitch153  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 13-May 10

Re: Game of NIM using vectors

Posted 13 May 2010 - 05:57 PM

Okay, I'll do that. But would you have any idea on how to use one vector for multiple functions? When I did my program I did this for the playrsturn:
bool playersturn(const vector <int> &stonepile, int playernum){

 cout<< "[" << stonepile[0] << "]";
 cout<< "[" << stonepile[1] << "]";
 cout<< "[" << stonepile[2] << "]";
 cout<< "[" << stonepile[3] << "]"<<endl;
 playernum ++;
 if( playernum % 2 )
	  playernum = 2;
	  cout<<"Player "<< playernum <<" choose a stonepile to chose  
          from: ";
 }


and I KNOW it's not right. I didn't complete it..or even really start because I know that I have to use vectors to set it up.

This post has been edited by JackOfAllTrades: 14 May 2010 - 04:25 AM
Reason for edit:: Added code tags.

Was This Post Helpful? 0
  • +
  • -

#8 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Game of NIM using vectors

Posted 13 May 2010 - 06:05 PM

Well you seem to be passing the vector in correctly. Your usage of the vector is fine.

Post your current code in :code: tags
Was This Post Helpful? 0
  • +
  • -

#9 Twitch153  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 13-May 10

Re: Game of NIM using vectors

Posted 13 May 2010 - 06:09 PM

Yeah but when I try to execute it it will say something like:

Quote

"Linker error:Undefined symbol vector<int>::operator[](int) const in module"

Was This Post Helpful? 0
  • +
  • -

#10 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Game of NIM using vectors

Posted 13 May 2010 - 06:19 PM

Take out the 'const' or try using the .at() function from the vector class.
Was This Post Helpful? 0
  • +
  • -

#11 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Game of NIM using vectors

Posted 13 May 2010 - 06:21 PM

Quote

Well, we're using Turbo c++ in my class and I'm assuming the lvp\vector.h is considerably close to the vector library,
I'm not. I assume lvp means lawrenceville press, and the vector library is basically like the efforts of the AP library and the rest of the bunch that existed before the 1999 standard. Basically, it's like you're programming as if you live in 1990.

The linker error is not the same as a compile error. Syntactically, everything is fine. The problem is, the linker can't find the actual code. For example, if I write the code:

void CreateWorldPeace();
int main() { CreateWorldPeace(); }



I have a syntactically correct program, but I will fail at link time. That's because I don't have the actual code for this function anywhere.

You have the same problem. vector.h just indicates the existence of the vector and all member functions (like operator [] which you are using). Problem: where's the actual code?
Was This Post Helpful? 1
  • +
  • -

#12 Twitch153  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 13-May 10

Re: Game of NIM using vectors

Posted 13 May 2010 - 06:24 PM

.at()? Never heard of it. See? This is what I'm talking about with the poor teaching haha. I'm sorry if I'm being a hassle but I really do appreciate the help.
Was This Post Helpful? 0
  • +
  • -

#13 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Game of NIM using vectors

Posted 13 May 2010 - 06:28 PM

Quote

This is what I'm talking about with the poor teaching haha.
Poor teaching, maybe. Here's the thing. The curriculum is something that would have made sense in the 90s. C++ wasn't standardized until 1990, but it was well in use before then. So things like the LVP and AP libraries made sense. Borland Turbo C++ was also very good in the early 90s.

Obviously two decades have passed, and a lot has changed. If the curriculum hasn't changed, I blame your school system. They basically don't care about the CS electives. It's a token elective if they don't even look at it for 20 years. Your teacher, bad or not, has to teach along that really old syllabus.
Was This Post Helpful? 0
  • +
  • -

#14 Twitch153  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 13-May 10

Re: Game of NIM using vectors

Posted 13 May 2010 - 06:33 PM

Hahaha Yeah, I know what you mean with the 1990 programming. See, I live in NY and it's..not the best place to be up to date with any kind of technological anything haha Well, I will show you what I was doing:

 
#include <iostream.h>
#include <lvp\vector.h>
#include <lvp\random.h>
#include <lvp\bool.h>

int totalstones(const vector <int> &stonepile){
}

bool playersturn(const vector <int> &stonepile, int playernum){

 cout<< "[" << stonepile[0] << "]";
 cout<< "[" << stonepile[1] << "]";
 cout<< "[" << stonepile[2] << "]";
 cout<< "[" << stonepile[3] << "]"<<endl;
 playernum ++;
 if( playernum % 2 )
     playernum = 2; 
     cout<<"Player "<< playernum <<" choose a stonepile to chose from: ";
 }

void initializep(vector <int> &stonepile, int lo, int hi){
}

void main(){
 cout<<"Testing, testing, one two, one two.";
}


I know it's not the greatest but I was using it to test if it would execute or not.
Was This Post Helpful? 0
  • +
  • -

#15 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Game of NIM using vectors

Posted 13 May 2010 - 06:40 PM

Again, you need the actual code. I looked at the LVP library and found that the code consists of headers and source files, with instructions to put the headers in include\lvp folder for your compiler. But you still need to use the source files (the actual code).

What I personally would do is compile the source files to a static library, and then link as necessary. However, since you are still learning, the best thing to do is to just include the source files along with the rest of your program. Compile them all.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2