Results 1 to 9 of 9

Thread: Coin Game Help

  1. #1
    Join Date
    May 2012
    Location
    Draynor Willows
    Posts
    498
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default Coin Game Help

    Hey guys, for uni I have to do a game that kinda is just taking coins away from a pile and the last one to take from the pile is the loser. It is against the computer, which I have done, but I have a function that handles the input and output.

    I've been told that I can't do such things, what would be better, having a procedure that does it? Or having it in the main game loop.

  2. #2
    Join Date
    Dec 2011
    Location
    Nj
    Posts
    2,341
    Mentioned
    1 Post(s)
    Quoted
    18 Post(s)

    Default

    Procedure. Always trust the procedures
    Edit: Unless its a very short program. What are the specifics of the game?

    For the basics of the basics of pascal, try my TuT. ||Photoshop Editing ||MapleResourceDung Script || Book a flight! BuySellTrip

  3. #3
    Join Date
    Jan 2012
    Location
    127.0.0.1
    Posts
    702
    Mentioned
    11 Post(s)
    Quoted
    76 Post(s)

    Default

    Quote Originally Posted by TehNeonFishy View Post
    Hey guys, for uni I have to do a game that kinda is just taking coins away from a pile and the last one to take from the pile is the loser. It is against the computer, which I have done, but I have a function that handles the input and output.

    I've been told that I can't do such things, what would be better, having a procedure that does it? Or having it in the main game loop.
    google "nim algorithms" it should give you the awnser.

    Stack handler?

  4. #4
    Join Date
    May 2012
    Location
    Draynor Willows
    Posts
    498
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default

    Ah yeah it seems alot like Nim, but with coins. Just a stack of say 25 coins, each turn the player or computer takes an amount of coins from 1-5 trying to make the other person take the last coin.

    I guess it would be alright in the main loop since it is pretty much a very short/simple game, if I have time I might make it look all fancy. xD

  5. #5
    Join Date
    Dec 2011
    Location
    Nj
    Posts
    2,341
    Mentioned
    1 Post(s)
    Quoted
    18 Post(s)

    Default

    Lol, nice! You would need a predicting algorithm for that.

    For the basics of the basics of pascal, try my TuT. ||Photoshop Editing ||MapleResourceDung Script || Book a flight! BuySellTrip

  6. #6
    Join Date
    Jan 2012
    Location
    127.0.0.1
    Posts
    702
    Mentioned
    11 Post(s)
    Quoted
    76 Post(s)

    Default

    Quote Originally Posted by Rezozo View Post
    Lol, nice! You would need a predicting algorithm for that.
    not really, simple maths formula

  7. #7
    Join Date
    Dec 2011
    Location
    Nj
    Posts
    2,341
    Mentioned
    1 Post(s)
    Quoted
    18 Post(s)

    Default

    Not simple for me
    Also...I see a RunAway!

    For the basics of the basics of pascal, try my TuT. ||Photoshop Editing ||MapleResourceDung Script || Book a flight! BuySellTrip

  8. #8
    Join Date
    May 2012
    Location
    Draynor Willows
    Posts
    498
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default

    I need to have the game show how many coins left in 'o's, how the hell do I do that o.O
    Last edited by TehNeonFishy; 11-04-2012 at 07:10 PM.

  9. #9
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by TehNeonFishy View Post
    I need to have the game show how many coins left in 'o's, how the hell do I do that o.O

    Meh.. close enough.. I don't know any algorithms and I'm lazy to find/write one.

    C++ Code:
    #include <iostream>

    void Computer(int &Coins)
    {
        if (Coins > 11 || Coins == 6)
        {
            Coins -= 5;
            std::cout<<"The computer removed 5 coins leaving a total of: "<<Coins<<std::endl;
        }
        else if (Coins > 6)
        {
            Coins -= 1;
            std::cout<<"\nThe computer removed 1 coin leaving a total of: "<<Coins<<std::endl;
        }
        else
        {
            for (int I = 0; I < Coins; ++I)
            {
                if (Coins - I == 1)
                {
                    Coins -= I;
                    std::cout<<"\nThe computer removed "<<I<<" coin(s) leaving a total of: "<<Coins<<std::endl;
                }
            }
        }
    }

    void Player(int &Coins)
    {
        int AmountRemoved = 0;
        while(true)
        {
            std::cout<<"\nPlease enter how many coins you'd like to remove: ";
            std::cin>> AmountRemoved;
            std::cin.ignore();
            if (AmountRemoved <= Coins)
                break;
        }
        Coins -= AmountRemoved;
        std::cout<<"\nYou removed "<<AmountRemoved<<" coin(s) leaving a total of: "<<Coins<<std::endl;
    }

    int main()
    {
        int Coins = 25;
        bool WhosTurn = false;

        while(Coins != 0)
        {
            WhosTurn = true;
            Computer(Coins);
            WhosTurn = false;
            Player(Coins);
            std::cout<<"\n\n";
        }

        if (WhosTurn)
            std::cout<<"\n\nYou won!"<<std::endl;
        else
            std::cout<<"\n\nYou Lost!"<<std::endl;
    }
    I am Ggzz..
    Hackintosher

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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