Thread: Chat BOT

  1. #46
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    classes dont havta be in seperate files
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  2. #47
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Which is better tho, i want this code well documented and easily readable, and i would think a few different cpp's would make this easier then just one.

  3. #48
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Well, if you place them into separate .cpp files, you'll have to compile them separately, then link the .obj files when building the program. A good newbie way is to place the functions in separate header files, and just #include them with your program. Cheap and easy
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #49
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    so like this?

    openfile.h
    readfile.h
    searchfile.h

    Code:
    #include "openfile.h"
    #include "readfile.h"
    #include "searchfile.h"
    So then how do i call the functions when i need them?

  5. #50
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    In the header, just do:

    char * GetBytes( const char filename[], int * num_bytes) {
    //...code
    }


    Then in the main.cpp file:

    int main() {
    char * bytes;
    int amount;

    bytes = GetBytes("response.txt", &amount);

    bytes[amount-1] = '\0';

    //...code...

    }
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  6. #51
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Ok i'm sure that will make sense once i get going haha.

    thnx

  7. #52
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Okee... Well, from what I know, these are the main purposes of headers:

    -For classes:
    -put the class declaration (or whatever you call it) in (classname).h
    -put the implementation (or whatever you call it) in (classname).cpp

    i.e.
    Code:
    //this is classname.h
    
    class Classname
    {
       public:
          void changeData(int n);
          int getData();
       protected:
          int data;
    };
    
    //this is classname.cpp
    
    #include "classname.h"
    
    void Classname::changeData(int n)
    {
       data = n;
    }
    
    int Classname::getData()
    {
       return data;
    }

    Then in main.cpp (or whatever you call it)

    Code:
    #include "classname.h"
    
    int main()
    {
       Classname myObject;
       myObject.changeData(5);
       cout << "myObject.data = " << myObject.getData();
       return 0;
    }
    Another purpose is to stick related functions/macros together:
    Code:
    //this is anglestuff.h
    
    #define PI 3.1415926535897932384626
    #define DEGREES_TO_RADIANS(degrees) ((degrees) * (PI / 180))
    #define RADIANS_TO_DEGREES(radians) ((radians) * (180 / PI))
    
    float getRefAngle(float angle)
    {
       if(angle >= 0 && angle < 90)
          return angle;
       else if(angle < 180)
          return (180 - angle);
       else if(angle < 270)
          return (angle - 180);
       else
          return (360 - angle);
    }
    The last (I think) reason for using separate headers is, of course, just to confuse people and make the code impossible to understand. As for how the multiple-cpp's work, look at the classes example ;) They're for if you have the function prototype in a header and the definition in a cpp file.

    **EDIT**
    #include "openfile.h"
    #include "closefile.h"
    #include "readfile.h"
    No, that is probably not a good idea :) Instead, you'd probably want to do this:
    Code:
    #include "myfilestuff.h"
    Or, on the other hand, you could just do file i/o like normal people do it, and do the opening and stuff manually :P
    Last edited by Hunter2; 10-13-2002 at 01:53 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  8. #53
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    wow this thread is loaded....

    ok hunt thnx for the help(?) lol.

  9. #54
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    No prob(?) lol.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  10. #55

    results of more geography boredom...

    I have been thinking about how one could implement my previous idea. Here is what i have come with (scrawled on the back of a geography worksheet).

    When the user asks a question, do the following:
    change the case
    filter out uneeded words and characters (articles, punctuation, etc.)
    try to find a match.
    If you find a match, feed back the related answer.
    if you don't:
    -counter it (as before described)
    -write it into the file
    -write the user's response to the file
    reply.

    To distinguish the questions from other statements and related words, questions could either have a separate file (questions.txt) or have a separate range of id's. The related answer(s) would have the same ID and probably be in a different file (answers.txt) or another section of the main file.

    The bot should also randomly ask the user a question and record the feedback so the bot can fuel it's own answer-repository.

    When the bot is parsing the input, the bot could have a list of names (which are added to every time the user logs in) that it replaces with %s for subject if it finds them.

    Also, to make the conversation more interesting, the bot could have a long list of generic starements and replies that have a %o in then (for object) that it uses to keep the conversation going. This (along with a variable containing the object and some way to filter out the object of conversation) would make the bot seem more coherent and intelligent.

    That's all for now,
    ~Inquirer
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  11. #56
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    as much as i love your idea, i haven't even got past the opening of the file, the checking of the file for a match, the opening the reply file, and replying.

  12. #57
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    You haven't gotten past opening the file yet?? Psst... try #include <fstream> And then look into std::ifstream and std:fstream.

    P.S.
    I hope I'm not slighting your intelligence; if you already knew the stuff very well, feel free to ignore me
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  13. #58
    i'm mostly just putting the ideas out there for when i get around to making my own. I like getting my ideas out there to be chewed up, mixed around, and spat back out (pardon the metaphor) just to see if they get improved anyo or if it is possible or a waste of time, etc.

    P.S. an O.K. tutorial on file opening and stiff i found at http://www.cpp-home.com/FileIO_tutorial.php . The one i learned from isn't online anymore, and i don't know where it went.

    //edit

    P.P.S. In the tutorial i gave you, beware of the bad programming practices he uses (void main() etc.) and the fact that he calls quotes inverted commas. good luck!

    edit//

    ~Inquirer
    Last edited by Inquirer; 10-13-2002 at 03:30 PM.
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  14. #59
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Wasn't there supposed to be an online "Sam's teach yourself c++ in 21 days"? That's a good place to look.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  15. #60
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Ok i got the open/close file down. I open it at the very start of the program, now how would i search the text enterd by the user for keywords that match words in the keywords.txt i opend?

    Like this idea:

    If word matches
    goto appropriate response in response.txt (also oepnd)
    Output the answer.

    if not
    Add question to Addquestion.txt
    tell user you don't know.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Chat Bot Help!!
    By arealfind08 in forum C Programming
    Replies: 1
    Last Post: 03-09-2009, 06:52 AM
  2. Chat bot brain ideas
    By cogeek in forum C++ Programming
    Replies: 14
    Last Post: 10-02-2004, 12:26 AM
  3. Chat Bot: Multiple headers problem
    By RoD in forum C++ Programming
    Replies: 4
    Last Post: 03-26-2003, 06:07 PM
  4. Chat BOT Sample
    By RoD in forum C++ Programming
    Replies: 19
    Last Post: 11-04-2002, 04:51 AM
  5. Msvc Aim Chat Bot ???
    By Unregistered in forum C++ Programming
    Replies: 0
    Last Post: 09-19-2001, 08:46 AM