public void ChooseItem(Items item, Case unit) { CaseVerifier verifier = new CaseVerifier(unit); MotherboardVerifier motherboardVerifier = new MotherboardVerifier(unit.Motherboard); switch (item) { case Items.MOTHERBOARD: CheckFunction <Motherboard> checkMoth = verifier.MotherboardFitsCase; configurator.Choose(Motherboards.FindAll(), Items.MOTHERBOARD, unit, checkMoth); break; case Items.POWER_SOURCE: CheckFunction <PowerSource> checkPow = verifier.PowerSourceFitsCase; configurator.Choose(PowerSources.FindAll(), Items.POWER_SOURCE, unit, checkPow); break; case Items.PROCESSOR: CheckFunction <Processor> checkProc = motherboardVerifier.ProcessorsFitsMotherboard; configurator.Choose(Processors.FindAll(), Items.PROCESSOR, unit, checkProc); break; case Items.MEMORY_CARD: CheckFunction <MemoryCard> checkMemory = motherboardVerifier.MemoryCardFitsMotherBoard; configurator.ChooseMultiple(unit, unit.Motherboard.MemoryCardsAdded, MemoryCards.FindAll(), Items.MEMORY_CARD, checkMemory); break; } }
public void Initialize(string placeHolderText, Action <string> callback, CheckFunction callbackCheck = null, Action <string> callbackWrongInput = null) { if (callbackCheck == null) { _checkFunction = BaseCheckFunction; } else { _checkFunction = callbackCheck; } _inputField.text = placeHolderText; _cancelButton.onClick.AddListener(OnClickCloseButton); _okButton.onClick.AddListener( delegate { if (_checkFunction(_inputField.text)) { callback(_inputField.text); OnClickCloseButton(); } else { if (callbackWrongInput != null) { callbackWrongInput(_inputField.text); } } } ); }
Result RunRound(char[][] data, CheckFunction check, int claustrophobia) { var result = new Result { Data = data.Select(x => x.ToArray()).ToArray(), ChangeCount = 0 }; for (int y = 0; y < data.Count(); y++) { for (int x = 0; x < data[y].Count(); x++) { if (data[y][x] == 'L' && CountCompass(data, x, y, check) == 0) { result.Data[y][x] = '#'; result.ChangeCount++; } else if (data[y][x] == '#' && CountCompass(data, x, y, check) >= claustrophobia) { result.Data[y][x] = 'L'; result.ChangeCount++; } } } return(result); }
/// <summary> /// Adds a named check function /// </summary> /// <param name="checkProvider"></param> /// <param name="name">Exposed name of the function</param> /// <param name="func">Method that matches delegate CheckFunction</param> public static void AddCheckFunction(this ICheckProvider checkProvider, string name, CheckFunction func) { checkProvider.Functions.Add("check_" + name, (settings) => { return func(settings as CheckSettings); }); }
public Task <bool> CheckQueryAsync(string doc, BlockParameter blockParameter = null) { var checkFunction = new CheckFunction(); checkFunction.Doc = doc; return(ContractHandler.QueryAsync <CheckFunction, bool>(checkFunction, blockParameter)); }
IEnumerator Flow(GameObject[] objects, CheckFunction checker = null) { SetActiveGameObjects(objects, true); while (checker == null ? !nextFlow : !checker()) { yield return null; } SetActiveGameObjects(objects, false); }
public static void CheckMapItem(string Index, CheckFunction checkFn, DecodedContainer arrayContainer, CheckValues checkValues) { Assert.IsTrue(arrayContainer.solidityVar.name == checkValues.parentName, "Error the parent name does not match it should be " + arrayContainer.solidityVar.name); DecodedContainer current = arrayContainer; current = current.children.Find(a => a.key == Index); Assert.IsTrue(current != null, "Error map check failed index is {0} but count is {1}", Index, current.children.Count); Assert.IsTrue(checkFn(current, checkValues), "Check function failed for " + arrayContainer.solidityVar.name); }
// 新增UpdateFunc private void AddUpdateFunc(string name, CheckFunction func) { if (!funcList.ContainsKey(name)) { funcList.Add(name, func); } else { SaveLog($"[Warning] {name} Function Repeat"); } }
/// <summary> /// ProtocolItem 객체를 추가 /// </summary> /// <param name="nBufferSize"></param> /// <param name="bUsing"></param> /// <param name="CheckFunc"></param> /// <param name="CatchFunc"></param> /// <returns></returns> public bool AddProtocolItem(int nBufferSize, bool bUsing, CheckFunction CheckFunc, CatchFunction CatchFunc) { ProtocolItem pI = new ProtocolItem(); pI.Queue.SetSize(nBufferSize); pI.Using = bUsing; pI.OnCheck = CheckFunc; pI.OnCatch = CatchFunc; this.m_ProtocolItems.Add(pI); return(true); }
/// <summary> /// 画像データを与えるとGoogleCloudVisionでラベル検知したやつを返す。 /// </summary> /// <param name="imageData"></param> /// <returns></returns> public static EntityAnnotation[] RequestVisionAPI(string base64String) { // 参考:https://qiita.com/jyuko/items/e6115a5dfc959f52591d string apiKey = "AIzaSyAQe-ZtCVwWx0xIco4b9U3dpbk83MoLv_c"; string url = "https://vision.googleapis.com/v1/images:annotate?key=" + apiKey; // 送信用データを作成 // 1.requestBodyを作成 var requests = new requestBody(); requests.requests = new List <AnnotateImageRequest>(); // 2.requestBody > requestを作成 var request = new AnnotateImageRequest(); request.image = new Image(); request.image.content = base64String; // 3.requestBody > request > featureを作成 request.features = new List <Feature>(); var feature = new Feature(); feature.type = FeatureType.LABEL_DETECTION.ToString(); feature.maxResults = 10; request.features.Add(feature); requests.requests.Add(request); // JSONに変換 string jsonRequestBody = JsonUtility.ToJson(requests); // ヘッダを"application/json"にして投げる var webRequest = new UnityWebRequest(url, "POST"); byte[] postData = Encoding.UTF8.GetBytes(jsonRequestBody); webRequest.uploadHandler = new UploadHandlerRaw(postData); webRequest.downloadHandler = new DownloadHandlerBuffer(); webRequest.SetRequestHeader("Content-Type", "application/json"); webRequest.SendWebRequest(); // 受信するまで待機 while (!webRequest.isDone) { } var buff = JsonUtility.FromJson <responseBody>(webRequest.downloadHandler.text); return(CheckFunction.removeAnnotation(buff.responses[0].labelAnnotations.ToArray())); }
public static void CheckArrayItem(int index, CheckFunction checkFn, DecodedContainer arrayContainer, CheckValues checkValues) { if (arrayContainer.children.Count > index) { Assert.IsTrue(checkFn(arrayContainer.children[index], checkValues), string.Format("Error check array failed on check function for array {0} length {1}", arrayContainer.solidityVar.name, arrayContainer.children.Count)); } else { Assert.Fail("Error array check failed index is {0} but count is {1}", index, arrayContainer.children.Count); } }
int Solve(CheckFunction check, int claustrophobia) { var data = Rows.Select(x => x.ToCharArray()).ToArray(); while (true) { var result = RunRound(data, check, claustrophobia); if (result.ChangeCount == 0) { return(result.Data.Sum(x => x.Count(y => y == '#'))); } data = result.Data; } }
/// <summary>Finds all the valid numbers (that meet the given password criteria) in /// the range given by the inputs.</summary> /// <param name="inputs">Minimum and maximum value (inclusive) for the numbers to check.</param> /// <param name="checkFn">Validity function to pass.</param> /// <returns>Count of numbers in the range that pass the test.</returns> static int GetCountOfValidNumbers(int[] inputs, CheckFunction checkFn) { int min = inputs[0]; int max = inputs[1]; int count = 0; for (int n = min; n <= max; n++) { if (checkFn(n)) { count++; } } return(count); }
int CountCompass(char[][] data, int x, int y, CheckFunction check) { int count = 0; for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { if (!(dx == 0 && dy == 0) && check(data, x, y, dx, dy)) { count++; } } } return(count); }
public void Choose <T>(List <T> list, Items choice, Case unitCase = null, CheckFunction <T> function = null) { Console.WriteLine($"\nPlease choose {choice}:\n"); foreach (var s in list) { if (function == null || unitCase == null) { Console.WriteLine($"{(list.IndexOf(s) + 1)} - {s}"); } else { Console.WriteLine(function(s) ? $"{(list.IndexOf(s) + 1)} - {s} - fits" : $"{list.IndexOf(s) + 1} - {s} - does not fit"); } } Console.WriteLine("\nPlease enter your option:"); bool repeat = true; while (repeat) { if (int.TryParse(Console.ReadLine(), out int input)) { if (input > 0 && input <= list.Count) { SetProp(choice, list[input - 1], unitCase); Console.WriteLine($"You`ve chosen {list[input - 1]}\n"); Console.WriteLine("Choose: " + unitCase); repeat = false; } else { Console.WriteLine("Number out of range, please try again!"); repeat = true; } } else { Console.WriteLine("Not a number, please try again!"); } } }
public void ChooseMultiple <T>(Case unitCase, List <T> listToClear, List <T> list, Items choice, CheckFunction <T> function) { listToClear.Clear(); Console.WriteLine($"\nPlease choose {choice}:\n"); foreach (var s in list) { Console.WriteLine(function(s) ? $"{(list.IndexOf(s) + 1)} - {s} - fits" : $"{(list.IndexOf(s) + 1)} - {s} - does not fit"); } Console.WriteLine("Please enter your options, to exit enter 'exit':\n"); bool exit = false; while (!exit) { var inputString = Console.ReadLine(); if (inputString != null) { if (int.TryParse(inputString, out int input)) { if (input > 0 && input <= list.Count) { SetProp(Items.MEMORY_CARD, list[input - 1], unitCase); Console.WriteLine($"You`ve chosen {list[input - 1]}"); } else { Console.WriteLine("Wrong number, please try again!\n"); exit = false; } } else if (inputString.Equals("exit")) { exit = true; } else { Console.WriteLine("Not a number, try again"); } } } }
/// <summary> /// Adds check function as default function /// </summary> /// <param name="checkProvider"></param> /// <param name="func">Method that matches delegate CheckFunction</param> public static void AddCheckFunction(this ICheckProvider checkProvider, CheckFunction func) { checkProvider.AddCheckFunction("default", func); }
public static void DoWithChain(AbstractElement beginning, DoSomethingWithElement func, CheckFunction isNotTheEnd = null) { if (isNotTheEnd == null) { isNotTheEnd = x => x != null; } for (var i = beginning; isNotTheEnd(i); i = i.NextElement) { func(i); } }
public Task <bool> CheckQueryAsync(CheckFunction checkFunction, BlockParameter blockParameter = null) { return(ContractHandler.QueryAsync <CheckFunction, bool>(checkFunction, blockParameter)); }