public void True_1() { var nimGame = new NimGame("1"); var result = nimGame.IWin(); Assert.True(result); }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { NimGame.TriggerMessage(); } }
public void False_4() { var nimGame = new NimGame("4"); var result = nimGame.IWin(); Assert.False(result); }
public void Be_Created_With_4_Piles_When_Hard_Selected() { //arrange int expected = 4; int actual; //act var game = new NimGame(GameDifficulty.Hard); actual = game.GetPileIDs().Length; //assert Assert.AreEqual(expected, actual); }
public void Allow_You_To_Take_One_Object_From_a_Pile() { //arrange var game = new NimGame(GameDifficulty.Easy); var ids = game.GetPileIDs(); var amountTaking = -10; bool result; //act result = game.TakeFromPile(ids[0], amountTaking); //assert Assert.IsFalse(result); }
public void Allow_You_To_Take_The_Same_Number_Of_Objects_Present_In_a_Pile() { //arrange var game = new NimGame(GameDifficulty.Easy); var ids = game.GetPileIDs(); var amountTaking = game.GetPileSize(ids[0]); bool result; //act result = game.TakeFromPile(ids[0], amountTaking); //assert Assert.IsTrue(result); }
public void Not_Allow_You_To_Take_More_Objects_Then_Present_In_a_Pile() { //arrange var game = new NimGame(GameDifficulty.Easy); var ids = game.GetPileIDs(); var amountTaking = game.GetPileSize(ids[0]) + 1; bool result; //act result = game.TakeFromPile(ids[0], amountTaking); //assert Assert.IsFalse(result); }
public void Have_The_Configuration_2_3_8_9_When_Hard_Selected() { //arrange int[] expectedConfiguration = { 2, 3, 8, 9 }; //act var game = new NimGame(GameDifficulty.Hard); var names = game.GetPileIDs(); //assert for (int i = 0; i < expectedConfiguration.Length && i < names.Length; i++) { Assert.AreEqual(expectedConfiguration[i], game.GetPileSize(names[i]), $"The Value Expected was {expectedConfiguration[i]} in position {i} but was {game.GetPileSize(names[i])}"); } }
public void Have_The_Configuration_3_3_When_Easy_Selected() { //arrange int expected = 3; //act var game = new NimGame(GameDifficulty.Easy); var names = game.GetPileIDs(); //assert foreach (var name in names) { Assert.AreEqual(expected, game.GetPileSize(name)); } }
// Free all loaded libraries void UnloadAll() { Debug.Log("Unload All"); if (NimGame.UnityPluginUnload != null) { NimGame.UnityPluginUnload(); } else { Debug.Log("Unload Func = null"); } foreach (var kvp in _loadedPlugins) { bool result = DynLibInterface.UnloadPlugin(kvp.Value); } _loadedPlugins.Clear(); }
public void Reset_To_Original_State_After_ResetGame_Is_Called() { //arrange var game = new NimGame(GameDifficulty.Easy); var ids = game.GetPileIDs(); var amountTaking = game.GetPileSize(ids[0]); var expectedConfiguration = new [] { 3, 3 }; //act game.TakeFromPile(ids[0], amountTaking); game.ResetGame(); //assert for (int i = 0; i < expectedConfiguration.Length; i++) { Assert.AreEqual(expectedConfiguration[i], game.GetPileSize(ids[i])); } }
public void Fire_Game_Over_When_All_Piles_Are_Empty() { //arrange var game = new NimGame(GameDifficulty.Hard); bool gameIsOver = false; game.GameOver += (s, e) => gameIsOver = true; //act foreach (var pileID in game.GetPileIDs()) { game.TakeFromPile(pileID, game.GetPileSize(pileID)); } //assert if (!gameIsOver) { Assert.Fail(); } }
private NimGame.MessageHandlerDel msgHandler; // Ensure it doesn't get garbage collected // Start is called before the first frame update void Start() { msgHandler = new NimGame.MessageHandlerDel(OnMessage); NimGame.SetMessageHandler(msgHandler); }
// Load all plugins with 'PluginAttr' // Load all functions with 'PluginFunctionAttr' void LoadAll() { // TODO: Could loop over just Assembly-CSharp.dll in most cases? // Loop over all assemblies var assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in assemblies) { // Loop over all types foreach (var type in assembly.GetTypes()) { // Get custom attributes for type var typeAttributes = type.GetCustomAttributes(typeof(PluginAttr), true); if (typeAttributes.Length > 0) { Debug.Assert(typeAttributes.Length == 1); // should not be possible var typeAttribute = typeAttributes[0] as PluginAttr; var pluginName = typeAttribute.pluginName; IntPtr pluginHandle = IntPtr.Zero; if (!_loadedPlugins.TryGetValue(pluginName, out pluginHandle)) { var pluginPath = _path + pluginName + DynLibInterface.EXT; pluginHandle = DynLibInterface.LoadPlugin(pluginPath); Debug.Log("LoadPlugin " + pluginPath); if (pluginHandle == IntPtr.Zero) { throw new System.Exception("Failed to load plugin [" + pluginPath + "]"); } _loadedPlugins.Add(pluginName, pluginHandle); } // Loop over fields in type var fields = type.GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); foreach (var field in fields) { // Get custom attributes for field var fieldAttributes = field.GetCustomAttributes(typeof(PluginFunctionAttr), true); if (fieldAttributes.Length > 0) { Debug.Assert(fieldAttributes.Length == 1); // should not be possible // Get PluginFunctionAttr attribute var fieldAttribute = fieldAttributes[0] as PluginFunctionAttr; var functionName = fieldAttribute.functionName; // Get function pointer var fnPtr = DynLibInterface.GetPluginProcAddress(pluginHandle, functionName); if (fnPtr == IntPtr.Zero) { Debug.LogError(string.Format("Failed to find function [{0}] in plugin [{1}].", functionName, pluginName)); continue; } // Get delegate pointer var fnDelegate = Marshal.GetDelegateForFunctionPointer(fnPtr, field.FieldType); // Set static field value field.SetValue(null, fnDelegate); } } } } } var interf = GetUnityInterfacesPtr(); if (interf == IntPtr.Zero) { Debug.Log("Fail to GetUnityInterfacesPtr"); } else { NimGame.UnityPluginLoad(GetUnityInterfacesPtr()); } }