The three rules of Ruby Q.:
-
Please do not post any solutions or spoiler discussion for this quiz
until
48 hours have passed from the time on this message. -
Support Ruby Q. by submitting ideas as often as you can:
- Enjoy!
Suggestion: A [QUIZ] in the subject of emails about the problem helps
everyone
on Ruby T. 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:
-
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. -
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. -
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. -
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: