@echo off
setlocal

REM Build brownan GPL solver as standalone executable
REM Source is in .external/Rubiks-Cube-Solver (GPL-2.0, NEVER link into Unreal)

set SRCDIR=..\..\.external\Rubiks-Cube-Solver
set OUTDIR=..\..\UnrealHyperTwist\Binaries\Win64\Solvers

if not exist %OUTDIR% mkdir %OUTDIR%

cl.exe /nologo /W4 /O2 /Fe%OUTDIR%\brownan-solver.exe ^
    %SRCDIR%\cube.c ^
    %SRCDIR%\stack.c ^
    %SRCDIR%\common.c ^
    %SRCDIR%\cornertable.c ^
    %SRCDIR%\goal.c ^
    %SRCDIR%\edgetable.c ^
    %SRCDIR%\main.c

if errorlevel 1 (
    echo Build failed
    exit /b 1
)

REM Copy pre-generated tables if they exist
if exist %SRCDIR%\table_corner.rht copy /Y %SRCDIR%\table_corner.rht %OUTDIR%\
if exist %SRCDIR%\table_edge1.rht copy /Y %SRCDIR%\table_edge1.rht %OUTDIR%\
if exist %SRCDIR%\table_edge2.rht copy /Y %SRCDIR%\table_edge2.rht %OUTDIR%\

echo brownan-solver built successfully at %OUTDIR%\brownan-solver.exe
