swarm-0.7.0.0: 2D resource gathering game with programmable robots
LicenseBSD-3-Clause
Safe HaskellNone
LanguageHaskell2010

Swarm.Game.Robot

Description

A data type to represent robots.

Synopsis

Robots data

_robotID :: RobotR phase -> RobotID phase Source #

_robotLocation :: RobotR phase -> RobotLocation phase Source #

type family RobotMachine (phase :: RobotPhase) Source #

Instances

Instances details
type RobotMachine 'TemplateRobot Source # 
Instance details

Defined in Swarm.Game.Robot

_machine :: RobotR phase -> RobotMachine phase Source #

type family RobotActivity (phase :: RobotPhase) Source #

Instances

Instances details
type RobotActivity 'TemplateRobot Source # 
Instance details

Defined in Swarm.Game.Robot

type family RobotLogMember (phase :: RobotPhase) Source #

Instances

Instances details
type RobotLogMember 'TemplateRobot Source # 
Instance details

Defined in Swarm.Game.Robot

type family RobotLogUpdatedMember (phase :: RobotPhase) Source #

Instances

Instances details
type RobotLogUpdatedMember 'TemplateRobot Source # 
Instance details

Defined in Swarm.Game.Robot

Robots

data RobotPhase Source #

The phase of a robot description record.

Constructors

TemplateRobot

The robot record has just been read in from a scenario description; it represents a template that may later be instantiated as one or more concrete robots.

ConcreteRobot

The robot record represents a concrete robot in the world.

type RID = Int Source #

A unique identifier for a robot.

data RobotR (phase :: RobotPhase) Source #

A value of type RobotR is a record representing the state of a single robot. The f parameter is for tracking whether or not the robot has been assigned a unique ID.

Instances

Instances details
FromJSONE TerrainEntityMaps TRobot Source #

We can parse a robot from a YAML file if we have access to an EntityMap in which we can look up the names of entities.

Instance details

Defined in Swarm.Game.Robot

Generic (RobotR phase) Source # 
Instance details

Defined in Swarm.Game.Robot

Associated Types

type Rep (RobotR phase) 
Instance details

Defined in Swarm.Game.Robot

type Rep (RobotR phase)

Methods

from :: RobotR phase -> Rep (RobotR phase) x #

to :: Rep (RobotR phase) x -> RobotR phase #

(Show (RobotLocation phase), Show (RobotID phase), Show (RobotMachine phase), Show (RobotActivity phase), Show (RobotLogMember phase), Show (RobotLogUpdatedMember phase)) => Show (RobotR phase) Source # 
Instance details

Defined in Swarm.Game.Robot

Methods

showsPrec :: Int -> RobotR phase -> ShowS #

show :: RobotR phase -> String #

showList :: [RobotR phase] -> ShowS #

(Eq (RobotLocation phase), Eq (RobotID phase), Eq (RobotMachine phase), Eq (RobotActivity phase), Eq (RobotLogMember phase), Eq (RobotLogUpdatedMember phase)) => Eq (RobotR phase) Source # 
Instance details

Defined in Swarm.Game.Robot

Methods

(==) :: RobotR phase -> RobotR phase -> Bool #

(/=) :: RobotR phase -> RobotR phase -> Bool #

FromJSONE (TerrainEntityMaps, RobotMap) Cell

Parse a tuple such as [grass, rock, base] into a Cell. The entity and robot, if present, are immediately looked up and converted into Entity and TRobot values. If they are not found, a parse error results.

Instance details

Defined in Swarm.Game.Scenario.Topography.Cell

type Rep (RobotR phase) Source # 
Instance details

Defined in Swarm.Game.Robot

type Rep (RobotR phase)

type Robot = RobotR 'ConcreteRobot Source #

A concrete robot, with a unique ID number and a specific location.

type TRobot = RobotR 'TemplateRobot Source #

A template robot, i.e. a template robot record without a unique ID number, and possibly without a location.

Lenses

robotEntity :: forall (phase :: RobotPhase) f. Functor f => (Entity -> f Entity) -> RobotR phase -> f (RobotR phase) Source #

Robots are not entities, but they have almost all the characteristics of one (or perhaps we could think of robots as very special sorts of entities), so for convenience each robot carries an Entity record to store all the information it has in common with any Entity.

Note there are various lenses provided for convenience that directly reference fields inside this record; for example, one can use robotName instead of writing robotEntity . entityName.

robotName :: Lens' Robot Text Source #

The name of a robot.

trobotName :: Lens' TRobot Text Source #

The name of a robot template.

unwalkableEntities :: Lens' Robot (WalkabilityExceptions EntityName) Source #

Entities that the robot cannot move onto

robotCreatedAt :: Lens' Robot TimeSpec Source #

The creation date of the robot.

robotDisplay :: Lens' Robot Display Source #

The Display of a robot. This is a special lens that automatically sets the curOrientation to the orientation of the robot every time you do a get operation. Technically this does not satisfy the lens laws---in particular, the get/put law does not hold. But we should think of the curOrientation as being simply a cache of the displayed entity's direction.

robotLocation :: Getter Robot (Cosmic Location) Source #

The robot's current location, represented as (x,y). This is only a getter, since when changing a robot's location we must remember to update the robotsByLocation map as well. You can use the updateRobotLocation function for this purpose.

unsafeSetRobotLocation :: Cosmic Location -> Robot -> Robot Source #

Set a robot's location. This is unsafe and should never be called directly except by the updateRobotLocation function. The reason is that we need to make sure the robotsByLocation map stays in sync.

trobotLocation :: Lens' TRobot (Maybe (Cosmic Location)) Source #

A template robot's location. Unlike robotLocation, this is a lens, since when dealing with robot templates there is as yet no robotsByLocation map to keep up-to-date.

robotOrientation :: Lens' Robot (Maybe Heading) Source #

Which way the robot is currently facing.

robotInventory :: Lens' Robot Inventory Source #

The robot's inventory.

trobotInventory :: Lens' TRobot Inventory Source #

A robot template's inventory.

equippedDevices :: Lens' Robot Inventory Source #

A separate inventory for equipped devices, which provide the robot with certain capabilities.

Note that every time the inventory of equipped devices is modified, this lens recomputes a cached set of the capabilities the equipped devices provide, to speed up subsequent lookups to see whether the robot has a certain capability (see robotCapabilities)

tequippedDevices :: Getter TRobot Inventory Source #

A robot template's equipped devices.

inventoryHash :: Getter Robot Int Source #

A hash of a robot's entity record and equipped devices, to facilitate quickly deciding whether we need to redraw the robot info panel.

robotCapabilities :: Getter Robot (MultiEntityCapabilities Entity EntityName) Source #

Get the set of capabilities this robot possesses. This is only a getter, not a lens, because it is automatically generated from the equippedDevices. The only way to change a robot's capabilities is to modify its equippedDevices.

robotID :: Getter Robot RID Source #

The (unique) ID number of the robot. This is only a Getter since the robot ID is immutable.

robotParentID :: Lens' Robot (Maybe RID) Source #

The ID number of the robot's parent, that is, the robot that built (or most recently reprogrammed) this robot, if there is one.

robotHeavy :: Lens' Robot Bool Source #

Is this robot extra heavy (thus requiring tank treads to move)?

systemRobot :: Lens' Robot Bool Source #

Is this robot a "system robot"? System robots are generated by the system (as opposed to created by the user) and are not subject to the usual capability restrictions.

selfDestruct :: Lens' Robot Bool Source #

Does this robot wish to self destruct?

runningAtomic :: Lens' Robot Bool Source #

Is the robot currently running an atomic block?

Creation & instantiation

mkRobot Source #

Arguments

:: Maybe Int 
-> Text

Name of the robot.

-> Document Syntax

Description of the robot.

-> Maybe (Cosmic Location)

Initial location.

-> Heading

Initial heading/direction.

-> Display

Robot display.

-> Maybe TSyntax

Initial CESK machine.

-> [Entity]

Equipped devices.

-> [(Count, Entity)]

Initial inventory.

-> Bool

Should this be a system robot?

-> Bool

Is this robot heavy?

-> WalkabilityExceptions EntityName

Unwalkable entities

-> TimeSpec

Creation date

-> TRobot 

A general function for creating robots.

Query

robotKnows :: Robot -> Entity -> Bool Source #

Does a robot know of an entity's existence?

Constants