Create a Guess Game

This is the place for ALL of the user submitted challenges. If you create a little challenge/mission/riddle/whatever, post it here.
Forum rules
Do not post missions that you did NOT create without proper citing.

Re: Create a Guess Game

Post by -Ninjex- on Tue Aug 27, 2013 2:26 am
([msg=77058]see Re: Create a Guess Game[/msg])

pretentious wrote:Wow haha, now that's truelly a guessing game


I think that's supposed to be his initializer for how many guess attempts you have.
Code: Select all
var randnumb = (Math.floor (Math.random()*16));

would be the random number
image
For those that know
K: 0x2CD8D4F9
User avatar
-Ninjex-
Moderator
Moderator
 
Posts: 1691
Joined: Sun Sep 02, 2012 8:02 pm
Blog: View Blog (0)


Re: Create a Guess Game

Post by pretentious on Tue Aug 27, 2013 7:14 am
([msg=77060]see Re: Create a Guess Game[/msg])

I figured as much. Was commenting on the fact that the user is only allowed 2 guesses
Goatboy wrote:Oh, that's simple. All you need to do is dedicate many years of your life to studying security.

IF you feel like exchanging ASCII arrays, let me know ;)
Can you say brainwashing It's a non stop disco
User avatar
pretentious
Addict
Addict
 
Posts: 1203
Joined: Wed Mar 03, 2010 12:48 am
Blog: View Blog (0)


Re: Create a Guess Game

Post by -Ninjex- on Tue Aug 27, 2013 8:05 am
([msg=77063]see Re: Create a Guess Game[/msg])

pretentious wrote:I figured as much. Was commenting on the fact that the user is only allowed 2 guesses


Ah, I see now. I initially misread your post.
I apologize. It kind of is truly a guessing game, assuming you are so limited haha
image
For those that know
K: 0x2CD8D4F9
User avatar
-Ninjex-
Moderator
Moderator
 
Posts: 1691
Joined: Sun Sep 02, 2012 8:02 pm
Blog: View Blog (0)


Re: Create a Guess Game

Post by F6Zman on Tue Aug 27, 2013 1:04 pm
([msg=77072]see Re: Create a Guess Game[/msg])

-Ninjex- wrote:
pretentious wrote:I figured as much. Was commenting on the fact that the user is only allowed 2 guesses


Ah, I see now. I initially misread your post.
I apologize. It kind of is truly a guessing game, assuming you are so limited haha


So... did I pass your mission?
F6Zman
New User
New User
 
Posts: 11
Joined: Tue Aug 13, 2013 9:33 am
Blog: View Blog (0)


Re: Create a Guess Game

Post by Gill_Sans on Sun Sep 01, 2013 10:04 pm
([msg=77189]see Re: Create a Guess Game[/msg])

My C++ has gotten rusty over the summer. Good exercise to get back into things.


Code: Select all
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <ctime>
using namespace std;

void usage();

int main(int argc, char ** argv)
{
    if(argc != 2)
    {
        usage();
        return 0;
    }

    bool bError = false;

    for(int i = 0; i < strlen(argv[1]); i++)
    {
        if(!(isdigit(argv[1][i])))
            bError = true;
    }

    if(bError)
        usage();

    else
    {
    int seed = time(0);
    srand(seed);
    int iValue = 1 + rand() % 15;
    int iGuesses = atoi(argv[1]);
    int iSize = 30;
    int iInput;
    char csValue[iSize];

    do
    {
     
        do
        {   
            bError = false;
            printf("\n\t%i guesses remain", iGuesses);
            printf("\n\tWhat might the value be: ");
            cin.getline(csValue, iSize);

            for(int i = 0; i < strlen(csValue); i++)
            {
                if(!(isdigit(csValue[i])))
                    bError = true;
            }
            if(bError)
                printf("\n\tNumeric data only please!");

        }while(bError);
            iInput = atoi(csValue);


        if(iInput == iValue)
        {
            printf("\n\tYou have guessed correctly, as the value was indeed %i", iValue);
            printf("\n\n");
            return 0;
        }

        else
        {
            printf("\n\tNot exactly...");
            iGuesses--;

            printf("\n\tThe current tempurature is ");
            if(iInput >= iValue - 2 && iInput <= iValue + 2)
            {
                printf("hot");
            }

            else if(iInput >= iValue - 5 && iInput <= iValue + 5)
                printf("warm");
            else
                printf("cold");
        }

    }while(iGuesses > 0);

    printf("\n\tSorry, cowboy, but no more guesses remain.");
    printf("\n\tThe value turned out to be %i", iValue);
    printf("\n\n");
    return 0;
    }
}

void usage()
{
    printf("\n\tThis guessing game accept one integer argument");
    printf("\n\t\tguess [int]\n\n");
    return;
}
User avatar
Gill_Sans
New User
New User
 
Posts: 7
Joined: Tue Aug 27, 2013 9:13 am
Blog: View Blog (0)


Re: Create a Guess Game

Post by -Ninjex- on Mon Sep 02, 2013 1:38 am
([msg=77190]see Re: Create a Guess Game[/msg])

@Gill_Sans, I really like how you did the indentation when echoing out the data.

+50
image
For those that know
K: 0x2CD8D4F9
User avatar
-Ninjex-
Moderator
Moderator
 
Posts: 1691
Joined: Sun Sep 02, 2012 8:02 pm
Blog: View Blog (0)


Re: Create a Guess Game

Post by Amazingred on Wed Sep 11, 2013 9:40 pm
([msg=77340]see Re: Create a Guess Game[/msg])

Had to give it a go...Python

Code: Select all
import random

def setup():
    """
    Gets difficulty setting from user and uses that to determine the
    number of possible guesses and the ranges of a 'HOT' and 'WARM' guess.
    Returns warmnumber variable, hotnumber variable, number to guess.
    """
    difficulty=input('Please select difficulty level between 1-100 where 1 is easiest & 100 is hardest')
    warmbase=4+((difficulty-1)*2)
    hotbase=2+((difficulty-1)*1)
    choices=15+((difficulty-1)*5)
    number=random.randrange(choices+1)
    warmnum=range(number-warmbase, number+warmbase+1)
    hotnum=range(number-hotbase, number+hotbase+1)
    return warmnum, hotnum, number, choices

def check_guess(guessnum, triesleft, warm, hot, number):
    """
    Checks the guess by the user and determines how close the guess is, how many
    tries are left, if the guess is correct.
    Returns triesremaining, proximity temp if not correct;
    Returns -1, Congratulations message if correct
    """
    if number==guessnum:
        return -1, "YOU HAVE GUESSED CORRECTLY!  CONGRATS ON SOLVING THE GUESSING GAME!"
    elif guessnum in hot:
        return triesleft-1, 'HOT!'
    elif guessnum in warm:
        return triesleft-1, 'Warm'
    else:
        return triesleft-1, 'Cold'

def PlayGame():
    """
    Takes data returned by setup() function and begins the guessing game
    """
    warm, hot, number, choices=setup()
    tries=5
    guess=input('You have %d attempts to guess the number Im thinking of between 1 and %d.' %(tries, choices))
    while tries>0:
        tries, closeness=check_guess(guess, tries, warm, hot, number)
        if tries==-1:
            print closeness
            quit
        elif tries>0:
            guess=input('Nope! You are %s.  You have %d tries remaining.' %(closeness, tries))
        elif tries==0:
            print "SORRY.  You didn't guess correctly.  The number I was thinking of was %d." %(number)

def main():
    PlayGame()

if __name__ == '__main__':
    main()
There are 10 types of people in the world. Those who understand binary and those who don't.
User avatar
Amazingred
Experienced User
Experienced User
 
Posts: 74
Joined: Wed Jul 25, 2012 7:10 pm
Location: Wayyyyyy out there
Blog: View Blog (0)


Re: Create a Guess Game

Post by -Ninjex- on Mon Sep 16, 2013 7:55 am
([msg=77383]see Re: Create a Guess Game[/msg])

@Amazingred +75
image
For those that know
K: 0x2CD8D4F9
User avatar
-Ninjex-
Moderator
Moderator
 
Posts: 1691
Joined: Sun Sep 02, 2012 8:02 pm
Blog: View Blog (0)


Re: Create a Guess Game

Post by nightmair on Thu Oct 17, 2013 8:44 am
([msg=77724]see Re: Create a Guess Game[/msg])

Started learning C# recently, so here goes:
I hope it's readable.

Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        private static int goal;
        private static int difficulty;
        private static int max;
        private static Random rand;
        private static int guesses;

        static void Main(string[] args)
        {
            rand = new Random();
            string s;
            string yn;
                do
                {
                    //the user is asked for his preferred difficulty before each game
                    System.Console.WriteLine("What should be the difficulty? (1-100)");
                    s = System.Console.ReadLine();
                    while (!int.TryParse(s, out difficulty) || difficulty <= 0 || difficulty > 100)
                    {
                        System.Console.WriteLine("Invalid input. Please enter a number >=1 and <=100");
                        s = System.Console.ReadLine();
                    }
                    //fit the game to the difficulty input
                    max = 5 * difficulty + 10;
                    guesses = 6 + (int) Math.Log(difficulty, 2);
                    System.Console.WriteLine("Please Guess the number <= {0}",max);
                    goal = rand.Next(max) + 1;
                    //start game
                    LetGuess();
                    //ask whether the player wants to play again after previous game has ended
                    System.Console.WriteLine("Play again? y/n");
                    yn = System.Console.ReadLine();
                } while (yn.CompareTo("y")==0);
        }
        static void LetGuess()
        {
            string s = System.Console.ReadLine();
            int guess;
            //try to cast input to int
            if (!int.TryParse(s, out guess))
            {
                //cast wasn't successfull
                System.Console.WriteLine("Wrong type of input! \nPlease enter an Integer.");
                LetGuess();
                return;
            }
            if (guess == goal)
            {
                System.Console.WriteLine("You Win!");
                return;
            }
            else
                if (Math.Abs(guess - goal) <= 2 + difficulty - 1)//centip3de's algorithm for hot numbers
                    System.Console.WriteLine("Hot!");
                else
                    if (Math.Abs(guess - goal) <= 4 + (difficulty - 1) * 2)//centip3de's algorithm for warm numbers
                        System.Console.WriteLine("Warm.");
                    else
                        System.Console.WriteLine("cold.");
            guesses--;
            if (guesses > 0)
            {
                System.Console.WriteLine("You have {0} guesses left", guesses);
                LetGuess();
            }
            else
                System.Console.WriteLine("You lost :( \nthe number was {0}", goal);
        }
    }
}

(My first post on HTS, yay :D)
nightmair
New User
New User
 
Posts: 4
Joined: Sat Aug 31, 2013 5:46 pm
Blog: View Blog (0)


Re: Create a Guess Game

Post by -Ninjex- on Sat Oct 19, 2013 7:21 pm
([msg=77768]see Re: Create a Guess Game[/msg])

nightmair wrote:(My first post on HTS, yay :D)


Firstly, welcome to HTS!
Secondly, +50
image
For those that know
K: 0x2CD8D4F9
User avatar
-Ninjex-
Moderator
Moderator
 
Posts: 1691
Joined: Sun Sep 02, 2012 8:02 pm
Blog: View Blog (0)


PreviousNext

Return to User Submitted

Who is online

Users browsing this forum: No registered users and 0 guests