Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 29

Thread: different kind of number guessing game

  1. #11
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: different kind of number guessing game

    Sandy, I can't seem to find the latest version that works. Can you post the version you are using, thanks.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  2. #12

    Re: different kind of number guessing game

    Here it is:
    [code=thinbasic] '---******************************************************
    '---* Game of MasterMind *
    '---* This version uses a four digit *
    '---* code instead of using different *
    '---* colors. *
    '---******************************************************



    '---******************************************************
    '---* This is a console script so it has to have *
    '---* the uses "console" to work *
    '---******************************************************

    uses "console"

    '---******************************************************
    '---* Here are all the variables used in the script *
    '---******************************************************

    dim Quit as long
    dim myNum as string
    dim guess as string
    dim Playing as long
    dim Play_again as long
    dim Result as string
    dim n as long
    dim Num_check as string
    dim Num_only as long
    dim Player_guess as long
    dim build_code as long
    dim x as long
    dim pos_correct as long
    dim dig_correct as long
    dim y as string
    dim z as long
    dim a_guess as string
    dim guess_number as long

    Intro() 'tell about game & how to play

    Quit = %false 'variable changed to %true when time to quit while loop
    while Quit = %False 'while loop where game played
    guess_number = 1 'begin counting the number of guesses to win
    myNum = "" 'variable to hold computer's number

    randomize 'seeds the rnd function
    myNum = int(rnd(0,9)) 'get first digit
    while len(myNum) < 4 'while loop to build 4 digit number - quit when we have 4
    x = int(rnd(0,9)) 'pick next random digit
    if instr(myNum,x) = 0 then 'Make sure each digit is unique
    myNum = myNum + x 'if it is add to computer's number
    end if
    wend 'move on when finished

    console_writeline("I've picked a number") 'tell player computer has number
    console_writeline("") 'then print blank line

    Playing = %false 'variable = %true when player has
    while Playing = %false 'guessed number. There is no offer for player to quit.

    Num_only = %false 'variable = %true if player guess is acceptable
    while Num_only = %false 'loop to check guess
    Console_SetInputMode(%Console_ENABLE_PROCESSED_INPUT) 'lets player use backspace to edit guess before enter key pressed
    console_writeline("Guess Number: " + guess_number) 'tell player the number of guess

    console_write("What is your guess? ") 'ask for guess
    guess = console_readline() 'get the guess
    a_guess = left$(guess,(len(guess)-1)) 'take off cr/enter character from end of guess

    Num_check = VERIFY(a_guess, "0123456789") 'make sure guess has only digits

    select case Num_check
    case <> 0
    console_writeline("Your guess MUST be numbers ONLY!") 'in case player put a wrong character in guess
    console_writeline("")

    case else
    N = len(a_guess)
    if N = 4 then
    Num_only = %true
    else
    console_writeline("Your guess must be 4 digit!") 'don't let guess be < 4 or > 4 digits
    console_writeline("Try again")
    console_writeline("")
    end if
    end select
    wend

    pos_correct = 0 'keep count of number in correct position
    for x = 1 to 4 'look at all 4 digits and
    if mid$(a_guess,x,1) = mid$(myNum,x,1) then 'add to count when needed
    pos_correct += 1

    end if
    next

    dig_correct = 0 'keep count of all digits that are correct
    for x = 1 to 4 'even if they aren't in correct position
    y = mid$(myNum,x,1)

    for z = 1 to 4 'loop to keep count of digits that are correct
    if y = mid$(a_guess,z,1) then
    dig_correct += 1
    exit for 'exit for loop when correct digit found
    end if
    next
    next

    if a_guess = myNum then 'see if player guessed computer's number
    console_writeline("")
    console_writeline("You guessed correctly! You WON!!!!!") 'tell player about win and
    console_writeline("")
    console_writeline("You took " + guess_number + " guesses") 'how many guesses it took
    console_writeline("")
    Playing = %true
    else
    console_writeline("")
    guess_number += 1 'if not a win then increment the guess number by one


    console_writeline("You have " + dig_correct + " digits correct") 'give number of digits correct
    console_writeline("You have " + pos_correct + " digits in the correct position") 'and number of digits in correct position
    console_writeline("")

    end if

    wend


    console_write("Play again? ( (Y)es or (N)o )") 'after win ask if player wants to play again or quit

    Play_again = %false
    WHILE Play_again = %FALSE

    '---Read keyboard input
    Result = Console_inKeyb

    '---Handle returned string
    select case Result

    case "n","N" 'all this if player says no
    console_cls
    Console_Writeline("")
    console_writeline("GOODBYE!!!")
    n = sleep(1000)
    Play_again = %TRUE
    Quit = %true
    case "y","Y"
    guess_number = 1 'all this if player says yes
    console_cls
    Play_again = %true
    end select
    wend

    wend

    function Intro() 'this function gives instructions about how to play
    console_writeline("A Guessing Game!")
    console_writeline("")
    console_writeline("I will choose a 4-digit number.")
    console_writeline("You will try to guess the number.")
    Console_writeline("All I will tell you is how many digits are correct")
    console_writeline("and how many are in the correct position.")
    console_writeline("When you have guessed the number, you win")
    console_writeline("")
    end function
    '---******************************************************
    '---* End of script *
    '---* That's all there is *
    '---******************************************************

    [/code]

    Thanks
    Sandy

  3. #13
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: different kind of number guessing game

    Thanks Sandy. I lucked out and got a 9 after a few games of average 16 scores. Great game and fun as always.
    Let me know who ever gets a lower score, so we have a target to shoot for!!
    Attached Images Attached Images
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  4. #14

    Re: different kind of number guessing game

    I hate to admit it but I've never gotten a score that low. I plan to keep trying.

    If you have any suggestions about how to make the game better please let me know..... I'm kinda out of ideas for now.

    Thanks
    Sandy

  5. #15
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: different kind of number guessing game

    Sandy,

    For console, it would be neat if it cleared the screen and presented your guesses in a nice easy way without the questions. Sort of like an updated score board. Then it will be easier to analyze your guesses.
    2 Guesses so far:
    1234 2 correct numbers - 0 correct position
    2134 2 correct numbers - 2 correct position

    Your next guess please?

    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  6. #16

    Re: different kind of number guessing game

    I needed 12 tries Kent's sugeestion would help a lot. A help function that shows the correct numbers and positions with different colors would be nice. Of course with a penalty on the scores.
    Attached Images Attached Images

  7. #17

    Re: different kind of number guessing game

    Thank you for the replies.

    MikeHart, I'm sorry but I don't completely understand your suggestion about using colors. Could you explain that a little more, please?

    Thanks
    Sandy

  8. #18
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: different kind of number guessing game

    Mike 12 is very good. I just lucked out with that 9. My average was around 16 till that lucky game.

    Sandy, this is how the mastermind game sort of works in color.
    http://www.valil.com/netcf/mastermind.gif

    Instead of numbers you use colored pegs.
    Then you see how many are correct color but in wrong spot (white dot)
    Black dot means right color, right position.

    This is a photo of the plastic game that I used to play and am sure others have played.
    http://upload.wikimedia.org/wikipedi...Mastermind.jpg

    Hope this gives you some ideas!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  9. #19
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: different kind of number guessing game

    Hi sandyrepope,

    your game is very good, but I won't post here no. of my tries until I beat Mike and krytons score . Till know my guessing is terrible.

    kryton, this is shocking - I didn't know mastermind exists as a real life toy


    Bye,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  10. #20

    Re: different kind of number guessing game

    Petr, yes I played that alot when I was a kid.

    Sandy, I will give you a visual example, when I'm back froim work tonight.

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. number guessing game script
    By sandyrepope in forum Console: advanced source code examples
    Replies: 7
    Last Post: 24-02-2007, 08:17

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •