swarm-game / swarm

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

Code golf scoring #866

Closed kostmo closed 1 year ago

kostmo commented 1 year ago

It would be fun to keep track of the "best" solution in terms of code size.

The code size might be determined by summing all of the REPL executions plus all transitive inclusions of code (include or run).

To discourage short variable names, it may be best to use "symbol count" rather than "character count" as the metric.

byorgey commented 1 year ago

symbol count

Or number of AST nodes.

byorgey commented 1 year ago

Personally, I enjoy trying to optimize character count, but tastes vary.

kostmo commented 1 year ago

trying to optimize character count

That can be fun, but I think there's more challenge in crafting a parsimonious program structure than shrinking variable names. I recognize appeal of finding out in which circumstances whitespace or semicolons are optional as well.

Perhaps we can track both AST node count and character count as metrics?

byorgey commented 1 year ago

Perhaps we can track both AST node count and character count as metrics?

Sure, why not? :smile: I agree, both are fun for different reasons. One is about finding elegant program structures, as you say, and one is about pushing a language to its limits.

xsebek commented 1 year ago

This sounds fun and should be easy to add to current best score. đź‘Ť

I think it needs an “automated mode” where you can not cancel your solution and start writing in REPL. 🤔 Once that computation finishes you have either won or failed (new state) and can leave or continue experimenting, now with REPL.

byorgey commented 1 year ago

I think it needs an “automated mode” where you can not cancel your solution and start writing in REPL.

I don't think I understand - what's the motivation?

xsebek commented 1 year ago

@byorgey well if you could continue in REPL, then an empty solution would be always shortest and then just finish it in REPL.

byorgey commented 1 year ago

I thought the idea was to count all things typed at the REPL plus anything run.

xsebek commented 1 year ago

But that way its always more efficient to type in REPL and step through.

For example the sheep solution would not have to wait for wool to drop, if the player waits for it.

I.e. the “solution” would not have to be full, which is OK, but different from other code golf challenges.

xsebek commented 1 year ago

Also if you wanted to count REPL, you would have to do it at each command because of run.

Counting once is much simpler and would not litter the codebase.

byorgey commented 1 year ago

Ah, I think I see your point now. It's also harder to share short solutions if they require typing multiple things at the REPL. I agree, to keep things simple and consistent we should probably just score a single .sw file (+ transitive imports) when counting length.

kostmo commented 1 year ago

Perhaps for now, one shall only be qualified for code golf scoring when using the --run CLI option. Any repl commands entered before the goal is reached shall disqualify the attempt.

xsebek commented 1 year ago

Maybe we could allow either —run or one REPL entry. 🤔

Then we could have states NoEntry, EntryWithLength and MoreEntries. If you finish the game with second state, it’s considered for shortest solution.

kostmo commented 1 year ago

I wonder if it might be interesting to have constraints on the "stored code size" of a robot for a challenge. Perhaps by default all built robots have an "infinite memory bank", but we could define a "finite memory bank" entity. Perhaps possessing many of these entities avails the robot to some multiple of AST nodes.