A paddle is a little like a racket.
Paddle is a microworld. This means that Paddle lets you simulate the world around you. However, the world is a very big place. Therefore, it is best to think of Paddle as a set of tools for simulating a small part of the world: you’re going to have to make some assumptions, approximate here and there, and in the end, you’ll have a model of the world that lets you explore some idea.
Paddle is not the first microworld, nor is it the only. It is inspired heavily by NetLogo. NetLogo provides a way to write code for simulating everything from intrepid turtles to flocking birds to viral epidemics. Paddle borrows language and ideas from NetLogo (for consistency) and implements them in Racket.
Here is an example of a paddle that randomly distributes turtles around the world, and then sets them moving in a straight line.
#lang racket (require paddle) (make-world 100 600) (create-breed turtle turtles) (create turtles 100) (define (setup) (ask turtles (set turtle-x (random (get global world-columns))) (set turtle-y (random (get global world-rows))) (set turtle-direction (random 360)) )) (define (go) (ask turtles (move 1)) ;; Slow the turtles down! (sleep (/ 1 20)) ) (run-world setup go)
What follows is a brief walkthrough of the example.
If you want to create a Paddle world, you need to first require the paddle package.
Next, we need to create the world. The world is made up of patches, which can be thought of like a checkerboard. Turtles wander over these patches, and can (if they wish) interact with those patches.
(make-world 100 600)
make-world is a function that, in its simplest form, takes one parameter. This defines the number of columns and rows of patches in the world—
In microworlds, simulated creatures are most often referred to as agents. In NetLogo, they often refer to them as turtles; this is because, in the programming language Logo, the "turtle" plays a prominent role (and NetLogo is descended from Logo). I personally like the idea of turtles everywhere, so I will generally use the word turtles to mean computational agents that wander around and interact with the world and other agents in a simulated environment.
Next, we need to declare a new breed of agents in our microworld; I’ll choose to declare my agents to be turtles. I need to give both the singular and plural form for this new breed of agent. I then create 100 turtles in the world.
(create-breed turtle turtles) (create turtles 100)
To run our microworld, we need to provide two functions: setup and go. The setup function is used once when our world is created, and go is used over-and-over. Inside the go function, we wiggle and move our turtles, and after the function is run, the world is redrawn to reflect the changes in our turtles and the world around them.
(define (setup) (ask turtles (set xcor (random (get global world-columns))) (set ycor (random (get global world-rows))) (set direction (random 360)))) (define (go) (ask turtles (move 1)) (sleep (/ 1 20))) (run-world setup go)
The set and get forms are borrowed from NetLogo. set will set a value for the current agent that is being asked to do things. Likewise, when we say get, we will retrieve a value from the current agent. It is possible to set and retrieve values for a patch or for the global environment as well.
The setup function asks all of the turtles to do three things. First, we set the xcor, or x-coordinate, of each turtle to a random value between zero and the number of columns in the world. Then, we randomize the y-coordinate in the same way; this has the effect of scattering turtles around the world. Lastly, I set the turtle’s direction so each turtle has a randomized heading.
In go, I ask turtles to move forward one patch. (In a world that is 100x100, a move of 1 is 1/100th of the distance across the world.)
Finally, the setup and go functions are handed off to the run-world function, which then does a bunch of work behind the scenes. Along the way, it runs the setup function once, and go function over-and-over, with a 1/20th of a second pause between frames, which is determined by sleep; leaving out the pause will let the simulation run as fast as possible.
This package is under active development. Conversation and collaboration are welcome. Next steps include integrating plotting and logging, additional interface forms, and completing documentation. As of January 1, 2019, things are stabilizing, and documentation will follow. Currently, I am implementing examples so as to find where the environment does, and does not, work as a microworld.
I am currently making notes and tracking "to do" type items through a combination of the GitHub ticket queue and a Trello board. If you’re interested in contributing (examples, core language/API, optimizations), please feel free to reach out via email, make a pull request, etc.