Results 1 to 5 of 5

Thread: Setting up AI, of a sort?

  1. #1
    Join Date
    May 2008
    Posts
    1,345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Setting up AI, of a sort?

    Ok, so I'm looking to add some crude ai to my script, favor the messages that get more replies over the ones that give less replies.

    Looking for a way to do this. This is what I have so far, probably totally wrong :P.

    SCAR Code:
    Program New;
    {.include srl/srl.scar}

    var
      Array1 : Array of String;
      Array2 : Array of Integer;
     
    Function Go : String;
    Begin
      Case Random(Array2[0] + Array2[1] + Array2[2]) Of
        0..Array2[0] : Begin
                         Result := Array1[0];
                         Inc(Array2[0]);
                       End;
        Array2[0] + 1..Array2[1] + 1 : Begin
                                     Result := Array1[1];
                                     Inc(Array2[1]);
                                   End;
        Array2[1] + 1..Array2[2] + 1 : Begin
                                     Result := Array1[2];
                                     Inc(Array2[2]);
                                   End;
      End;
    End;

    Begin
      SetupSrl;
      Array1 := ['Hi', 'Hello', 'Yo'];
      Array2 := [0, 0, 0];
      Repeat
        WriteLn(Go);
        wait(100);
      Until(isfkeydown(9))
      WriteLn(IntToStr(Array2[0]))
      WriteLn(IntToStr(Array2[1]))
      WriteLn(IntToStr(Array2[2]))
    End.

  2. #2
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Shorter:
    SCAR Code:
    Program New;
    var
      Array1 : Array of String;

    Begin
      Array1 := ['Hi', 'Hello', 'Yo'];
      Repeat
        WriteLn(Array1[Random(Length(Array1))]);
        wait(100);
      Until(isfkeydown(9))
    End.


  3. #3
    Join Date
    May 2008
    Posts
    1,345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Nono, I know how to do that. I'm looking for it to pick the one that gets used more, but still rarely use the others. The one I posted will use the first one, then only that one.

  4. #4
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Like this?
    SCAR Code:
    program New;
    const debug=false;
    var a,b,c,d:integer;
    begin
      writeln('press f12 after a while');
      repeat
        case random(100) of
        0..39:
          begin
            if debug then writeln('a');
            inc(a);
          end;
        40..59:
          begin
            if debug then writeln('b');
            inc(b);
          end;
        60..79:
          begin
            if debug then writeln('c');
            inc(c);
          end;
        80..99:
          begin
            if debug then writeln('d');
            inc(d);
          end;
        end;
      until isfkeydown(12);
      writeln('---------------------------------------');
      writeln('A: '+inttostr(a));
      writeln('B: '+inttostr(b));
      writeln('C: '+inttostr(c));
      writeln('D: '+inttostr(d));
    end.

  5. #5
    Join Date
    May 2008
    Posts
    1,345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    No, something like this:

    SCAR Code:
    Program New;
    {.include srl/srl.scar}
    var
      Array1 : Array of String;
      Array2 : Array of Integer;

    Function FunDuel : String;
    Var
      P : Integer;
    Begin
      Case Random(Array2[0] + Array2[1] + Array2[2] + Array2[3] + Array2[4] + Array2[5]) Of
        0..Array2[0] : Begin
                         Result := Array1[0];
                         Inc(Array2[0]);
                       End;
        Array2[0]..Array2[1] + Array2[0] : Begin
                                                 Result := Array1[1];
                                                 Inc(Array2[1]);
                                               End;
        Array2[1]..Array2[2] + Array2[1] : Begin
                                                 Result := Array1[2];
                                                 Inc(Array2[2]);
                                               End;
        Array2[2]..Array2[3] + Array2[2] : Begin
                                                 Result := Array1[3];
                                                 Inc(Array2[3]);
                                               End;
        Array2[3]..Array2[4] + Array2[3] : Begin
                                                 Result := Array1[4];
                                                 Inc(Array2[4]);
                                               End;
        Array2[4]..Array2[5] + Array2[4] : Begin
                                                 Result := Array1[5];
                                                 Inc(Array2[5]);
                                               End;
      End;
      If Result = '' Then
      Begin
        P := Random(6);
        Result := Array1[P];
        Inc(Array2[P]);
      End;
    End;

    Begin
      SetupSrl;
      ClearDebug;
      Array1 := ['funning all', 'fun dueling', 'funning everyone', 'dueling for fun', 'funning', 'funning anyone'];
      Array2 := [1, 2, 3, 4, 5, 6];
      Repeat
        WriteLn(Funduel)
        wait(1);
      Until(IsFkeyDown(9))
      AddToReport(IntToStr(Array2[0]));
      AddToReport(IntToStr(Array2[1]));
      AddToReport(IntToStr(Array2[2]));
      AddToReport(IntToStr(Array2[3]));
      AddToReport(IntToStr(Array2[4]));
      AddToReport(IntToStr(Array2[5]));
    End.


    Got it working .

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. my first C app (sort of)
    By Shuttleu in forum C/C++ Help and Tutorials
    Replies: 5
    Last Post: 02-10-2009, 09:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •