Well, it's a good thing there's nothing wrong with lengthy code, this thing's getting up there already...

Code:
;@@@ Mastermind @@@
on 1:text:*mastermind:#: {
  if (%!mastermind == on) {
    if ($1 == %c $+ mastermind) {
      if ($me !isvoice $chan) {
        MSG $chan Sorry, I've lost the privilege to speak. Try again later when I've been reactivated.
        halt
      }    
      set %fnum $rand(1,9)
      set %snum $rand(1,9)
      set %tnum $rand(1,9)
      set %hnum $rand(1,9)
      set %counter 0
      set %mnum %fnum $+ %snum $+ %tnum $+ %hnum
      bt $chan I'm thinking of a number... It's a four digit number, between 1000 and 9999. Try and guess it with !guess (####)
    }
  }
}
on 1:text:*guess*:#: {
  if ($1 == %c $+ guess) {
    if (%mnum == $null) { msg $chan I'm not thinking of a number yet. | halt }
    if ($2 !isnum 1000-9999) { msg $chan Enter a number between 1000 and 9999 | halt }
    if ($2 == %mnum) { 
      msg $chan That's right! %mnum $+ ! You win, $nick $+ ! And it only took %counter guesses. Type !mastermind to start a new guessing game.
      unset %mnum | halt
    }
    if ($2 != %mnum) { 
      inc %counter
      set %gfnum $mid($2, 1, 1)
      set %gsnum $mid($2, 2, 1)
      set %gtnum $mid($2, 3, 1)
      set %ghnum $mid($2, 4, 1)
      set %correct 0
      set %close1 0
      set %closef 0
      set %closes 0
      set %closet 0
      set %closeh 0
      if (%gfnum == %fnum) { inc %closef }
      if (%gfnum == %snum) { inc %closef }
      if (%gfnum == %tnum) { inc %closef }
      if (%gfnum == %hnum) { inc %closef }
      if (%gsnum == %snum) { inc %closes }
      if (%gsnum == %tnum) { inc %closes }
      if (%gsnum == %hnum) { inc %closes }
      if (%gsnum == %fnum) { inc %closes }
      if (%gtnum == %tnum) { inc %closet }
      if (%gtnum == %hnum) { inc %closet }
      if (%gtnum == %fnum) { inc %closet }
      if (%gtnum == %snum) { inc %closet }
      if (%ghnum == %hnum) { inc %closeh }
      if (%ghnum == %fnum) { inc %closeh }
      if (%ghnum == %snum) { inc %closeh }
      if (%ghnum == %tnum) { inc %closeh }
      if (%gfnum == %fnum) { inc %correct }
      if (%gsnum == %snum) { inc %correct }
      if (%gtnum == %tnum) { inc %correct }
      if (%ghnum == %hnum) { inc %correct }
      if (%closef >= 1) { inc %close1 }
      if (%closes >= 1) { inc %close1 }
      if (%closet >= 1) { inc %close1 }
      if (%closeh >= 1) { inc %close1 }
      set %close %close1 - %correct 
      msg $chan You have %correct correct.
      msg $chan You have %close out of place.
    }
  }
}


Sorry for the lack of comments, I almost never comment my own work... Should be fairly easy to follow, though. The code works fine, it just has logical errors in it leading to it being screwy, depending what number is set and what numbers are guessed. (Which obviously isn't a good thing). And if you're still unsure of what it is I'm trying to do, take a look at the wiki page for the game: http://en.wikipedia.org/wiki/Mastermind_(board_game) ...Yeah, that was supposed to be linked way back up in the first post, I dunno how the other page ended up getting linked. Must've had the wrong thing copied at the time.

Last edited by Fernin; 27/01/09 01:04 AM.