/// <summary> /// Constructs a new KinectViceoStream /// </summary> public KinectVideoStream() { Main = MainProgram.Main; Graphics = Main.Display.Graphics; int screenWidth = Graphics.PreferredBackBufferWidth; int screenHeight = Graphics.PreferredBackBufferHeight; int width = (int)(screenWidth * 0.225f); int height = (int)(width * 3.0 / 4); int x = (int)(screenWidth * 0.98f - width); int y = (int)(screenHeight * 0.98f - height ); VideoStreamPosition = new int[] { x, y }; VideoStreamSize = new int[] { width, height }; Color = Color.White; }
private void ReplaceEditor_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; this.Hide(); MainProgram.getInstance().ReloadConfigs(); }
public static async void UpdateCheck() { try { if (Directory.Exists(TEMP_DIR_NAME)) { Directory.Delete(TEMP_DIR_NAME); } var asm = Assembly.GetExecutingAssembly(); var program_version = asm.GetName().Version; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(RELEASE_INFO_API); request.UserAgent = API_USER_AGENT; var response = await request.GetResponseAsync(); Version release_version = null; string download_url = null; using (var reader = new StreamReader(response.GetResponseStream())) { var content = reader.ReadToEnd(); var matches = Regex.Matches(content, @"\""(\w+)\""\s*:\s*\""(.+?)\"""); foreach (Match match in matches) { var name = match.Groups[1].Value; var val = match.Groups[2].Value; switch (name.ToLower()) { case "tag_name": release_version = new Version(val.TrimStart('v')); break; case "browser_download_url": download_url = val; break; default: break; } } } if (release_version == null || string.IsNullOrWhiteSpace(download_url)) { Log.Warn("Get release info failed! please visit \"https://github.com/MikiraSora/ReOsuStoryboardPlayer/releases/latest\"."); return; } Log.User($"Progress current version:{program_version} ,release latest version:{release_version}"); if (release_version > program_version) { await Task.Run(() => { if (MessageBox.Show(null, $"There is a new version available to update.\ncurrent version:{program_version} \nlatest version:{release_version}", "Program Updater", MessageBoxButtons.YesNo) == DialogResult.Yes) { var client = new WebClient(); Log.User($"Downloading {download_url}"); int prev_progress = -1; client.DownloadProgressChanged += (o, e) => { if (prev_progress == e.ProgressPercentage) { return; } prev_progress = e.ProgressPercentage; Log.User($"Downloading... {e.ProgressPercentage}%"); }; client.DownloadFileCompleted += (o, e) => { if (!File.Exists(DOWNLOAD_ZIP)) { Log.Error($"Can't download update zip file."); return; } using (ZipArchive archive = ZipFile.Open(DOWNLOAD_ZIP, ZipArchiveMode.Read)) { if (!Directory.Exists(TEMP_DIR_NAME)) { Directory.CreateDirectory(TEMP_DIR_NAME); } else { //clean foreach (var file in Directory.EnumerateFiles(TEMP_DIR_NAME)) { if (Directory.Exists(file)) { Directory.Delete(file); } else { File.Delete(file); } } } archive.ExtractToDirectory(TEMP_DIR_NAME); } var exe_file_path = Directory.EnumerateFiles(TEMP_DIR_NAME, EXE_NAME, SearchOption.AllDirectories).FirstOrDefault(); var exe_path = Path.GetDirectoryName(exe_file_path); if (!File.Exists(exe_file_path)) { Log.Error($"Can't find the exe file \"{EXE_NAME}\" as program updater,please redownload or manually copy files/directories of folder \"{TEMP_DIR_NAME}\" to current program folder"); return; } var updater_exe_file = Path.Combine(exe_path, UPDATE_EXE_NAME); File.Copy(exe_file_path, updater_exe_file, true); if (File.Exists(DOWNLOAD_ZIP)) { File.Delete(DOWNLOAD_ZIP); } var current_path = AppDomain.CurrentDomain.BaseDirectory; Process.Start(new ProcessStartInfo(updater_exe_file, $"\"{Process.GetCurrentProcess().Id}\" -program_update \"{current_path}\" -disable_update_check")); MainProgram.Exit(); }; client.DownloadFileAsync(new Uri(download_url), DOWNLOAD_ZIP); } }); } } catch (Exception e) { Log.Error($"Update check failed:{e.Message} , you can go to https://github.com/MikiraSora/ReOsuStoryboardPlayer/releases/latest and check manually"); } }
public static void ApplyUpdate(int raw_proc_id, string dest_path) { try { if (raw_proc_id != 0) { Process.GetProcessById(raw_proc_id)?.Kill(); } } catch { } try { Log.User($"Waiting for all players were shutdown...."); while (Process.GetProcessesByName("ReOsuStoryBoardPlayer").Any()) { Thread.Sleep(500); } var current_exe_name = Path.GetFileName(Process.GetCurrentProcess().Modules[0].FileName); var current_path = AppDomain.CurrentDomain.BaseDirectory; if (!Directory.Exists(dest_path)) { MainProgram.Exit("program_update must set a directory path."); } Log.User($"Copy files to {dest_path}"); bool success_fully = true; var files = Directory.EnumerateFiles(current_path).Where(x => Path.GetFileName(x) != current_exe_name).ToArray(); for (int i = 0; i < files.Length; i++) { var source_file = files[i]; var display_file_path = string.Empty; try { display_file_path = RelativePath(current_path, source_file); Log.User($"Copy file({i+1}/{files.Length}):{display_file_path}"); CopyRelativeFile(source_file, current_path, dest_path); } catch (Exception e) { Log.Error($"Copy file \"{display_file_path}\" failed:{e.Message}"); success_fully = false; } } if (success_fully) { Log.User("Program update successfully!"); } else { Log.Warn("Program update isn't successful even failed,but you can copy the files/directories of \"update_temp\" folder to current program folder"); } MainProgram.Exit("Update Done."); } catch (Exception e) { MainProgram.Exit("Update failed :" + e.Message); } }
protected override double GetFitnessMethod(string program) { byte input1 = 0, input2 = 0; int state = 0; double countBonus = 0; double penalty = 0; List <byte> digits = new List <byte>(); for (int i = 0; i < _trainingCount; i++) { switch (i) { case 0: input1 = 1; input2 = 2; break; case 1: input1 = 3; input2 = 5; break; case 2: input1 = 8; input2 = 13; break; } ; try { state = 0; _console.Clear(); digits.Clear(); // Run the program. _bf = new Interpreter(program, () => { if (state == 0) { state++; return(input1); } else if (state == 1) { state++; return(input2); } else { // Not ready for input. penalty++; return(0); } }, (b) => { if (state < 2) { // Not ready for output. penalty++; } else { _console.Append(b); _console.Append(","); digits.Add(b); } }); _bf.Run(_maxIterationCount); } catch { } _output.Append(_console.ToString()); _output.Append("|"); // 0,1,1,2,3,5,8,13,21,34,55,89,144,233. Starting at 3 and verifying 10 digits. int index = 0; int targetValue = input1 + input2; // 1 + 2 = 3 int lastValue = input2; // 2 foreach (byte digit in digits) { Fitness += 256 - Math.Abs(digit - targetValue); int temp = lastValue; // 2 lastValue = targetValue; // 3 targetValue += temp; // 3 + 2 = 5 if (++index >= _maxDigits) { break; } } // Make the AI wait until a solution is found without the penalty (too many input characters). Fitness -= penalty; // Check for solution. IsFitnessAchieved(); // Bonus for less operations to optimize the code. countBonus += ((_maxIterationCount - _bf.m_Ticks) / 1000.0); // Bonus for using functions. if (_functionCount > 0) { for (char functionName = 'a'; functionName < 'a' + _functionCount; functionName++) { if (MainProgram.Contains(functionName)) { countBonus += 25; } } } Ticks += _bf.m_Ticks; } if (_fitness != Double.MaxValue) { _fitness = Fitness + countBonus; } return(_fitness); }
private void Awake() { _instance = this; }
public ChooseStressFlow(MainProgram form) { this.form = form; InitializeComponent(); }
public FirstInput(MainProgram form) { InitializeComponent(); this.form = form; }
//Entry into the form public Form1() { InitializeComponent(); orderList = new MainProgram(); AddOrder(); }
static void Main(string[] args) { MainProgram mainProgram = new MainProgram(); mainProgram.Run(); }
/// <summary> /// Build a curve using the least squares method /// </summary> /// <param name="begin"></param> /// <param name="end"></param> /// <param name="xData"></param> /// <param name="yData"></param> /// <param name="curve"></param> /// <param name="form"></param> public static double[] leastSquaresBuild(int begin, int end, LineItem allPointsForBuilding, ref LineItem curve, MainProgram form) { double[] data = LeastSquareData(allPointsForBuilding); double k = data[0]; double b = data[1]; curve.Tag = 2; for (int i = begin; i < end; i++) { curve.AddPoint(new PointPair(i, k * i + b)); } return(new double[] { k, b }); }
public static PointPair Sigma(LineItem originalCurve, PointPair p2, LineItem LineCurve, LineItem curved2, MainProgram form, bool zeroTwo, string name) { int index = originalCurve.Points.Count - 4; double[] xData = GraphProcessing.CurveToArray(LineCurve, true); double[] yData = GraphProcessing.CurveToArray(LineCurve, false); double offSetY = originalCurve[index].Y - p2.Y; double offSetX = originalCurve[index].X - p2.X; for (int i = 0; i < xData.Length; i++) { xData[i] += offSetX; yData[i] += offSetY; } var ds = new XYDataSet(xData, yData); double k = ds.Slope; double b = ds.YIntercept; LineItem curve = null; form.buttons.Add(GraphProcessing.CreateCurve(ref curve, form.CurvesDropDownButton, form.ZGCInstance, "Параллель 1", Color.DarkCyan, 1, SymbolType.Default, Color.DarkCyan)); int curveLength = originalCurve.Points.Count; for (int i = 0; i < 1.1 * originalCurve.Points[curveLength - 5].X; i++) { if ((k * i + b) > 0) { curve.AddPoint(new PointPair(i, k * i + b)); } } // y = kx + b x = (y-b)/k; kx = b = > x = k/b double pos = Math.Abs(b / k); curve.AddPoint(new PointPair(pos, 0)); int offSetX2 = (int)Math.Round(0.8 * curve.Points[0].X); LineItem curve2; curve2 = LineCurve.Clone(); form.buttons.Add(GraphProcessing.CreateCurve(ref curve2, form.CurvesDropDownButton, form.ZGCInstance, "Параллель 2", Color.DarkCyan, 1, SymbolType.Default, Color.DarkCyan)); for (int i = 0; i < LineCurve[0].X; i++) { if ((form.kCoef * i + form.bCoef) > 0) { curve2.AddPoint(new PointPair(i, form.kCoef * i + form.bCoef)); } } curve2.AddPoint(new PointPair(Math.Abs(form.bCoef / form.kCoef), 0)); form.IntersectionPointBegin = curve[curve.Points.Count - 1].X; form.IntersectionPointEnd = curve2[curve2.Points.Count - 1].X; curve.Tag = 5; curve2.Tag = 1; // y = kx + b // y = k(x+0.02) + b // y = kx + 0.02k + b // yy = kx + (0.02k + b // -kx + y = b double distance = Math.Abs(form.IntersectionPointEnd - form.IntersectionPointBegin); PointPair temp = new PointPair(0, 0); if (zeroTwo) { temp = parallelLineSigma(0.02, form, LineCurve, originalCurve, distance, name); } else { temp = parallelLineSigma(0.05, form, LineCurve, originalCurve, distance, name); } GraphProcessing.UpdateGraph(form.ZGCInstance); return(temp); }
public static void zeroTwoSigma1(LineItem originalCurve, PointPair p2, LineItem LineCurve, LineItem curved2, MainProgram form) { LineItem curve1 = null; LineItem curve2 = null; form.buttons.Add(GraphProcessing.CreateCurve(ref curve1, form.CurvesDropDownButton, form.ZGCInstance, "Параллель 1", Color.DarkCyan, 2, SymbolType.Default, Color.DarkCyan)); curve1 = LineCurve; form.buttons.Add(GraphProcessing.CreateCurve(ref curve2, form.CurvesDropDownButton, form.ZGCInstance, "Параллель 2", Color.DarkCyan, 2, SymbolType.Default, Color.DarkCyan)); //int max = 0; //for (int i = 0; i < originalCurve.Points.Count; i++) if (originalCurve.Points[i].X > max) max = (int)originalCurve.Points[i].X; //double average = 0; //for (int i = 0; i < curved2.Points.Count - 10; i++) average += Math.Abs(curved2[i].Y); //average /= curved2.Points.Count - 10; //int index = 0; //for (index = 0; index < curved2.Points.Count; index++) { if (curved2[index].Y > 10.0 * average) break; } double offSetY = originalCurve[originalCurve.Points.Count - 4].Y - p2.Y; double offSetX = originalCurve[originalCurve.Points.Count - 4].X - p2.X; for (int i = 0; i < LineCurve.Points.Count - 1; i++) { curve1.AddPoint(new PointPair(LineCurve.Points[i].X + offSetX, LineCurve.Points[i].Y += offSetY)); } int offSetX2 = (int)Math.Round(0.98 * originalCurve.Points[originalCurve.Points.Count - 4].X); for (int i = 0; i < curve1.Points.Count; i++) { curve2.AddPoint(new PointPair(curve1.Points[i].X + offSetX2, curve1.Points[i].Y)); } }
public static void zeroTwoSigma2(LineItem originalCurve, PointPair p2, LineItem LineCurve, LineItem curved2, MainProgram form) { LineItem curve1 = null; LineItem curve2 = null; form.buttons.Add(GraphProcessing.CreateCurve(ref curve1, form.CurvesDropDownButton, form.ZGCInstance, "Паралелль 1", Color.DarkCyan, 4, SymbolType.Default, Color.DarkCyan)); form.buttons.Add(GraphProcessing.CreateCurve(ref curve2, form.CurvesDropDownButton, form.ZGCInstance, "Паралелль 2", Color.DarkCyan, 4, SymbolType.Default, Color.DarkCyan)); int max = 0; for (int i = 0; i < originalCurve.Points.Count; i++) { if (originalCurve.Points[i].X > max) { max = (int)originalCurve.Points[i].X; } } double average = 0; for (int i = 0; i < curved2.Points.Count - 10; i++) { average += Math.Abs(curved2[i].Y); } average /= curved2.Points.Count - 10; int index = 0; for (index = 0; index < curved2.Points.Count; index++) { if (curved2[index].Y > 10.0 * average) { break; } } double offSetY = originalCurve[index].Y - p2.Y; double offSetX = originalCurve[index].X - p2.X; for (int i = 0; i < LineCurve.Points.Count - 1; i++) { double x = LineCurve.Points[i].X - offSetX; double y = LineCurve.Points[i].Y + offSetY; curve1.AddPoint(new PointPair(x, y)); } int offSetX2 = (int)Math.Round(0.8 * curve1.Points[0].X); for (int i = 0; i < curve1.Points.Count; i++) { curve2.AddPoint(new PointPair(curve1.Points[i].X - offSetX2, curve1.Points[i].Y)); } curve1.Tag = 5; curve2.Tag = 5; }
public void WaitInput(MainProgram program) { throw new System.NotImplementedException(); }
public static BeatmapFolderInfo Parse(string folder_path, ProgramCommandParser.Parameters args) { if (!Directory.Exists(folder_path)) { throw new Exception($"\"{folder_path}\" not a folder!"); } BeatmapFolderInfo info = new BeatmapFolderInfo(); var osu_files = TryGetAnyFiles(".osu"); string explicitly_osu_diff_name = string.Empty; if (args != null && args.TryGetArg("diff", out var diff_name)) { explicitly_osu_diff_name = diff_name; } if (!string.IsNullOrWhiteSpace(explicitly_osu_diff_name)) { int index = -1; index = int.TryParse(explicitly_osu_diff_name, out index) ? index : -1; if (index > 0) { info.osu_file_path = osu_files.OrderBy(x => x).FirstOrDefault(); } else { var fix_pattern = Regex.Escape(explicitly_osu_diff_name); Regex regex = new Regex(@"\[.*" + fix_pattern + @".*\]\.osu", RegexOptions.IgnoreCase); info.osu_file_path = osu_files.Where(x => regex.IsMatch(x)).OrderBy(x => x.Length).FirstOrDefault(); } } else { //优先先选std铺面的.一些图其他模式谱面会有阻挡 53925 fripSide - Hesitation Snow info.osu_file_path = osu_files.FirstOrDefault(x => { var lines = File.ReadAllLines(x); foreach (var line in lines) { if (line.StartsWith("Mode")) { try { var mode = line.Split(':').Last().ToInt(); if (mode == 0) { return(true); } } catch { } } } return(false); }); if (!File.Exists(info.osu_file_path)) { info.osu_file_path = osu_files.FirstOrDefault(); } } if (string.IsNullOrWhiteSpace(info.osu_file_path) || !File.Exists(info.osu_file_path)) { Log.Warn("No .osu load"); } info.osb_file_path = TryGetAnyFiles(".osb").FirstOrDefault(); info.folder_path = folder_path; if ((!string.IsNullOrWhiteSpace(info.osu_file_path)) && File.Exists(info.osu_file_path)) { info.reader = new OsuFileReader(info.osu_file_path); var section = new SectionReader(Section.General, info.reader); info.audio_file_path = Path.Combine(folder_path, section.ReadProperty("AudioFilename")); Log.User($"audio file path={info.audio_file_path}"); var wideMatch = section.ReadProperty("WidescreenStoryboard"); if (!string.IsNullOrWhiteSpace(wideMatch)) { info.IsWidescreenStoryboard = wideMatch.ToInt() == 1; } } if (string.IsNullOrWhiteSpace(info.osu_file_path) || (!File.Exists(info.osu_file_path))) { info.audio_file_path = Directory .GetFiles(info.folder_path, "*.mp3") .Select(x => new FileInfo(x)) .OrderByDescending(x => x.Length) .FirstOrDefault() ?.FullName; } if (!(_check(info.osu_file_path) || _check(info.osb_file_path)) && _check(info.audio_file_path)) { MainProgram.Exit($"missing files such as .osu/.osb and audio file which is registered in .osu"); } return(info); bool _check(string file_path) { return((!string.IsNullOrWhiteSpace(file_path)) && File.Exists(file_path)); } IEnumerable <string> TryGetAnyFiles(string extend_name) { return(Directory.EnumerateFiles(folder_path, "*" + extend_name, SearchOption.AllDirectories)); } }
public void WaitInput(MainProgram program) { }
public CustomLine(MainProgram form) { InitializeComponent(); this.form = form; }
protected override double GetFitnessMethod(string program) { byte input1 = 0; int state = 0; double countBonus = 0; double penalty = 0; byte result = 0; for (int i = 0; i < _trainingCount; i++) { switch (i) { case 0: input1 = 4; break; case 1: input1 = 5; break; case 2: input1 = 8; break; } ; try { state = 0; _console.Clear(); result = 0; // Run the program. _bf = new Interpreter(program, () => { if (state == 0) { state++; return(input1); } else { // Not ready for input. penalty++; return(0); } }, (b) => { if (state == 1) { _console.Append(b); _console.Append(","); result = b; state++; } else { // Not ready for output. penalty++; } }); _bf.Run(_maxIterationCount); } catch { } // Order bonus. if (_console.Length > 0) { _output.Append(_console.ToString()); _output.Append("|"); Fitness += 256 - Math.Abs(result - (input1 + input1)); } // Make the AI wait until a solution is found without the penalty (too many input characters). Fitness -= penalty; // Check for solution. IsFitnessAchieved(); // Bonus for less operations to optimize the code. countBonus += ((_maxIterationCount - _bf.m_Ticks) / 1000.0); // Bonus for using functions. if (_functionCount > 0) { for (char functionName = 'a'; functionName < 'a' + _functionCount; functionName++) { if (MainProgram.Contains(functionName)) { countBonus += 25; } } } Ticks += _bf.m_Ticks; } if (_fitness != Double.MaxValue) { _fitness = Fitness + countBonus; } return(_fitness); }
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; MainProgram.theProgram(worker, e); }
private static void beginPlay(int numCPU) { bool playCont = true; int count; List <CPU> listOfCPUS = new List <CPU>(); for (int x = 0; x < numCPU; x++) { CPU temp = new CPU(); temp.setUpCPU("CPU" + x); listOfCPUS.Add(temp); } while (playCont) { List <string[]> cardsInPlay = dealCards(numCPU); count = 2; foreach (CPU comp in listOfCPUS) { comp.setUpCPUHand(cardsInPlay[count][0], cardsInPlay[count][1]); count++; } int revealCards = 3; string commCards = ""; bool roundCont = true; bool playerFold = false; while (roundCont) { bool playerChoice1 = true; while (playerChoice1) { int contPlay = playerTurn(commCards, cardsInPlay); if (contPlay == 0) { revealCards = 6; playerFold = true; playerChoice1 = false; } else if (contPlay == 1) { playerChoice1 = false; } } foreach (CPU comp in listOfCPUS) { comp.checkState(null); } if (revealCards > 5) { roundCont = false; } else { for (int x = 0; x < revealCards; x++) { commCards = commCards + cardsInPlay[0][x] + " "; } Console.WriteLine("Community Cards: " + commCards); } commCards = ""; revealCards++; } int cpuNum = 1; foreach (string [] x in cardsInPlay) { if (x.Length < 3) { if (playerFold) { Console.WriteLine("CPU" + cpuNum++ + "'s Hand: " + x[0] + " " + x[1]); } else { Console.WriteLine("Player's Hand: " + x[0] + " " + x[1]); playerFold = true; } } } string[] winners = MainProgram.findPokerWinner(formatList(cardsInPlay, playerFold)); Console.WriteLine(winners[0] + " wins!"); Console.WriteLine("Would you like to continue? y/n"); bool playerChoice2 = true; while (playerChoice2) { string exit = Console.ReadLine(); if (exit.Equals("n")) { Console.WriteLine("Your winnings: " + amount); playCont = false; playerChoice2 = false; } else if (exit.Equals("y")) { Console.WriteLine("Your winnings: " + amount); playerChoice2 = false; } else { Console.WriteLine("Unkown Command. Please write a valid command"); } } } }