Scrambled Word Game

By RusselB on Apr 28, 2005

Picks a word at random, then scrambles the letters, displaying the scrambled word. Keeps track of the total number of guesses and how long it takes to guess each word

To start: !Scramble
To Guess:!Scramble word

Random word coding compliments of another scripter. Would love to be able to give proper credit to this person, but they didn't include their name in the code that I got, and I don't recall where I got the code from.

on *:text:!scramble*:#:{
  if (!$2) {
    unset %guess_count
    unset %output
    while !%word {
      set %word $lower($randword)
      while $numtok(%word,32) > 1 {          set %word $lower($randword)        }
      var %letter = 1
      while %letter <= $len(%word) {
        if $mid(%word,%letter,1) !isletter unset %word
        inc %letter 1
      }
    }
    var %remain = %word
    var %d $len(%word)
    while %d > 0 {
      var %f = $rand(1,%d)
      var %output = %output $+ $right($left(%remain,%f),1)
      var %remain = $+($left(%remain,$calc(%f - 1)),$right(%remain,$calc(%f - $calc(%f * 2))))
      dec %d
    }
    set %start $ctime
    describe # 5The scrambled word is %output
  }
  elseif $len($2) > $len(%word)     .notice $nick Sorry but you have $calc($len($2) - $len(%word)) letters too many
  elseif $len($2) < $len(%word) .notice $nick Sorry but you have $calc($len(%word) - $len($2)) letters too few
  elseif $lower($2) == %word {
    inc %guess_count 1
    describe # Congratulates $nick for $iif(%guess_count > 1 ,guessing the correct word  4 $upper(%word)  in 5 %guess_count  tries and 12 $duration($calc($ctime - %start)) ,figuring out the correct word  4 $upper(%word1)  in 5 1  try and 12 $duration($calc($ctime - %start)) )
    unset %word
  }
  else {
    inc %guess_count 1
    var %d = 1
    while %d <= $len(%word1) {
      if $mid($2,%d,1) !isin %word1 {
        .notice $nick 4 Invalid letters detected 
        halt
      }
      inc %d
    }
    var %d = 1
    while %d <= $len(%word1) {
      if $mid($2,%d,1) == $mid(%word1,%d,1) {          var %output = $+(%output,$upper($mid($2,%d,1)))        }
      else {          var %output = $+(%output,$lower($mid($2,%d,1)))        }
      inc %d
    }
    describe # 5The scrambled word is %output
  }
}

; Generate initial word list (not necessary, but recommended)
on *:LOAD:{
  randword -r
}
alias randword {
  if ($sock(randomword) != $null) { sockclose randomword }
  sockopen randomword dict.org 2628
  set %rand.file $+(",$scriptdir,randword.txt,")
  ; Identifier
  if ($isid) {
    if ($read(%rand.file) != $null) && ($1 != -r) { return $read(%rand.file) }
    ; If the file's empty it returns blah
    ; This is mainly for first time you use this
    if ($read(%rand.file) == $null) && ($1 != -r) { return blah }
  }
  ; Alias
  else {
    if ($read(%rand.file) != $null) && ($1 != -r) { echo $color(info) -a $read(%rand.file) }
    if ($read(%rand.file) == $null) && ($1 != -r) { echo $color(info) -a blah }
  }
}
on *:sockopen:randomword:{
  write -c %rand.file
  sockwrite -n $sockname m substring $+($rand(a,z),$rand(a,z),$rand(a,z))
  sockwrite -n $sockname quit
  unset %rand.match
  unset %rand.wcount
}
on *:sockread:randomword:{
  if ($sockerr > 0) return
  :next
  inc %rand.wcount
  sockread %rand.temp
  if ($sockbr == 0) return
  if (!%rand.temp) { goto next }
  if ($gettok($remove(%rand.temp,"),2-,32) isupper) { goto next }
  if ($gettok(%rand.temp,1,32) !isnum) {
    write %rand.file $gettok($remove(%rand.temp,"),2-,32)
  }
  goto next
}
on *:sockclose:randomword:{
  if ($lines(%rand.file) == 0) {
    .timer -m 1 250 randword -r
  }
}

Comments

Sign in to comment.
RusselB   -  Jun 08, 2010

If the script has found a word, then the word does exist. There is no guarantee that the word will be from a particular language, or won't be a contraction, short form, slang, etc.

As to resetting the file, this has to be done using the client that is running the code and can be re-generated by typing /randword -r

Lloyd_B  -  May 11, 2013

I've tried to reset this several times and all it gives me is a word made of "sppp". May I suggest a word list file on the bot itself? I maintain a channel bot with different games and I would really like to have a reliable Scramble game. To be honest, I don't have the scripting skill yet to make the changes. I'm gonna take a look at it anyway but I thought maybe the script author would prefer to make the change first.

RusselB  -  May 12, 2013

Regretfully I've been too busy with real life to do any scripting. The only thing that I can think of that would stop this script from working is if the website that supplies the code gets the words from has changed their coding. If this is the case, then there's nothing I can do, as that section of the code was written by someone else, as stated in the introduction.
If someone else wants to take a crack at checking, and, if necessary, recoding that section of the script, be my guest. I don't have the time.

Lloyd_B  -  May 12, 2013

It's ok, I found another scramble game that uses a word list someone can create and add to. I'd rather not rely on a website that can change or even close. Perhaps someone can add that functionality and append a message to this thread to give that code.

Sign in to comment

Glasgow-Girl   -  Jun 08, 2010

i have this script in my chatroom and it has got us all stumped for it has a word that does not exist randomly generated how do we replace the file with another file?

RusselB  -  May 12, 2013

Sorry I didn't get back to you sooner. The easiest way to do that is to follow the instructions on resetting the word list,

Sign in to comment

RusselB   -  Jun 03, 2010

Open the Remotes section of mIRC, using Alt+R, then copy & paste the code into an empty remote. If the remote that opens automatically isn't empty, click File -> New to get a clean remote page.

 Respond  
Efraimz   -  Jun 03, 2010

can you help me where to add this?

i'm beginner @ MIRC and started to learn how to add scramble :(

 Respond  
RusselB   -  Jan 02, 2010

As I stated, the part of the code that generates the random words is not my coding, thus I accept no responsibility if it fails.
I just tested the code again, and it still worked fine for me, so the only thing I can think of is that the site was down when the script tried to get the initial words.

 Respond  
bugboy1028   -  Jan 02, 2010

script is not giving any word :(

 Respond  
RusselB   -  Sep 22, 2009

ttp? Unless you're getting a weird word from the internet site that supplies the words, I have no idea how my code could be giving you that.

 Respond  
bugboy1028   -  Sep 22, 2009

but my MIRC KEEPING say ttp at the end

 Respond  
Firstmate   -  Mar 31, 2009

Nicely done.
9/10

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.