Safe Haskell | None |
---|---|
Language | Haskell98 |
Game.Spacegoo
Description
This module provides you with everything to quicky write clients for the
GPN13 Spacegoo programming contest. Essentially you write a function of type
Strategy
that takes the State
and may return a Move
. If you pass such
a function to clients
, you are good to go. See the examples section for
some examples.
- type PlayerId = Int
- type Round = Int
- type Units = (Int, Int, Int)
- type Coord = (Int, Int)
- data Player = Player {}
- data Fleet = Fleet {}
- data Planet = Planet {
- planetId :: Int
- position :: Coord
- planetOwner :: PlayerId
- production :: Units
- planetShips :: Units
- data State = State {}
- type Move = Maybe (Int, Int, Units)
- type Strategy = State -> Move
- client :: Int -> String -> String -> String -> Strategy -> IO ()
- me :: State -> Int
- he :: State -> Int
- opponentName :: State -> Text
- battle :: Units -> Units -> (Bool, Units)
- winsAgainst :: Units -> Units -> Bool
- distance :: Planet -> Planet -> Int
- hasMore :: Units -> Units -> Bool
- ownerAt :: State -> Int -> Round -> (PlayerId, Units)
- linInt :: Double -> Units -> Units -> Units
- nemesisOf :: Units -> Units
- minimizeUnits :: Units -> Units -> Units
- nop :: Strategy
- attackNeutral :: Strategy
- sendSomewhere :: Strategy
- intercept :: Strategy
The state
type Units = (Int, Int, Int) Source
Units, either on a planet, on a fleet, or as a production indication.
Constructors
Fleet | |
Constructors
Planet | |
Fields
|
Constructors
State | |
Moves
type Move = Maybe (Int, Int, Units) Source
A Move contains the id of a source planet, the id or a target planet, and the number of ships to send
Writing clients
Arguments
:: Int | Port |
-> String | Hostname |
-> String | Username |
-> String | Passwort |
-> Strategy | Your strategy |
-> IO () |
This is your main entry point to play one round of the game.
Utilities
opponentName :: State -> Text Source
The opponent's name; to filter out known bad opponents
battle :: Units -> Units -> (Bool, Units) Source
Whether the first argument wins against the second, and how many ships are left
winsAgainst :: Units -> Units -> Bool Source
Whether the first fleet wins against the second (defaulting to the second)
hasMore :: Units -> Units -> Bool Source
Whether the first player has at least as many ships as the other
ownerAt :: State -> Int -> Round -> (PlayerId, Units) Source
Predict the owner and strength of the planet at the given round
minimizeUnits :: Units -> Units -> Units Source
Example strategies
attackNeutral :: Strategy Source
Picks an own planet with a reasonable number of ships and sends it to some neutral planet.
sendSomewhere :: Strategy Source
From any own planet, send all ships to any opposing planet.