Safe Haskell | Safe |
---|
Player
Description
This untrusted module implements the server side of a player, which communicates with its client side via TCP. When the server prompts the client for input, it uses "resign" as the quit message (see Command).
- data PlacingHandle
- data ShootingHandle
- placing :: Handle -> Bool -> DC PlacingHandle
- getComplete :: PlacingHandle -> DC (Maybe (Complete, ShootingHandle))
- data ShotResult
- shoot :: ShootingHandle -> DC (Maybe (Pos, ShotResult -> DC ()))
- opponentShot :: ShootingHandle -> Pos -> DC ()
- won :: ShootingHandle -> DC ()
- lost :: ShootingHandle -> DC ()
Documentation
data PlacingHandle
Placing handle for player -- handle for player during the placing phase of game.
data ShootingHandle
Shooting handle for player -- handle for player during the shooting phase of game.
placing :: Handle -> Bool -> DC PlacingHandle
returns a placing
clnt goFirstDC
action that, when run
with current label dcPublic
, starts up a new player, returning
its placing handle, and leaving the current label and clearance
unchanged. The player will use clnt
(which must have label
dcPublic
) to communicate with its client side, using the protocol
of Command, and will go (shoot) first iff goFirst
.
Note: all DC
actions derived from the placing handle via the
following functions must be run with current label dcPublic
. They
all leave the current label and clearance unchanged. In
particular, this applies to the DC
actions returned by the reply
functions produced by the DC
actions returned by the shoot
function -- see below.
getComplete :: PlacingHandle -> DC (Maybe (Complete, ShootingHandle))
returns a getComplete
phDC
action that, when run, waits
for the player corresponding to the placing handle ph
to finish
placing its ships. If the player resigns or terminates before
fully placing its ships, then the DC
action returns Nothing
;
otherwise, the DC
action returns
, where
Just
(compl, sh)compl
is the complete placing chosen by the player, and sh
is the shooting handle for the player. The DC
action returned by
calling getComplete
on a given placing handle may only be run
once.
data ShotResult
Shot results communicated to shooting player.
shoot :: ShootingHandle -> DC (Maybe (Pos, ShotResult -> DC ()))
returns a shoot
shDC
action that, when run, waits for
the player with shooting handle sh
to supply a value of type
, and then returns
this value.
Maybe
(Pos
, ShotResult
-> DC
())
- If
Nothing
is supplied, this means the player is resigning. - If
is returned, this means the player has chosen to shoot cellJust
(pos, shotFun)pos
of the opponent's board. The caller ofshoot
is then responsible for callingshotFun
with the value of typeShotResult
describing the outcome of this shot, and for then running theDC
action returned byshotFun
, thus communicating this outcome back to the player. (This must be done before any otherDC
actions associated withsh
are run.)
opponentShot :: ShootingHandle -> Pos -> DC ()
returns a opponentShot
sh posDC
action that, when
run, tells the player with shooting handle sh
that its
opponent has shot cell pos
of the player's board.
won :: ShootingHandle -> DC ()