Beginners Brevity Contest: BUZZ

Online C++ programming contests.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard, raimo

Beginners Brevity Contest: BUZZ

Postby Darryl » Fri Sep 09, 2005 9:58 am

BUZZ: A Beginners Brevity Contest
Deadline: September 30, 2005 11:59PM EST

Introduction:

This brevity contest is based on the Drinking game of Buzz. It should be fairly simple and straight forward to implement with a low token count, which is why I am calling it a beginners brevity, but I still encourage all to participate.


Programming Task:
You will derive a player from the provided player class that plays the game of Buzz as described in the link above. Your player must keep track of whose turn it is as well as direction of play during the game. Each turn the "Game" will give you the last reply and you will respond with one of the following:
-if it is your turn respond with current number or "buzz".
-if it is not your turn return empty string.

If a player responds incorrectly, they will be eliminated and a new game is started with remaining players(which means init() will be called again and your player may get a new seat number). Game play will continue until there is either 1 player remaining or the game has reach INT_MAX in the count.

Judging
All entries the remain in the game up to INT_MAX will be judged based on code brevity using tokxx.

Rules/Restrictions:
You must submit 1 source file, with a .h or .hpp extension.
Your entry may not use any input files.
No macos / asm
For the init() you can return any unique name, but I would suggest your cpphome screen name.
Submit entries to my gmail address, username littled

I will not be providing a test framework because it contains solutions to the problems you are solving since it must determine right and wrong answers and I don't want it to affect your creativity, however I will let you know if there are any technical problems with your entry if they are submitted early enough.

Here is the class to overide:
Code: Select all
#include <string>

class player
{
        public:
   virtual std::string init(int player_position, int num_of_players)=0;
   // Return your players unique name
   // player_position is your "seat" position starting with 1
   // player 1 goes first, then 2 etc, player 1 goes after last player
   // play direction switches after a "buzz", highest player then goes after player 1
   
   virtual std::string respond(std::string last_response)=0;
   //if it is your turn, respond with the current number or "buzz"
   //there should be no leading/trailing spaces in the number
   //if it is not your turn, return empty string so string.empty() will give true;
        //the first last_response to start game is empty string
};


Your file will be included after my player class definition therefore you do not need to #include "player.h" but simply just: class Your_Player : public player

Have fun and good luck to all.
Last edited by Darryl on Sat Sep 10, 2005 6:25 am, edited 4 times in total.
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby tomcant » Fri Sep 09, 2005 10:04 am

The link isn't working for me. :roll:
If it wasn't for C, we would be using BASI, PASAL and OBOL.
User avatar
tomcant
 
Posts: 3101
Joined: Tue Sep 23, 2003 1:56 am
Location: Colchester, UK

Postby Darryl » Fri Sep 09, 2005 10:17 am

The link is good, but seems a bit slow now, but here are the rules from that page:

Buzz

This game is not only a fun and simple drinking game but a learning experience as well. If you don't have your math skills honed then be wary of this game.

Rules:

