News:

How did you even find this place?

Main Menu

Making Trivia Bot Hints

Started by Ryan Marcus, December 19, 2005, 10:21:16 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ryan Marcus

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.


  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

Joe

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
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


igimo1

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

FrOzeN

Quote from: Joe[e2] on December 19, 2005, 11:09:01 PM
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)

:)

Ryan Marcus

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

Joe

Haha @ frozen, you're the man.

@Ryan: Does RB support writing to MID?
Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.


Ryan Marcus

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

Joe

Quote from: Camel on June 09, 2009, 04:12:23 PMI'd personally do as Joe suggests

Quote from: AntiVirus on October 19, 2010, 02:36:52 PM
You might be right about that, Joe.