Skip to content

Instantly share code, notes, and snippets.

@rooklift
rooklift / katrain_accuracy.txt
Last active May 8, 2023 17:50
KaTrain accuracy statistic
For each move:
Generate a difficulty statistic for the position in which the move was made, as follows:
- For each candidate move (i.e. each entry in moveInfos) multiply the prior by the points the move
loses, which is the rootInfo scoreLead minus the moveInfo scoreLead, adjusted for colour if needed
and clamped so it's not less than 0.
- Sum the values produced in this manner (from all the moveInfos).
Generate a raw weight, as follows:
- Divide the difficulty stat by the sum of the moveInfos priors (usually this is close to 1; so

If your language can generate a standalone binary for Linux, probably you can use it for Lux. This little guide details what I learned writing a Golang bot for the competition.

It all starts with main.py

The first thing Lux will do when running your bot is run (or possibly import) main.py, a Python script which will call your bot as a subprocess. This script will pass your stdout to Lux, and will pass the game state each turn to your bot.

Various main.py scripts exist now in the official Lux kits. I recommend using the JavaScript kit's main.py (yes, it's a Python script in the JavaScript kit). This version of main.py has the useful property that it adjusts what Lux sends it slightly, producing a consistently-formatted input to your bot. All you have to do is edit it so that instead of running node as its subprocess, it runs your bot instead.

Input

Heavy Robot

  • Costs 100 metal (500 ore) and 500 power
  • Can carry 1000 resources
  • Can carry 3000 power, gaining 10 in daylight
  • Digs 20 (or destroys 100 lichen) - costs 60 power
  • Movement costs between [20,120]

Light Robot

"use strict";
const barker_props = {
bark() {
console.log(`Woof, I am ${this.name}`);
}
};
const meower_props = {
meow() {

Due to a bunch of stupid issues in C with autocasting, sensible ways of parsing network bytes into something like an int might not work as expected, for which see here:

https://justine.lol/endian.html

The solution is something like this (mutatis mutandis if the incoming thing is little endian).

https://news.ycombinator.com/item?id=27086482

uint32_t read32be(const uint8_t *p) {

The logical relations between Go scoring systems

What is the simplest Go scoring system? It's this:

  • Stone Scoring: just count the stones on the board

At the end of the game, both players will want to fill in as much of their own territory as they can, while allowing two eyes per group (so they aren't captured). Then the winner is just the player with more stones on the board. Note that prisoners are not counted.

But nobody wants to play all these extra stones at the end. So we can instead use:

@rooklift
rooklift / django_start.md
Last active February 28, 2016 21:51
Notes on starting a Django 1.9 project

Initialisation...

  • django-admin startproject site
  • python manage.py startapp appname

Views and URLs...

  • Edit appname/views.py
  • Edit appname/urls.py
  • Edit site/urls.py
@rooklift
rooklift / channel_test.go
Created February 20, 2016 19:01
Windows didn't like this at all
package main
import "fmt"
import "time"
var finalchan = make(chan time.Time)
func chain(n int, in chan time.Time) {
var out chan time.Time