Sit everyone around in a circle. Choose one person to start. They start by saying the number 1. The person to their left or right (it doesn't matter) says then says 2 and so on. When someone is about to say either 7, 11, a multiple of 7 or 11, or a number containing 7, they must say Buzz. (Ex. 1,2,3,4,5,6,Buzz,8,9,10,Buzz.) As soon as someone says Buzz you switch directions. So if you were going to the right you switch to the left. If anyone messes up, everyone drinks. This is supposed to be a quick moving game so if someone thinks for a minute that counts as messing up. It's really fun and easy to learn!!


Sample output from 4 player game:
player 1: 1
player 2: 2
player 3: 3
player 4: 4
player 1: 5
player 2: 6
player 3: buzz
player 2: 8
player 1: 9
player 4: 10
player 3: buzz
player 4: 12
etc.
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby exomo » Fri Sep 09, 2005 10:34 am

I don't like the line "If anyone messes up, everyone drinks".
I'm sure my PC is totally drunk before I can submit^^

How do I know how many players there are in the game? You can't know if it is your turn if you don't know the total number of players
Who needs a signature anyway.
User avatar
exomo
 
Posts: 894
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Postby Darryl » Fri Sep 09, 2005 10:35 am

exomo wrote:I don't like the line "If anyone messes up, everyone drinks".
I'm sure my PC is totally drunk before I can submit^^

How do I know how many players there are in the game? You can't know if it is your turn if you don't know the total number of players


Yea I noticed that and already fixed it in the init() function.

As far as the drinking goes, when I was a drinker and played that game, only the person who messed up drank, but for this we'll make the programmer drink :-)
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby Emery » Fri Sep 09, 2005 11:00 am

Darryl wrote:I was a drinker
#define drinker drunk
--~~~~
User avatar
Emery
 
Posts: 4313
Joined: Sat Mar 19, 2005 9:16 am

Postby Darryl » Fri Sep 09, 2005 11:04 am

RITZ wrote:
Darryl wrote:I was a drinker
#define drinker drunk

#ifdef matured
#undef drinker


If a moderator could kindly move this thread to contest, i'd appreciate it
Last edited by Darryl on Fri Sep 09, 2005 11:07 am, edited 1 time in total.
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby Emery » Fri Sep 09, 2005 11:06 am

Darryl wrote:
RITZ wrote:
Darryl wrote:I was a drinker
#define drinker drunk

#ifdef matured
#undef drinker

fatal error C1004: unexpected end of file found

( =P j/k )

I'll probably participate in this one.
--~~~~
User avatar
Emery
 
Posts: 4313
Joined: Sat Mar 19, 2005 9:16 am

Postby Corsix » Fri Sep 09, 2005 11:17 am

So you'd say "buzz" on 7, 11, etc. and 17, 27, 73, 747 etc?

Also, when is respond called, and why does it need / what does it have in the argument?
Code: Select all
#include <stdio.h>
char*_="XxTIHRCXCxTIHRXRCxTIHXHRCxTIXIHRCxTXTIHRCxXxTIHRCX";
int main(int l){for(l+=7;l!=putchar(010);++l);if(*(++_))main
(*_!=88?(putchar(*_^073)|putchar(33))&1:0xffff2a8b);}
User avatar
Corsix
 
Posts: 1181
Joined: Fri Jul 23, 2004 9:33 am
Location: Berkeley, UK

Postby Darryl » Fri Sep 09, 2005 1:07 pm

Corsix wrote:So you'd say "buzz" on 7, 11, etc. and 17, 27, 73, 747 etc?

Also, when is respond called, and why does it need / what does it have in the argument?


reposnd is called on every turn for each player, if it's your turn then you repond accordingly, if not, with an empty string.

The arguement is the last response, basically the last number that was called

so if we are on 6 respond ("5") is what is called and if it's your turn you'd return "6" otherwise return ""

if we are on 8 respond("buzz") is called and the player whose turn it is returns "8" and everyone else returns ""

ps. to put it in terms of the real game, each player hears the reponses and any player can then repond if they think it's their turn. When you're drinking this poses much more of a problem. But the AI is not the focus of this contest, the brevity is.
Last edited by Darryl on Fri Sep 09, 2005 1:11 pm, edited 1 time in total.
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby Wizard » Fri Sep 09, 2005 1:08 pm

Also on multipls of 7 and 11, ie 14, 21, 22, 28, 33, 35
User avatar
Wizard
Site Admin
 
Posts: 3226
Joined: Mon Sep 22, 2003 4:52 pm
Location: ON, CA

Re: Beginners Brevity Contest: BUZZ

Postby Corsix » Fri Sep 09, 2005 1:51 pm

Darryl wrote:Your entry may not use any input files.
Yay - I got a new rule implemented :)
Code: Select all
#include <stdio.h>
char*_="XxTIHRCXCxTIHRXRCxTIHXHRCxTIXIHRCxTXTIHRCxXxTIHRCX";
int main(int l){for(l+=7;l!=putchar(010);++l);if(*(++_))main
(*_!=88?(putchar(*_^073)|putchar(33))&1:0xffff2a8b);}
User avatar
Corsix
 
Posts: 1181
Joined: Fri Jul 23, 2004 9:33 am
Location: Berkeley, UK

Postby exomo » Fri Sep 09, 2005 7:17 pm

I will enter this time. But I have to read some tutorials about inheritance first. I can't get my class to work :oops:
Who needs a signature anyway.
User avatar
exomo
 
Posts: 894
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Postby Darryl » Sat Sep 10, 2005 6:37 am

exomo wrote:I will enter this time. But I have to read some tutorials about inheritance first. I can't get my class to work :oops:


could be my fault, forgot to make methods public. fixed now.

Also, here is a test framework that's not a spoiler, it only test that your class works and not that it works right. I also include a sample class to show inheritence, but it is also not fully functional. To use the test, change the 2 lines that say change and remove the sample class.

[syntax="cpp"]
#include <string>
#include <sstream>
#include <iostream>

class player
{
public:
virtual std::string init(int player_position, int num_of_players)=0;
virtual std::string respond(std::string last_response)=0;
};

//#include your_file.hpp // <------------------- change

class sample_player:public player
{
public:
int counter;

sample_player():counter(1){}

std::string init(int player_position, int num_of_players)
{
return "sample";
}

std::string respond(std::string last_response)
{
std::stringstream ss;
ss << counter;
if (counter%7 != 0)
{
counter++;
return ss.str();
}
else
{
counter++;
return "buzz";
}

}


};

int main()
{
std::string prev_response = "";
std::string current_response;
int position = 1;
std::string player_name;

sample_player a_player; // < ------------------- change

player* ptr_player = &a_player;

player_name = ptr_player->init(1,1);

for (int a = 1; a<101;a++)
{
current_response = ptr_player->respond(prev_response);
std::cout << player_name << " : " << current_response << std::endl;
prev_response = current_response;
}

}
[/syntax]
User avatar
Darryl
 
Posts: 1342
Joined: Wed Sep 01, 2004 10:50 am
Location: Cayman Islands

Postby exomo » Sat Sep 10, 2005 7:57 am

32 C:\Dokumente und Einstellungen\Exomo\Eigene Dateien\Contests\buzz.cpp aggregate `std::stringstream ss' has incomplete type and cannot be defined
:?:

EDIT: My own class works now (it compiles, it doesn't do anything yet). I'm writing now my own testframe before I start working on the class itself^^
Who needs a signature anyway.
User avatar
exomo
 
Posts: 894
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Next

Return to Contests

Who is online

Users browsing this forum: No registered users and 1 guest