[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[QUIZ] GOPS (#116

James Gray

3/2/2007 1:35:00 PM

The three rules of Ruby Quiz:

1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.

2. Support Ruby Quiz by submitting ideas as often as you can:

http://www.rub...

3. Enjoy!

Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone
on Ruby Talk follow the discussion. Please reply to the original quiz message,
if you can.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

by Christoffer Lerno

GOPS, the Game of Pure Strategy (a.k.a Goofspiel), is a very simple cardgame.

In GOPS, one suit is singled out as "competition suit" and each of the remaining
suits becomes the hand for a player (with one suit discarded if there are only
two players). The competition suit is shuffled and placed face down.

Game starts by turning up the top card in the competition stack. The players
then make a hidden bid on the card, using one of their own cards. Once all
players have made a bid, the cards are revealed and the player with the highest
card collects the competition card. In case of a tie, the competition card is
discarded.

The game then proceeds in the same manner until the competition stack is empty.

The winner is the player with the highest number of points calculated from the
competition cards won, where Ace is the lowest--worth 1 point--and King is the
highest--worth 13 points.

The task for this quiz is to write a bot to play 2-player GOPS against other
bots.

A bot needs to be able to read gameplay on STDIN and write its moves to STDOUT
using the following protocol:

1. The engine sends the first competition card as the string "Competition
card: CARD", where CARD is the value of the card, from 1 (Ace) to 13
(King).

Example: The server would write "Competition card: 12" if the competition
card for this round was Queen of the competition suit.

2. The engine then expects a response within 30 seconds. The response should
be the value of the card you wish to play as a string. You may only play
each card in your suit once, of course.

Example: The bot could print the line "10" to STDOUT (and flush output)
to bid with a ten.

3. The engine will respond by sending the card the opponent just played as
the string "Opponent's bid: CARD" where CARD is the value of the bid
(1-13).

Example, the engine would print "Opponent's bid: 3" if the opponent bid
a 3 in the last round. This tells you that your 10 beat the opponent's
3 and you won the Queen.

4. Return to 1 with the next card in the competition stack, until all 13
cards have been played.

Here is a very simple random bot implementing the protocol:

(1..13).sort_by { rand }.each do |card|
$stdin.gets # competition card--ignored
$stdout.puts card
$stdout.flush
$stdin.gets # opponent's play--ignored
end

A GOPS engine and some trivial bots are available for you to use in testing your
strategies:

http://rubyquiz.co...

17 Answers

Robert Dober

3/2/2007 3:19:00 PM

0

On 3/2/07, Ruby Quiz <james@grayproductions.net> wrote:
> The three rules of Ruby Quiz:
>
>
Maybe I missed something, but I needed to
add

$:.unshift( File.join( "..", "lib" ))
on top of test/ts_all.rb

Robert

In fact, in some ways, we are more confused than ever.
But we feel we are confused on a higher level and about more important things.
-Anonymous

James Gray

3/2/2007 3:25:00 PM

0

On Mar 2, 2007, at 9:19 AM, Robert Dober wrote:

> On 3/2/07, Ruby Quiz <james@grayproductions.net> wrote:
>> The three rules of Ruby Quiz:
>>
>>
> Maybe I missed something, but I needed to
> add
>
> $:.unshift( File.join( "..", "lib" ))
> on top of test/ts_all.rb

Sure, you can do that.

You can do that when you invoke a test too:

$ ruby -I lib:test test/...

I just use the provided Rakefile:

$ rake

James Edward Gray II


Robert Dober

3/2/2007 3:29:00 PM

0

On 3/2/07, James Edward Gray II <james@grayproductions.net> wrote:
> On Mar 2, 2007, at 9:19 AM, Robert Dober wrote:
>
> > On 3/2/07, Ruby Quiz <james@grayproductions.net> wrote:
> >> The three rules of Ruby Quiz:
> >>
> >>
> > Maybe I missed something, but I needed to
> > add
> >
> > $:.unshift( File.join( "..", "lib" ))
> > on top of test/ts_all.rb
>
> Sure, you can do that.
>
> You can do that when you invoke a test too:
>
> $ ruby -I lib:test test/...
>
> I just use the provided Rakefile:
>
> $ rake
>
> James Edward Gray II
>
Ok sorry no rake on my machine I am ashamed :(
--
We have not succeeded in answering all of our questions.
In fact, in some ways, we are more confused than ever.
But we feel we are confused on a higher level and about more important things.
-Anonymous

Raj Sahae

3/2/2007 8:38:00 PM

0

Do we construct the bot to play against one opponent or two?
If we add an option that allows for a 3 player game, in what order do we
recieve the opponents played cards?

Raj

James Gray

3/2/2007 9:05:00 PM

0

On Mar 2, 2007, at 2:37 PM, Raj Sahae wrote:

> Do we construct the bot to play against one opponent or two?

This quiz focuses on just two players...

> If we add an option that allows for a 3 player game, in what order
> do we recieve the opponents played cards?

Mainly for this reason. Let's keep things simple.

Feel free to add a bin/tournement script though that runs a series of
games among more than two players...

James Edward Gray II

Robert Dober

3/2/2007 10:18:00 PM

0

On 3/2/07, James Edward Gray II <james@grayproductions.net> wrote:
> On Mar 2, 2007, at 2:37 PM, Raj Sahae wrote:
>
> > Do we construct the bot to play against one opponent or two?
>
> This quiz focuses on just two players...
>
> > If we add an option that allows for a 3 player game, in what order
> > do we recieve the opponents played cards?
>
> Mainly for this reason. Let's keep things simple.
>
> Feel free to add a bin/tournement script though that runs a series of
> games among more than two players...
>
> James Edward Gray II
>
>
I just wondered if it might not be a good idea to shorten the Spoiler
Period this time; if I have more BOTs to play against maybe I could
improve mine, but I am aware that looking at the code of the other
BOTs is spoiling the fun too, hmmm, I do not know, maybe everyone
could decide for oneself?

What you think James?

Robert


--
We have not succeeded in answering all of our questions.
In fact, in some ways, we are more confused than ever.
But we feel we are confused on a higher level and about more important things.
-Anonymous

James Gray

3/2/2007 10:26:00 PM

0

On Mar 2, 2007, at 4:18 PM, Robert Dober wrote:

> I just wondered if it might not be a good idea to shorten the Spoiler
> Period this time; if I have more BOTs to play against maybe I could
> improve mine, but I am aware that looking at the code of the other
> BOTs is spoiling the fun too, hmmm, I do not know, maybe everyone
> could decide for oneself?
>
> What you think James?

I think we should keep the spoiler period. Give people some time to
build some tough bots. We will still have a few days after it.

Feel free to swap bots with a buddy off-list though, if you want to
start working against someone else sooner.

James Edward Gray II

Christoffer Lernö

3/2/2007 10:27:00 PM

0

On Mar 2, 2007, at 23:18 , Robert Dober wrote:

> I just wondered if it might not be a good idea to shorten the Spoiler
> Period this time; if I have more BOTs to play against maybe I could
> improve mine, but I am aware that looking at the code of the other
> BOTs is spoiling the fun too, hmmm, I do not know, maybe everyone
> could decide for oneself?

Well the tricky part with this quiz is that if you want to make sure
you have a strong bot you have to invent strong bots for it to
compete with. Just making a bot that beat all other bots is no
problem if you know how they play...

/C


James Gray

3/2/2007 10:31:00 PM

0

On Mar 2, 2007, at 4:27 PM, Christoffer Lernö wrote:

> On Mar 2, 2007, at 23:18 , Robert Dober wrote:
>
>> I just wondered if it might not be a good idea to shorten the Spoiler
>> Period this time; if I have more BOTs to play against maybe I could
>> improve mine, but I am aware that looking at the code of the other
>> BOTs is spoiling the fun too, hmmm, I do not know, maybe everyone
>> could decide for oneself?
>
> Well the tricky part with this quiz is that if you want to make
> sure you have a strong bot you have to invent strong bots for it to
> compete with. Just making a bot that beat all other bots is no
> problem if you know how they play...

That might be a good case for solving this one using an evolution
algorithm to grow smarter players. Anyone trying that?

James Edward Gray II

Raj Sahae

3/2/2007 10:35:00 PM

0


>
> Well the tricky part with this quiz is that if you want to make sure
> you have a strong bot you have to invent strong bots for it to compete
> with. Just making a bot that beat all other bots is no problem if you
> know how they play...
Well then, once you've played your bot against the other weaker bots out
there, start playing the bot against itself.