Reputation: 1890
I have a project to build a card game using C# ASP.NET, the project is to have a card games website where users play and challenge each others.
My friend can build the AI engine using C++, but how I can communicate with that engine through c# specially it should be an browser based online game.
Everything from pages, scripts and site system is easy to implement in C#, but the cards table for each game (the communication with the engine) is something that I cant figure.
Which approach to use, Is there any suggestions?
Upvotes: 0
Views: 670
Reputation: 1190
If you actually want to mix C# with C++, then probably the easiest way to communicate is to create a C++ DLL which includes a C interface. You can then import this DLL using P/Invoke:
[DllImport("ai.dll")]
static extern int doSomething(int numCardOnTable, int[] cardOnTable,
int numCardsOnHand, int[] cardsOnHand, out int cardToPlay);
Another way is to use Managed C++ which you can directly import in C#:
namespace CPP_managed_code
{
public ref class AI
{
public:
int doSomething(int numCardOnTable, int[] cardOnTable, int numCardsOnHand,
int[] cardsOnHand, out int cardToPlay)
{
// ...
return 0;
}
};
}
And your C# code:
using CPP_managed_code;
// ...
unsafe private void myCSharpMethod()
{
AI ai = new AI();
ai.doSomething(/*...*/);
}
But I'd not recommend using Managed C++ because it is not standard C++.
Upvotes: 1