mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 2 1 2
Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
I'm starting to wonder if this thing is even possible... It always seems to get wonky if there's double numbers involved. It works perfectly fine if each number is different, though. Here's a new log just taken...

[12:13] <Fernin> !guess 1111
[12:13] <+LexiaBot9000> You have 0 correct.
[12:13] <+LexiaBot9000> You have 0 out of place.
[12:13] <Fernin> !guess 2345
[12:13] <+LexiaBot9000> You have 1 correct.
[12:13] <+LexiaBot9000> You have 0 out of place.
[12:13] <Fernin> !guess 6789
[12:13] <+LexiaBot9000> You have 1 correct.
[12:13] <+LexiaBot9000> You have 1 out of place.
[12:13] <Fernin> ...
[12:14] <Fernin> !guess 0000
[12:14] <+LexiaBot9000> Enter a four digit number between 1111 and 9999
[12:14] <Fernin> !guess 2222
[12:14] <+LexiaBot9000> You have 1 correct.
[12:14] <+LexiaBot9000> You have 1 out of place.
[12:14] <Fernin> !guess 3333
[12:14] <+LexiaBot9000> You have 0 correct.
[12:14] <+LexiaBot9000> You have 0 out of place.
[12:14] <Fernin> !guess 6666
[12:14] <+LexiaBot9000> You have 0 correct.
[12:14] <+LexiaBot9000> You have 0 out of place.
[12:14] <Fernin> !guess 7777
[12:14] <+LexiaBot9000> You have 2 correct.
[12:14] <+LexiaBot9000> You have 2 out of place.
[12:14] <not_sure> broken still
[12:14] <Fernin> !guess 8888
[12:14] <+LexiaBot9000> You have 1 correct.
[12:14] <+LexiaBot9000> You have 1 out of place.
[12:14] <Fernin> very much so
[12:14] <Fernin> !guess 2778
[12:14] <+LexiaBot9000> That's right! 2778! You win, Fernin! And it only took 9 guesses. Type !mastermind to start a new guessing game.

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
The score-calculating code isn't quite correct. One error is the fact that %g*num vars are set to "x" before they are used in $remtok, whereas this should happen afterwards. But that's not the only problem (eg it fails with number = 8888, guess = 1118).

Here's an alternative that works with numbers of any length (not just 4).
Code:
; $mmscore(actual, guess)
; eg $mmscore(2778,7777)
; returns <correct> <close>
; ("2 0" for the above example)
alias mmscore {
  var %i = 1, %correct = 0, %close = 0
  while $mid($2,%i,1) != $null {
    if $v1 == $mid($1,%i,1) {
      inc %correct
      tokenize 32 $left($1,$calc(%i - 1)) $+ $right($1,- $+ %i) $&
        $left($2,$calc(%i - 1)) $+ $right($2,- $+ %i)
    }
    else inc %i
  }
  %i = 1
  while $mid($2,%i,1) != $null {
    if $pos($1,$v1) {
      inc %close
      tokenize 32 $left($1,$calc($v1 - 1)) $+ $right($1,- $+ $v1) $2
    }
    inc %i
  }
  return %correct %close
}


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
Back once again, the mastermind code you suggested worked perfectly, qwerty, that game is running smoothly now. I also finished up a craps game, which was far easier to program. I've gotten a better handle on the language over the past few weeks, and started to tinker around with the programs that came with the bot. One of them is a timebomb program, in which it kicks a person unless they're able to !snip a randomly selected wire from a randomly selected number of wires. I inserted the if statement to reset the code to 32 if it happens to come up 1, screwing them over instead of giving them a free pass, but it's not quite working yet. There's a lot more involved in this program, but this is the only part that could be going wrong...

Code:
  else {
    set %timeBombDuration $rand(%permTimebombMinimumDuration,%permTimebombMaximumDuration)
    set %TimebombTargetNick %timeBombNick
    set %TimebombTargetChan %timeBombChan
    set %timeBombnumberOfWires $rand(1,%permTimebombMaxWireCount)
    if (%timeBombnumberOfWires == 1) { set %timeBombnumberOfWires 32 }
    var %TimebombTempWireChoices %permTimebombWireChoices
    var %TimebombINC 1
    while (%TimebombINC <= %timeBombnumberOfWires) {
      var %TimebombCurrentWire = $gettok(%TimebombTempWireChoices,$rand(1,%timeBombnumberOfWires),32)
      var %TimebombTempWireChoices = $remtok(%TimebombTempWireChoices,%TimebombCurrentWire,1,32)
      var %TimebombSelectedWires = $addtok(%TimebombSelectedWires,%TimebombCurrentWire,32)
      inc %TimebombINC
    }
    set %TimeBombCorrectWire $gettok(%TimebombSelectedWires,$rand(1,$numtok(%TimebombSelectedWires,32)),32)
    set %timeBomblistOfWires They are %TimebombSelectedWires $+ .
  }


permTimebombWireChoices is a list of 34 different colors, space deliminated. When I was testing it, I had it rigged to always come up as 1 to be reset to 32, and that was working, it was telling me I had 32 wires. However, when it displayed the colors, I'd get anywhere from 6 to 14 colors, never the full 32. The only thing I can think of is that it's somehow choosing nothing as the color and adding nothing to the list, but that shouldn't be possible due to the $remtok in the loop. I feel like I've come here too often for help already, but... What's gone wrong this time?

Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
Isn't there anyone that can help me with that timebomb code?

...Please?

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Instead of:
var %TimebombCurrentWire = $gettok(%TimebombTempWireChoices,$rand(1,%timeBombnumberOfWires),32)
try:
var %TimebombCurrentWire = $gettok(%TimebombTempWireChoices,$rand(1,$numtok(%TimebombTempWireChoices,32)),32)

(You want to pick a random wire out if all the remaining possible wires, not out of the first N of the possible wires, where N is the number of wires-to-pick)

Page 2 of 2 1 2

Link Copied to Clipboard