Skip to content

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lem-in

Lem-in is a Go implementation of the classic ant farm pathfinding project. It parses a farm description, validates rooms and links, finds efficient non-overlapping paths from ##start to ##end, assigns ants across those paths, and prints the turn-by-turn simulation.

This repository is useful for anyone looking for a Go lem-in solver, ant colony pathfinding project, graph traversal example in Go, or a 42/1337 lem-in style implementation.

Features

  • Parses farm files from disk
  • Validates ant count, rooms, links, ##start, and ##end
  • Rejects malformed input and duplicate room/link definitions
  • Computes candidate paths through the farm graph
  • Chooses compatible paths that do not overlap on intermediate rooms
  • Assigns ants to the most efficient paths
  • Simulates movements turn by turn while respecting room and tunnel constraints
  • Prints the original input followed by the generated solution

Project Structure

  • main.go: CLI entry point
  • utils/ParseFarm.go: input parsing and validation
  • utils/FindPaths.go: path discovery and best path-set selection
  • utils/AssignAnts.go: ant-to-path distribution
  • utils/Simulation.go: movement simulation and output printing
  • utils/types.go: core data structures

Requirements

  • Go 1.23.2 or later

Run

go run . path/to/farm.txt

You can also build the binary first:

go build -o lem-in .
./lem-in path/to/farm.txt

Input Format

The program expects a farm description file with:

  • The number of ants on the first meaningful line
  • Room definitions in the format: name x y
  • ##start followed by the start room
  • ##end followed by the end room
  • Links in the format: room1-room2
  • Optional comments beginning with #

Example:

4
##start
start 0 0
room1 1 0
room2 2 0
##end
end 3 0
start-room1
room1-room2
room2-end

Output

The program prints:

  1. The original input
  2. A blank line
  3. The ant movements turn by turn

Example movement line:

L1-room1 L2-room1

How It Works

  1. The parser reads and validates the farm file.
  2. The graph is built from rooms and bidirectional links.
  3. The solver estimates distances from the end room using breadth-first search.
  4. Candidate paths are collected and ranked.
  5. A compatible set of non-conflicting paths is selected.
  6. Ants are distributed across paths using a simple path-length-plus-load score.
  7. The simulation prints legal moves until all ants reach the end.

Error Handling

The program reports errors such as:

  • unreadable input files
  • invalid ant counts
  • missing start or end rooms
  • duplicate rooms or links
  • malformed room or link lines
  • links that reference unknown rooms
  • invalid overall farm structure

About

Go implementation of the classic ant farm pathfinding project

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages