Author Topic: Making Trivia Bot Hints  (Read 5793 times)

0 Members and 1 Guest are viewing this topic.

Offline Ryan Marcus

  • Cross Platform.
  • Full Member
  • ***
  • Posts: 170
  • I'm Bono.
    • View Profile
    • My Blog
Making Trivia Bot Hints
« on: December 19, 2005, 10:21:16 pm »
I'm adding a trivia feature to my bot... I just finished writing the code to create a hint based on a integer that is passed in called HintLevel.

Code: [Select]
  dim i, ii, iii as integer
  dim r as new Random
  dim Hint as string
 
  i = len(Answer)
  ii = 0
 
  while ii<>i + 1
    Hint = hint + "-"
    ii = ii + 1
  wend
 
  ii = 0
 
  while ii<>HintLevel + 1
    iii = r.InRange(1, i)
    Hint = left(hint, iii - 1) + mid(Answer, iii - 1, 1) + mid(hint, iii)
    ii = ii + 1
  Wend
 
  return hint

That should return dashs with HintLevel filled in characters... I have not tested it, but I am sure there is a better way to do it. Its in REALBasic, by the way.
Thanks, Ryan Marcus

Quote
<OG-Trust> I BET YOU GOT A CAR!
<OG-Trust> A JAPANESE CAR!
Quote
deadly: Big blue fatass to the rescue!
496620796F75722072656164696E6720746869732C20796F75722061206E6572642E00

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: Making Trivia Bot Hints
« Reply #1 on: December 19, 2005, 11:09:01 pm »
It seems more common to use I, J, K, L for loop counters than than I, II, III, IIII.

I don't know about realbasic, but VB is pretty nice with its Mid function, allowing it to be written to as well.

I tossed this together in about 10 minutes. Feel free to do whatever you want with it. Warning: The letters it hints are horribly off. =p

Option Explicit

Private Sub Form_Load()
    MsgBox CreateHint("Ryan is weird.", 1)
    MsgBox CreateHint("Ryan is weird.", 1)
    MsgBox CreateHint("Ryan is weird.", 2)
    MsgBox CreateHint("Ryan is weird.", 2)
    MsgBox CreateHint("Ryan is weird.", 3)
    MsgBox CreateHint("Ryan is weird.", 3)
    MsgBox CreateHint("Ryan is weird.", 4)
    MsgBox CreateHint("Ryan is weird.", 4)
    MsgBox CreateHint("Ryan is weird.", 5)
End Sub

Public Function CreateHint(p_sMessage As String, p_iHintLevel As Integer)
    Dim m_iLettersToHint As Integer, m_sRet As String, ary_m_bHinted(1 To 100) As Boolean
    m_sRet = p_sMessage
    Select Case p_iHintLevel
        Case 1: m_iLettersToHint = Len(p_sMessage) / 5
        Case 2: m_iLettersToHint = Len(p_sMessage) / 4
        Case 3: m_iLettersToHint = Len(p_sMessage) / 3
        Case 4: m_iLettersToHint = Len(p_sMessage) / 2
        Case 5: m_iLettersToHint = Len(p_sMessage)      'The should have lost by now, but eh?
    End Select
    m_iLettersToHint = Len(p_sMessage) - m_iLettersToHint
    Dim I As Long, m_iPositionToHint As Integer
    For I = 1 To 100
        ary_m_bHinted(I) = False
    Next I
    For I = 1 To m_iLettersToHint
        m_iPositionToHint = Int(Rnd * Len(p_sMessage)) + 1
        While ary_m_bHinted(m_iPositionToHint)
            m_iPositionToHint = (m_iPositionToHint Mod Len(p_sMessage)) + 1
        Wend
        ary_m_bHinted(m_iPositionToHint) = True
        Mid(m_sRet, m_iPositionToHint, 1) = "*"
    Next I
    CreateHint = m_sRet
End Function
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline igimo1

  • Full Member
  • ***
  • Posts: 420
    • View Profile
Re: Making Trivia Bot Hints
« Reply #2 on: December 20, 2005, 02:46:18 am »
pseudo

Public Function createhint(hint As String, hintlen As Integer)
Dim i As Integer, place As Integer, char As String, L As Integer

i = Rnd(1 * hintlen)
char = Mid(hint, i, 1)
place = InStr(1, char, hint)

For L = 1 To hintlen
If Mid(hint, L, 1) <> char Then
Mid(hint, L, 1) = "-"
End If
Next
End Function

Offline FrOzeN

  • Newbie
  • *
  • Posts: 17
  • ?
    • View Profile
    • Clan AnThRaX
Re: Making Trivia Bot Hints
« Reply #3 on: December 20, 2005, 02:58:20 am »
Select Case p_iHintLevel
    Case 1: m_iLettersToHint = Len(p_sMessage) / 5
    Case 2: m_iLettersToHint = Len(p_sMessage) / 4
    Case 3: m_iLettersToHint = Len(p_sMessage) / 3
    Case 4: m_iLettersToHint = Len(p_sMessage) / 2
    Case 5: m_iLettersToHint = Len(p_sMessage) 'The should have lost by now, but eh?
End Select

m_iLettersToHint = Len(p_sMessage) / (6 - p_iHintLevel)

:)

Offline Ryan Marcus

  • Cross Platform.
  • Full Member
  • ***
  • Posts: 170
  • I'm Bono.
    • View Profile
    • My Blog
Re: Making Trivia Bot Hints
« Reply #4 on: December 20, 2005, 08:38:33 am »
Thanks everybody :)
Thanks, Ryan Marcus

Quote
<OG-Trust> I BET YOU GOT A CAR!
<OG-Trust> A JAPANESE CAR!
Quote
deadly: Big blue fatass to the rescue!
496620796F75722072656164696E6720746869732C20796F75722061206E6572642E00

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: Making Trivia Bot Hints
« Reply #5 on: December 20, 2005, 06:39:06 pm »
Haha @ frozen, you're the man.

@Ryan: Does RB support writing to MID?
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Ryan Marcus

  • Cross Platform.
  • Full Member
  • ***
  • Posts: 170
  • I'm Bono.
    • View Profile
    • My Blog
Re: Making Trivia Bot Hints
« Reply #6 on: December 22, 2005, 08:48:13 am »
Not by itself, but I wrote a method that lets me do it.
Thanks, Ryan Marcus

Quote
<OG-Trust> I BET YOU GOT A CAR!
<OG-Trust> A JAPANESE CAR!
Quote
deadly: Big blue fatass to the rescue!
496620796F75722072656164696E6720746869732C20796F75722061206E6572642E00

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: Making Trivia Bot Hints
« Reply #7 on: December 22, 2005, 05:59:16 pm »
Rock on.
I'd personally do as Joe suggests

You might be right about that, Joe.