nneonneo / 2048-ai

AI for the 2048 game
MIT License
1.09k stars 279 forks source link

Calling this dll from a C# program #77

Open stevehkwong opened 3 months ago

stevehkwong commented 3 months ago

Quick question (not sure if appropriate to ask) - I am trying to use this from a C# program (64bit)

the output from getBestMove seems to always be -1

i have declared below - [DllImport("2048.dll", CallingConvention = CallingConvention.Cdecl)] private static extern int find_best_move(UInt64 board);

I have also simulated your toCBoard function by converting a grid into a ulong

public static ulong ToCBoard(Grid m) { ulong board = 0; int i = 0; ulong t = 0;

        for (int row = 0; row < 4; row++)
        {
            for (int col = 0; col < 4; col++)
            {
                t = (ulong) m.Cells[col, row];
                board |= t << (4 * i);
                i++;
            }
        }
        return board;
    }

Calling this by: ulong t = ToCBoard(gameBoard); bestMove = find_best_move(t);

Any ideas?

nneonneo commented 3 months ago

Did you call init_tables first?