public void GameTest() { Decks playingDecks = new Decks(); playingDecks.FillCards(); byte[] gameCards = new byte[416]; gameCards = playingDecks.Cards; byte bjFlag; int testResult; LibraryLoader libraryLoader = new LibraryLoader("../../../../BotsLibrary/BotsLibrary.dll"); Assembly asm = libraryLoader.LoadLibrary(); PluginHelper pluginHelper = new PluginHelper(asm); // Dealer has blackjack and player in both hands has blackjack too gameCards[0] = 10; gameCards[1] = 1; gameCards[2] = 1; gameCards[3] = 10; gameCards[4] = 10; gameCards[5] = 1; bjFlag = 3; testResult = 32; SomeGameTest(pluginHelper, playingDecks, gameCards, testResult, bjFlag); gameCards[0] = 10; gameCards[1] = 10; gameCards[2] = 10; gameCards[3] = 1; bjFlag = 0; testResult = -16; // Dealer has blackjack, player's score is 20. SomeGameTest(pluginHelper, playingDecks, gameCards, testResult, bjFlag); gameCards[0] = 10; gameCards[1] = 10; gameCards[2] = 10; gameCards[3] = 7; bjFlag = 0; testResult = 32; // Dealer has 17, player's score is 20. SomeGameTest(pluginHelper, playingDecks, gameCards, testResult, bjFlag); gameCards[0] = 10; gameCards[1] = 10; gameCards[2] = 5; gameCards[3] = 7; bjFlag = 0; testResult = 8; // Player surrendered SomeGameTest(pluginHelper, playingDecks, gameCards, testResult, bjFlag); gameCards[0] = 9; gameCards[1] = 8; gameCards[2] = 8; gameCards[3] = 9; gameCards[4] = 10; gameCards[5] = 6; gameCards[6] = 10; bjFlag = 0; testResult = 64; // Player won with both hands SomeGameTest(pluginHelper, playingDecks, gameCards, testResult, bjFlag); // Now we test two games successively playingDecks.FillCards(); gameCards = playingDecks.Cards; gameCards[0] = 10; gameCards[1] = 10; gameCards[2] = 5; gameCards[3] = 7; bjFlag = 0; testResult = 8; // Player surrendered uint initialMoney = 1600; BlackjackGame testGame = new BlackjackGame(playingDecks, initialMoney); object[] parameters = new object[] { testGame.PlayingDealer.DealerCards[0], (uint)testGame.InitialMoney, testGame.PlayingCards, (uint)16 }; pluginHelper.CreatePlayer(parameters, 1); testGame.Player = pluginHelper.players[1]; Assert.AreEqual(testGame.Game(), testResult); for (int i = 0; i < 416; i++) { Assert.AreEqual(testGame.PlayingCards.Cards[i], gameCards[i]); } // Second game gameCards[0] = 9; gameCards[1] = 8; gameCards[2] = 8; gameCards[3] = 9; gameCards[4] = 10; gameCards[5] = 6; gameCards[6] = 10; bjFlag = 0; testResult = 64; // Player won with both hands Assert.AreEqual(testGame.Game(), testResult); for (int i = 0; i < 416; i++) { Assert.AreEqual(testGame.PlayingCards.Cards[i], gameCards[i]); } }
public void Find_InParentDirectory_HasValidValues() { var sut = new LibraryLoader(new TrackConfigurationSearcher(), new TrackParser(new IniFormatParser())); var library = sut.LoadLibrary(TestLibraryPath); Assert.Equal(2, library.Items.Count()); Assert.All(library.Items, i => Assert.Equal("AC/DC", i.Song.Author)); }
public void LoadLibrary_UseAddFunction() { var library = LibraryLoader.LoadLibrary("Soltys.VirtualMachine.Test"); Assert.Contains("add", library.Functions); var result = library.Functions["add"].Execute(6, 7); Assert.Equal(13, (int)result); }
public void PluginHelperTest() { LibraryLoader testLoader = new LibraryLoader("../../../../BotsLibrary/BotsLibrary.dll"); Assembly asm = testLoader.LoadLibrary(); PluginHelper testHelper = new PluginHelper(asm); // Invalid parameters in creating player string errorMessage = "Constructor on type 'BotsLibrary.CardsCounterStrategy' not found."; testHelper.CreatePlayer(null, 0); Assert.AreEqual(errorMessage, testHelper.LastExceptionMessage); }
public void AssembleInterfaceIsValid() { using (var ctx = CreateGlContext()) { ctx.MakeCurrent(); if (IsMac) { var lib = LibraryLoader.LoadLibrary("/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib"); var glInterface = GRGlInterface.Create(name => { return(LibraryLoader.GetSymbol(lib, name)); }); Assert.NotNull(glInterface); Assert.True(glInterface.Validate()); LibraryLoader.FreeLibrary(lib); } else if (IsWindows) { var lib = LibraryLoader.LoadLibrary("opengl32.dll"); var glInterface = GRGlInterface.Create(name => { var ptr = LibraryLoader.GetSymbol(lib, name); if (ptr == IntPtr.Zero) { ptr = wglGetProcAddress(name); } return(ptr); }); Assert.NotNull(glInterface); Assert.True(glInterface.Validate()); LibraryLoader.FreeLibrary(lib); } else if (IsLinux) { var glInterface = GRGlInterface.Create(name => { return(glXGetProcAddress(name)); }); Assert.NotNull(glInterface); Assert.True(glInterface.Validate()); } else { // more platforms !!! throw new Exception("Some strange platform that is not Windows, macOS nor Linux..."); } } }
public void LibraryLoaderTest() { // Invalid path LibraryLoader testLoader = new LibraryLoader("invalid path"); try { testLoader.LoadLibrary(); } catch (Exception ex) { Assert.AreEqual(testLoader.ExceptionMessage, ex.Message); } }
// #endregion // Public //------------------------------------------------------------------------- #region Private // T[] LoadFrom(AppDomain domain, string fName) { if (string.IsNullOrEmpty(fName)) { return(null); } // if (!File.Exists(fName)) { return(null); } // try { LibraryLoader <T> loader = (LibraryLoader <T>)domain.CreateInstanceAndUnwrap(typeof(LibraryLoader <T>).Assembly.FullName, typeof(LibraryLoader <T>).FullName); if (CommonDll != null) { for (int i = 0; i < CommonDll.Length; i++) { if (!File.Exists(CommonDll[i])) { continue; } // loader.LoadLibrary(CommonDll[i]); } } loader.LoadLibrary(fName); T[] types = loader.GetPlugins(); return(types); } catch { return(null); } }
static void Main(string[] args) { Console.Write("This programm represents the blackjack game with opportunity to split"); Console.Write(" cards, double wagers and surrender.\n"); Console.WriteLine("There are 3 strategies to play:"); Console.WriteLine("Basic strategy"); Console.WriteLine("Cards counting strategy, based on basic strategy and cards count"); Console.WriteLine("Simple strategy, based on basic strategy and players score at the moment"); Console.WriteLine("There are 3 bots with different strategies"); Console.WriteLine("The programm will print the approximate sum of their wagers when the game ends"); Decks playingDecks = new Decks(); playingDecks.FillCards(); double win = 0; try { BlackjackGame game = new BlackjackGame(playingDecks, 1600); // 1600 is initial players money for (int botsCount = 0; botsCount < 3; botsCount++) { Console.WriteLine("The turn of " + (botsCount + 1).ToString() + " bot."); LibraryLoader libraryLoader = new LibraryLoader("../../../../BotsLibrary/BotsLibrary.dll"); Assembly asm = libraryLoader.LoadLibrary(); PluginHelper pluginHelper = new PluginHelper(asm); object[] parameters = new object[] { game.PlayingDealer.DealerCards[0], game.InitialMoney, game.PlayingCards, (uint)16 }; pluginHelper.CreatePlayer(parameters, botsCount); game.Player = pluginHelper.players[botsCount]; for (int i = 0; i < 40; i++) { win += game.Game(); } Console.WriteLine("Approximate sum with 40 played rounds is {0}", win / 40.0); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.WriteLine("Press enter button to exit"); Console.ReadLine(); } }
private static List <Book> LoadBooksFromLibrary(IDataContext <Book> db) { var loader = new LibraryLoader(db, new Settings()); return(loader.LoadLibrary().ToList()); }
public void SetAlgorithmData(string filePath) { // Load the DLL file libLoader.LoadLibrary(filePath); }
public void LoadLibrary_LoadItself() { var library = LibraryLoader.LoadLibrary("Soltys.VirtualMachine.Test"); Assert.NotNull(library.Functions); }