Snake priorities

  • Only add tail if not 100 health

Each direction is weighted by:

  • Possible head (high -)
  • Is food (High + if low on health, low - otherwise)
  • Towards food (low + if low on health, neutral otherwise)
  • Towards tail (high +)

Sort by weight and pick the best

int GetWeight(MoveFlags flags, bool hungry) {
  int weight = 0;
  if (Match(flags, MoveFlags.Head)) {
    weight -= 5;
  }
  if (Match(flags, MoveFlags.Food)) {
    weight += hungry ? 3 : -1;
  } else if (Match(flags, MoveFlags.FoodDirection) && hungry) {
    weight += 3;
  }
  if (Match(flags, MoveFlags.Tail)) {
    weight += 3
  } else if (Match(flags, MoveFlags.TailArea)) {
    weight += 2
  }
  return weight;
}