1

I'm trying to put together a fun 'contest' of sorts. Developers will write a bot that plays some game - maybe BlackJack and the master program will host the game and let the bots play against each other.

I've participated in such things before, but never been involved with the 'host' application. And I'm not sure how to go about doing that.

I'll be doing this in VB.Net

Different people will write their own bots - I'm guessing I'd want to require them to implement a particular interface I'll define. They'll compile it into a DLL and send that to me. I need to have the host call the same methods on each of the different 'bot' DLLs to progress the game play - but I'm having some trouble doing that.

What's the best way to do this?

4

4 回答 4

3

Load the assembly using the reflection API. Then iterate through the types in that assembly until you find one that inherits from some base class you've defined, or interface. Then create an instance of it and start calling the methods :-)

From the sample documentation:

Imports System
Imports System.Reflection

Class Class1
    Public Shared Sub Main()
        Dim SampleAssembly As [Assembly]
        ' You must supply a valid fully qualified assembly name here.            
        SampleAssembly = [Assembly].Load("Assembly text name, Version, Culture, PublicKeyToken")
        Dim Types As Type() = SampleAssembly.GetTypes()
        Dim oType As Type
        ' Display all the types contained in the specified assembly.
        For Each oType In Types
            Console.WriteLine(oType.Name.ToString())
        Next oType
    End Sub 'LoadSample
End Class 'Class1

Once you have the type, you can create the instance using the Activator

于 2009-05-08T20:36:45.937 回答
2

Take a look at the Managed Extensibility Framework. It would let you easily create an interface (or even base classes), and they could just add an Export attribute to their implementation. You'd get all of the discovery and injection for free.

于 2009-05-08T21:03:59.040 回答
1

Ah, that idea brings back some memories from the very early days of .NET. I assume that code contains one or two bits of interest.

于 2009-05-08T20:50:47.153 回答
1

Depending on how realistic you want to be, you could always leverage the MS Robotics Studio which ties into Visual Studio 2008 and includes a simulator. There's even a league.

于 2009-05-08T20:53:40.220 回答