swarm-game / swarm

Resource gathering + programming game
Other
835 stars 52 forks source link

Opaque robot type #212

Closed byorgey closed 2 years ago

byorgey commented 2 years ago

Currently, all commands which need to identify a robot (e.g. install, give, reprogram) take a string identifying the robot by name. We also store robots by name internally in the robotMap. However, this has several disadvantages: it's not very type safe (for example, are you supposed to give "base" "tree" or give "tree" "base"? And if you misspell the name of a robot, it fails at runtime instead of typechecking time), and necessitates frequent, relatively costly string comparisons.

The basic idea is to add a new type robot which is opaque to the user but is internally represented by Int. Here are my current thoughts:

polux commented 2 years ago

What should parent return if the parent no longer exists? Should it return a handle to a non-existent robot or should it fail immediately?

byorgey commented 2 years ago

I think it would be safe to return a handle to a non-existent robot (but I could be convinced otherwise). We would just have to make sure that robot handles are never reused, but that should be easy.

byorgey commented 2 years ago

I don't think it should fail immediately if the parent doesn't exist. That would provide a way to instantly communicate a bit of information over any distance. =)

xsebek commented 2 years ago

I would also like to have some function for robots to detect each other in the wild - say meet : cmd (() + robot). :robot:

byorgey commented 2 years ago

Agreed! meet : cmd (() + robot) sounds great. I presume if there is more than one robot there, you just get an arbitrary one? Maybe later there could be a meetAll : cmd (list (robot)).