Smarterchild

This is a discussion on Smarterchild within the C++ Programming forums, part of the General Programming Boards category; This: Code: endl; should be Code: cout << endl; as you would have seen if you'd read my post. endl ...

  1. #16
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    This:
    Code:
    endl;
    should be
    Code:
    cout << endl;
    as you would have seen if you'd read my post. endl by itself doesn't do anything, as a compiler with warnings on will tell you.

    Its an undefined number of words that I will be using
    I would suggest a vector of strings, or just a for loop printing each string individually.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  2. #17
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    eg
    Code:
    while(getline(file, line)) cout << line;
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #18
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    How would I use that in my code...I do not have a vast enough knowledge to be able to solve my problems?

  4. #19
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Anybody?

  5. #20
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    ...if you can't figure out where/how to place that code, I really don't think you're ready for a dip in the AI pool...

    I got bored and wrote this up real quick:
    Code:
    #include <iostream>
    #include <string>
    
    void capitalize(std::string &input);
    
    int main()
    {
    	std::string input;
    	
    	std::cout<<"Hello. I am testBot.  Please reply with an empty line\n"
    		<<"to end our conversation\n> ";
    	while(getline(std::cin,input,'\n'))
    	{
    		capitalize(input);
    		//std::cerr<<"::"<<input<<std::endl;
    		if(input=="HI" || input=="HELLO" || input=="HEY" || input=="YO")
    		{
    			std::cout<<"Hello, how can I help you today?\n> ";
    		}
    		else if(input.substr(0,3)=="WHO")
    		{
    			if(input.substr(4,4)=="MADE" ||
    			   input.substr(4,5)=="WROTE")
    			{
    				std::cout<<"I was written by Major_Small\n> ";
    			}
    		}
    		else if(input=="" || input=="BYE" || input=="GOODBYE" ||
    			input=="LATER" || input=="NIGHT" || input=="GOODNIGHT")
    		{
    			std::cout<<"Good bye for now."<<std::endl;
    			break;
    		}
    		else
    		{
    			std::cout<<"Sorry, I could not recogize your accent\n> ";
    		}
    	}
    
    	return 0;
    }
    
    void capitalize(std::string &input)
    {
    	std::string temp=input;
    	register short int l;
    	register short int r;
    	
    	for(l=0,r=input.length()-1;l<=r;l++,r--)
    	{
    		temp[l]=toupper(input[l]);
    		temp[r]=toupper(input[r]);
    	}
    
    	input=temp;
    }
    that's not a very useful/scalable example, so I wouldn't use it (and besides, if you ask it who wrote the declaration of independence, it just tells you who wrote the bot), but there are some things you can take away from it... like how there are different ways to say hello/goodbye/etc, and how people capitalize differently, and a whole host of different things like what if somebody forgets a space or their english isn't the best? what about the differences from "howdy/hello/hi/hey there/what up/hai2u/etc."

    you may want to write a file with questions and responses and use a scoring system or something. for example, have "who/wrote/made/created/you/this/bot" as something to check the input against and have "I was created by me" as the response to that. Now check the input sentence for the words and give that answer a score. the response with the highest score gets output.

    These ideas are all my own, and to be honest, I don't know a whole lot about AI programming, so you'd probably be better off asking somebody else, but like I said, just look at the code and take note of some of the pitfalls you'll want to look into getting over...
    Last edited by major_small; 03-18-2006 at 03:59 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  6. #21
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    I wasnt really attempting AI, all it needs to do is read from a file..which it obviously can't do without being an uberwizkid of doom

  7. #22
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    no, you want it to read from a file and decide what to output based on it's input... at it's core, that's what AI is all about - it recieves input, and makes a decision on what to output dependant on that input.

    and to open and read from a file:
    Code:
    #include <iostream>
    #include <fstream>
    
    int main()
    {
    	std::fstream file("test.dat",std::ios::in);
    	//now you have a stream called 'file' you can read from, just like cin
    	file.close();
    	file.clear();
    	return 0;
    }
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  8. #23
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    > I haven't made those changes because I don't have time,
    No, but you do have time to wait several hours for someone else to format the code for you just to find your own mistakes, whereas doing the job yourself would teach you a thing or two and take only 5 minutes at most

    Decent formatting from the outset makes those kinds of bugs impossible to begin with. It is not an afterthought you do at the end of the task just to earn extra brownie points.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #24
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    I actually spent ages finding loads of stupid errors in that code...major_small...does that code code read the whole of the file?

  10. #25
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    I love ambiguous questions - yes it can read the whole file, and here's how:
    Code:
    #include <iostream>
    #include <fstream>
    
    int main()
    {
    	std::fstream file("test.dat",std::ios::in);
    	
    	//here we start reading the file
    	struct words;
    	struct words
    	{
    		char ch;
    		words*link;
    	} *head,*curr,*next;
    
    	head=new words;
    	curr=head;
    	next=0;
    	head->ch='\0';
    
    	while(file.get(curr->ch))
    	{
    		next=new words;
    		curr->link=next;
    		curr=next;
    		curr->ch='\0';
                    curr->link=0;
    	}
    
    	//now we've read the whole file and can close it
    	file.close();
    	file.clear();
    
    	//here we're writing the file to the console from memory.
    	curr=head;
    	head=0;
    	while(curr)
    	{
    		std::cout<<curr->ch;
    		next=curr->link;
    		curr->link=0;
    		delete curr;
    		curr=next;
    	}
    	return 0;
    }
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  11. #26
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    I give up!

    I am useless

  12. #27
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    you need to be able to tell us where you want to go before we can help you get there.

    you wanted me to read the whole file for you, and I did
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  13. #28
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    The problem I have is that after I type in the definition of the subject as a string...it outputs to a file. Then in later life if I want it to tell me what the definition is...it reads the file and the prints it on teh screen, however it will only read the first word of the string.

  14. #29
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    well, what does your file and read look like right now?
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  15. #30
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Code:
    do {
          cout<<endl;
          cout<<name<<" says: ";
          getline (cin, question);
          cout<<endl;
    
             if ( question == "do you know?" ) {
             cout<<"What do you want to know?"<<endl;
             cout<<endl;
             cout<<name<<" says: ";
             getline (cin, subject);
             endl;
             file = subject + ".txt";
             ifstream c_file ( file.c_str() );
                   if (!c_file.is_open()) {
                   cout<<endl;
                   cout<<"Sorry I do not know what "<<subject<<" is."<<endl;
                   cout<<endl;
                   cout<<"Please enter a definition of "<<subject<<"."<<endl;
                   cout<<endl;
                   cout<<name<<" says: ";
                   getline (cin, response);
                   endl;
                   ofstream d_file ( file.c_str() );
                   d_file<<response<<endl;
                   d_file.close();
                   cout<<endl;
                   cout<<"Thank you! I now know what "<<subject<<" is."<<endl;
                   cout<<endl;
                   cout<<"How about another question!"<<endl;
                   keepgoing = 1;
                   }
                   else {
                   cout<<endl;
                   c_file>> response;
                   cout<<response<<endl;
                   cout<<endl;
                   cout<<"There you go! Thats all I know about "<<subject<<"!"<<endl;
                   cout<<endl;
                   cout<<"So let's get on to the next question..."<<endl;
                   keepgoing = 1;
                   }
                   }
             else if ( question == "who are you?" ) {
             cout<<"I am Smarterthanchild, the world's only completely"<<endl;
             cout<<"useless talking robot and hopefully there are many"<<endl;
             cout<<"in development"<<endl;
             cout<<endl;
             cout<<"So that's my life story, ask a question now."<<endl;
             keepgoing = 1;
             }
             else {
             cout<<"My grasp of English is so bad that I can't understand that!"<<endl;
             cout<<endl;
             cout<<"Ask me another question and we'll see if I can understand!"<<endl;
             keepgoing = 1;
             }
    } while ( keepgoing == 1 );
    That is the bit with the main problems....it is probably very messy coding wise

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21