Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Codebreaker
#1
Code: (Select All)
$Color:32
Dim Shared f, f1, lastsolved, guess(10), guesses
Screen _NewImage(640, 480, 32)
Randomize Timer
f = _LoadFont("courbd.ttf", 64, "monospace")
f1 = _LoadFont("courbd.ttf", 32, "monospace")
Color Black, none

n$ = GetNum(5)

Do
    Cls
    guess$ = "": wheel = 0: Xon = 0
    For i = 1 To Len(n$)
        guess$ = guess$ + _Trim$(Str$(guess(i)))
    Next
    DrawLock guess$, n$

    While _MouseInput: wheel = wheel + _MouseWheel: Wend
    X = _MouseX: y = _MouseY: mb = _MouseButton(1): mb2 = _MouseButton(2)

    If y > 105 And y < 195 Then 'we're on the proper spot to be in the combination area
        Xon = Int((X - 105) / (300 / Len(n$)) + 1) 'this is the tumbler we're on
        If Xon > 0 And Xon <= Len(n$) Then
            If wheel Then
                guess(Xon) = guess(Xon) + wheel
            End If
            If mb And Not oldmouse Then guess(Xon) = guess(Xon) + 1
            If mb2 And Not oldmouse2 Then guess(Xon) = guess(Xon) - 1
            If guess(Xon) > 9 Then guess(Xon) = 0
            If guess(Xon) < 0 Then guess(Xon) = 9
        End If
    End If
    If mb And Not oldmouse Then
        If y > 205 And y < 295 Then 'in the solved row
            If X > 105 And X < 395 Then 'in the Last row
                lastsolved = 0: guesses = guesses + 1
                For i = 1 To Len(n$)
                    If Asc(guess$, i) = Asc(n$, i) Then lastsolved = lastsolved + 1
                Next
            End If
        End If
    End If
    oldmouse = mb: oldmouse2 = mb2
    _Display
    _Limit 15
Loop Until lastsolved = Len(n$)
_AutoDisplay
Cls
Color White
_Font f1
Print "YAY!  You got it in"; guesses; "tries!"
Sleep
System

Function GetNum$ (size)
    For i = 1 To size
        n = Int(Rnd * 11)
        tempGetNum$ = tempGetNum$ + _Trim$(Str$(n))
    Next
    GetNum$ = tempGetNum$
End Function

Sub DrawLock (guess$, num$)
    _Font f
    Color Black, none
    size = Len(num$)
    s = 300 / size
    Line (100, 100)-(400, 200), SlateGray, BF
    Line (100, 100)-(400, 300), SlateGray, BF
    Line (105, 105)-(395, 195), LightGray, BF
    Line (105, 205)-(395, 295), Green, BF
    For i = i To (size - 1)
        Line (100 + i * s, 100)-Step(5, 100), SlateGray, BF
        t$ = Mid$(guess$, i, 1)
        left = 105 + (s - _FontWidth) / 2
        _PrintString (left + (i - 1) * s, 150 - _FontHeight / 2), t$
    Next
    t$ = Mid$(guess$, i, 1)
    _PrintString (left + (i - 1) * s, 150 - _FontHeight / 2), t$
    _Font f1
    _PrintString (110, 210), "Last:" + _Trim$(Str$(lastsolved))
    _PrintString (110, 250), "Guesses:" + _Trim$(Str$(guesses))
End Sub


Another old work, found and shared here once again.  Some of you old timers who used to lurk at the old forums before they disappeared might remember seeing this already.

Quote:A little game I was playing around with making to just give my little grand-niece something to waste time on when she comes to visit.

This should be easy enough to figure out:
Use the mouse wheel or the buttons to increase or decrease the values of a tumbler.
Click in the green area to make a guess and see how many numbers you got correct out of your attempt.

Match the actual combination and win!


At this point, this only runs through the creation and puzzle process a single time, for a single 5-digit combination lock. I suppose all it really needs at this point to become a "replayable game" is to offer an option to select difficulty (it can generate anywhere up to 9-digit locks for increased difficulty), and then an option to replay/quit again afterwards -- but that's a simple enough mod for another day, when I have a little more free time again.

Now the question is: How fast can someone solve these type of puzzles? What's the best strategy to get to the win in the least possible number of moves normally?

Randomly type in a number and you *could* get it in one guess, but where's the logic in that?

Type in each number one at a time, click to check, and you're guaranteed to get the solution in 10 * wordlength guesses.

Type in all 5 digits the same, and you can eliminate a whole number from your guess each time. (For example guess five zeros 00000, find out that there's no matches, you've now dropped the possible data pool down to only using numbers 1 to 9. Do it for each of the numbers from 0 to 10, and you've eliminated half the puzzle in 10 guesses, as your 5 digit number can't hold 10 different values!)

Now that I've came up with the little problem to create the puzzles, I'm now left pondering on what might be the best solution for an AI to use to guess the puzzle in the fewest amount of tries possible. Anyone have any thoughts on a surefire Code Breaker solution routine with the fewest possible attempts usually?

I may end up trying to incorporate some sort of competition where a player tries to compete against the computer to shoot for the answer first, so various ideas for AI attempts could be written into the game as different opponents to try your luck against. Suzy might just try random numbers. Jane might do the meticulous one by one approach. Fred might do an elimination approach to solving. Anybody have any other methods to attempt for an AI?

Like most things on my "To Do List", adding AI to this was something which I never got around to doing. LOL!
Reply




Users browsing this thread: 1 Guest(s)