1.3 The Code
1.3.3 Server
1.3.3.1 Sequence
1.3.3.2 Board
1.3.3.3 Places
1.3.3.4 Engine
1.3.3.5 Background
1.3.3.6 Draw
1.3.3.7 Setup
1.3.3.8 Agent
1.3.3.9 Interval
1.3.3.10 Dispatcher
1.3.3.11 TCP Server
8.14
1.3.3.7 Setup🔗

Source code at setup.rkt

Setup creates an engine and populates it with blocks, and creates bots for a player.

(define (setup-engine)
  (make-engine 80 45))
(define (add-random-location engine entity-type)
  (let ([new-entity (add-entity engine entity-type (random-location (engine-board engine)))])
    (if new-entity
        new-entity
        (add-random-location engine entity-type))))
(define (setup-server engine)
  (for ([i 25])
    (add-random-location engine type-block))
  (thread (λ () (background engine)))
  #t)

To set up bots, a base is created in a random location. The bots are added at locations adjacent to the base.

(define (setup-bots engine)
  (let ([base-location (random-base (engine-board engine)
                               (λ (x) (available? engine x)))])
    (add-entity engine type-base base-location)
    (for/list ([location (all-directions base-location)])
      (add-entity engine type-bot location))))