Problem #231
Tags:
special
games
challenge
arena
c-0
scheme
This task has a Challenge attached.
You may
View Stats
or read a Help on Challenges.
Wow! there is also Arena
for this challenge!
This game is described by Jacques Arsac in his "Programming of Games and Puzzles", while he references J-C Baillif as author.
We want some simple game yet allowing basic strategy, to introduce and test our new "Arena" feature. Solution
should be in Scheme
so feel free to try Introducing Scheme if you haven't yet.
Two players are throwing single die in turns. On every turn player can cast die more than once, summing up
the score for this turn - until he/she decides to pass the turn to the opponent - or the value 1
is thrown.
If turn is passed voluntarily, sum score for this turn is added to player's total. However if turn ended with
getting 1
, score for the turn is nullified (nothing is added to total).
Winner is one who first reaches total of 100
.
Game example:
6, 3, 5
and stops (her total becomes 14
)2, 4, 4, 3, 2
and stops (his total becomes 15
)4, 1
and loses the turn (her total remains 14
)2 6
and stops (his total becomes 23
)6, 6, 5
and stops (her total becomes 31
)1
and loses the turn (his total remains 23
)Write function in Scheme
which implements some strategy for playing this game. Function should be named
player
and have 5 arguments:
(define (player my-total other-total accum current state)
...
)
Function is called after every throw and should return #t
or #f
depending on whether you want to continue
throwing in current turn or not. If you have just thrown 1
, then your turn ends anyway (return value is ignored).
Parameters to this function are:
my-total
- current total (score for previous turns) for "your" playerother-total
- opponent's totalaccum
- sum for previous throws of the current turn (zero on the first throw of a turn)current
- the latest throw (value on a die) of your current turnstate
- this is a single-value list which you can use to store (e.g. with set-car!
) info between calls,
as accessing global variables is not guaranteed.So, for example, second turn by Anna in the example above will call your function with arguments 14, 15, 0, 4 (...)
first, then 14, 15, 4, 1 (...)
and her turn ends involuntarily.
Your code shouldn't print anything. Your function will be used by checker to conduct match of 49
games against dummy player (quite simpleton strategy). To pass the check you need win 25
or more games.
Trivial "player" function would be like this:
; coward strategy - it never asks to continue
; thus slowly accumulating score with 1-throw turns
; obviously it needs not examine any of its parameters
(define (player my-total other-total accum current state)
#f)
You can also grab "playable" code with one "interactive" player, to experiment with your solution - here.
Amount of games won determines your challenge score (25
gives score of 0.04
while 49
gives score of 1.00
).
Main feature, however, is "Arena" - you can visit it by the link somewhere above and try your strategy against
those submitted by other players. In "Arena" you also participate in match of 49
games agains opponent you
chose. In both cases your code becomes "second" player in the first game - and then sides swap for every next
game (so you play 25 games as "second" and 24 as "first").