A high-performance Go-based algorithm implementation that solves OneTDraw puzzles - graph traversal puzzles where edges must be visited exactly once. This project was created as a collaborative challenge between @adarqui and @wricardo, inspired by the iPhone game "One T Draw".
- High-Performance Solver: Uses concurrent goroutines with recursive backtracking to explore all possible solutions
- Web Interface: Interactive canvas-based puzzle visualization and solving
- Multiple Output Formats: Clean text or JSON output
- Flexible Puzzle Format: JSON-based puzzle definition with support for directional constraints
- Comprehensive Test Suite: Built with benchmarking capabilities
The solver uses parallel goroutines to simultaneously explore all possible starting points in a graph. Each goroutine performs depth-first search with backtracking to find valid paths that traverse all edges exactly as specified. Solutions are collected thread-safely and deduplicated before output.
This is a GOPATH-style Go project. Clone and run:
git clone https://github.com/wricardo/OneTDraw-Solver.git
cd OneTDraw-Solver
go get -d ./...Start the web server to visualize and solve puzzles interactively:
go run main.go
# Server starts on http://localhost:8090Solve a specific puzzle file:
# Solve and show all solutions
go run main.go -solve puzzles/house.json
# Count solutions only
go run main.go -solve puzzles/house.json -count_only
# JSON output format
go run main.go -solve puzzles/house.json -output json
# Limit CPU usage (disable multi-core processing)
go run main.go -maxprocs=falsePuzzles are defined in JSON format with points and edges:
{
"Points": [
{"Point": 1, "Level": 1},
{"Point": 2, "Level": 2}
],
"Edges": [
{
"PointA": 1,
"PointB": 2,
"Count": 1,
"Direction": "optional_constraint"
}
]
}Points: Graph vertices with optional level information for visualizationEdges: Connections between pointsCount: Number of times the edge must be traversedDirection: Optional unidirectional constraint
The repository includes various puzzle examples in the puzzles/ directory:
house.json- Classic house drawing puzzleregular_triangle.json- Simple trianglejamaican_flag.json- Flag patternlevel53.jsonthroughlevel57.json- Game levels
# Run tests
go test ./solver
# Run benchmarks
go test -bench=. ./solver# Format and fix imports
goimports -w .github.com/stretchr/goweb- Web frameworklaunchpad.net/gocheck- Testing framework
solver/: Core solving algorithm and solution handlingwebserver.go: HTTP server with puzzle APIroutes.go: Web API endpointsstatic/ui2.html: Canvas-based puzzle visualizationpuzzles/: Example puzzle definitions
This project uses GOPATH-style Go modules. Contributions welcome - feel free to add new puzzles, improve the algorithm, or enhance the web interface.