1.1 Shared
1.1.1 Location
1.1.2 Direction
1.1.3 Entity
1.1.4 Request
1.1.5 Reply
8.14
1.1.3 Entity🔗

Source code at entity.rkt

The game world is populated with entities. An entity has a unique identifier, a type, and a location.

(struct entity (id type location) #:prefab)

Bots are controlled by game clients, and can move around the world. Markets are places where items can be bought and sold. Blocks are passive, and can be picked up, carried, and dropped by bots. Edges are a special type, generated by the server, to show bots where the edge of the world is.

(define type-bot 0)
(define type-base 1)
(define type-block 2)
(define type-edge 3)

(define (make-edge location) (entity 0 type-edge location))

When a bot moves, it changes an entity location.

(test-case:
 "change entity location"
 (check-equal?
  (change-entity-location (entity 101 type-bot (location 1 2)) (location 3 4))
  (entity 101 type-bot (location 3 4))))

Structures are immutable by default, so we make a copy with the new location.

(define (change-entity-location source new-location)
  (struct-copy entity source [location new-location]))