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.
- 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
main.go: CLI entry pointutils/ParseFarm.go: input parsing and validationutils/FindPaths.go: path discovery and best path-set selectionutils/AssignAnts.go: ant-to-path distributionutils/Simulation.go: movement simulation and output printingutils/types.go: core data structures
- Go
1.23.2or later
go run . path/to/farm.txtYou can also build the binary first:
go build -o lem-in .
./lem-in path/to/farm.txtThe program expects a farm description file with:
- The number of ants on the first meaningful line
- Room definitions in the format:
name x y ##startfollowed by the start room##endfollowed 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-endThe program prints:
- The original input
- A blank line
- The ant movements turn by turn
Example movement line:
L1-room1 L2-room1- The parser reads and validates the farm file.
- The graph is built from rooms and bidirectional links.
- The solver estimates distances from the end room using breadth-first search.
- Candidate paths are collected and ranked.
- A compatible set of non-conflicting paths is selected.
- Ants are distributed across paths using a simple path-length-plus-load score.
- The simulation prints legal moves until all ants reach the end.
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