Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling this dll from a C# program #77

Open
stevehkwong opened this issue Aug 4, 2024 · 1 comment
Open

Calling this dll from a C# program #77

stevehkwong opened this issue Aug 4, 2024 · 1 comment

Comments

@stevehkwong
Copy link

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
Copy link
Owner

nneonneo commented Aug 4, 2024

Did you call init_tables first?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants