arisuchan    [ tech / cult / art ]   [ λ / Δ ]   [ psy ]   [ ru ]   [ random ]   [ meta ]   [ all ]    info / stickers     temporarily disabledtemporarily disabled

/λ/ - programming

structure and interpretation of computer programs.
Name
Email
Subject
Comment

formatting options

File
Password (For file deletion.)

Help me fix this shit. https://legacy.arisuchan.jp/q/res/2703.html#2703

Kalyx ######


File: 1492427512219.jpg (54.95 KB, 400x400, UN-at-sign.jpg)

 No.1[Reply]

I'm currently working on like a silly digital assistant that i started on a long time ago on my C64.
But right now I have it where it can take just some simple single word commands, but I really want to try and get it to break down some sentences and be able to have a very basic conversation and take command stings.

So lets have a parsing engine thread! Text adventures welcome.

Here is what I have so far:

  #include <iostream>
  #include <string>
  #include <fstream>
  #include <cstdlib>
  #include <stdlib.h>
  #include <time.h>
  #include <unistd.h>
  using namespace std;

/*||||||Functions Prototype Start||||||*/

/*||||||Functions Prototype End||||||*/

  int main()
{

/*||||||Variables Start||||||*/
      string mainContVar;
    int menu_return;
/*||||||Variables End||||||*/
    

/*||||||Main Control Loop Start||||||*/
      while(mainContVar != "Close" || mainContVar != "close") {
      cout << "H   H    OOO   PPP   EEE\n";
      cout << "H   H   O   O  P  P  E  \n";
      cout << "HHHHH   O   O  P P   EE \n"; 
      cout << "H   H   O   O  P     E  \n";
      cout << "H   H *  OOO * P  *  EEE *\n\n" <<endl;

      cout << "Hello World! I am H.O.P.E.\n";
      cout << "What can I do for you? ";
      cin >> mainContVar;

          if (mainContVar == "about" || mainContVar == "About")
          {
              cout << endl << "Well I'm H.O.P.E. I'm a digital assitant. Anymore than that and R0gU3 might be mad at me.\n" << endl;
          sleep(5);
          }
        else if (mainContVar == "hello" || mainContVar == "Hello")
        {
          cout << endl << "I already said hello...I mean sure it was to the whole world. But come on, what else you got?\n" << endl;
          sleep(5);
        }
        else if (mainContVar == "poop" || mainContVar == "Poop")
        {
          cout << endl << "Really man. Like is there really a point to that?\n" << endl;
          sleep(5);
        }
         system("cls");
       system("clear");   
      }

/*|||||Main Control Loop End||||||*/
      return(0);

}
3 posts omitted. Click reply to view.

 No.12

>>11
I know this is off-topic, but that is sweet syntax highlighting. I haven't seen it like that on other boards.

 No.13

>>3
>>11

Okay, I change it out, that was just the first solution I found on a fast google search and I never really looked into anything else.


But I like your code 11, I might see if I can mod it for my program.

>>12
I feel like its a valid point, it does look really cool, but 3 is right, the highlighting is off.. So it might be that it isn't picking up on the language correctly.

 No.24

>>1

I was working on a simple parser example a while ago that's quite inefficient but might be something to work from.

#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>

enum EMaybe{
    Nothing,
    Just,
};

struct Maybe{
    enum EMaybe maybe;
    union{
        int *ip; int i;
        float *fp; float f;
        char *cp; char c; bool b;
    }result;
    size_t length;
};

struct Maybe character(char wanted, char c){
    struct Maybe val = {Nothing, 0};
    if (c == wanted){
        val.maybe = Just;
        val.length = 1;
        val.result.c = c;
    }
    return val;
}

struct Maybe many(struct Maybe (fn)(char), char *text){
    struct Maybe val = {Nothing, 0, 0};
    size_t index;
    for (index = 0; (fn(text[index])).maybe == Just; index++);
    val.maybe = Just;
    val.length = index;
    val.result.cp = text;
    return val;
}

struct Maybe upper(char l){
    struct Maybe val = {Nothing, 0};
    if (l > 64 && l < 91){
        val.maybe = Just;
        val.length = 1;
        val.result.c = l;
    }
    return val;
}

struct Maybe lower(char l){
    struct Maybe val = {Nothing, 0};
    if (l > 96 && l < 124){
        val.maybe = Just;
        val.length = 1;
        val.result.c = l;
    }
    return val;
}

struct Maybe letter(char l){
    struct Maybe val;
    val = upper(l);
    if (val.maybe == Just) return val;
    val = lower(l);
    if (val.maybe == Just) return val;
    val.maybe  = Nothing;
    val.length = 1;
    val.result.c = 0;
    return val;
}

struct Maybe digit(char d){
    struct Maybe val = {Nothing, 0};
    if (d > 47 && d < 58){
        val.maybe = Just;
        val.length = 1;
        val.result.c = d;
    }
    return val;
}

struct Maybe oneOf(char *string, size_t length, char c){
    struct Maybe val = {Nothing, 0};
    size_t index;
    for (index = 0; index < length; index++){
        if (string[index] == c){
            val.maybe = Just;
            val.length = 1;
            val.result.c = c;
            return val;
        }
    }
    return val;
}

#define letters(x) many(letter, x)
#define digits(x) many(digit, x)
#define spaces(x) many(space, x)
#define whitespace(x) oneOf(" \t\n", 3, x)
#define space(x) character(' ', x)
#define eof(x) character('\0', x)
#define newline(x) character('\n', x)
#define tab(x) ch
Post too long. Click here to view the full text.

 No.25

>>17
>I don't think the [.code] tags are cancelling the other formatting symbols.
This has been fixed. You may want to update your posts.

 No.34

File: 1493133588363.gif (266.79 KB, 400x400, have_a_nice_day.gif)

>>25
Thanks



File: 1492499456570.jpg (41.35 KB, 480x503, Lain_Split_Personnalities.JPG)

 No.14[Reply]

Ehy Lainons,
I was thinking of working on simple Genetic Algorithms implementations, probably in C or Python.
But I haven't read much so far, so instead of wasting time, I'd like to know what you would suggest to be worth considering as good material, either books/docs or vids.

 No.18

File: 1492565206414.png (114.34 KB, 181x434, monalisa_genetic1.PNG)

The book "Essentials of Metaheuristics" is probably what you want. It's a catalog of algorithms that includes a whole section on genetic and evolutionary algorithms. It explains them and provides pseudo code. Pic related.

 No.19

>>18
Great, many thanks Lainon, that's a wonderful book.
Do you have anything else to suggest, even more abstract?



Delete Post [ ]
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] Next [ Catalog ]