// Unnecessary helper public static TilePosition buildingPositionRelativeTo(string type, BW.Unit building, CustomTypes.Direction direction) { TilePosition building_position = building.theUnit.getTilePosition(); int x_offset = 0, y_offset = 0; switch (direction) { case CustomTypes.Direction.Left: { x_offset = -bwapi.getUnitType(type).tileWidth(); y_offset = 0; break; } case CustomTypes.Direction.Right: { x_offset = bwapi.getUnitType(building.Type).tileWidth(); y_offset = 0; break; } case CustomTypes.Direction.Down: { x_offset = 0; y_offset = bwapi.getUnitType(building.Type).tileHeight(); break; } case CustomTypes.Direction.Up: { x_offset = 0; y_offset = -bwapi.getUnitType(type).tileHeight(); break; } } return new TilePosition(building_position.xConst() + x_offset, building_position.yConst() + y_offset); }
//Načtení anime private void LoadAnime() { Main_LB01.Visible = true; AnimeS.Columns.Clear(); AnimeS.Rows.Clear(); AnimeID.Clear(); AnimeS.Width = Convert.ToInt32(Math.Truncate((float)this.Width / 250) * 250); AnimeS.Height = 240; AnimeS.Location = new Point((this.Width - AnimeS.Width) / 2, AnimeS.Location.Y); Anime.Location = new Point((this.Width - Anime.Width) / 2, AnimeS.Location.Y + AnimeS.Height + 20); AnimeS.Columns.Add(new DataGridViewImageColumn()); AnimeS.Rows.Add(); AnimeS.Rows[0].Height = 230; AnimeS.Rows.Add(); AnimeS.Rows[1].Height = 5; AnimeS.Rows[1].DefaultCellStyle.SelectionBackColor = DesignColor; AnimeS.Rows[1].DefaultCellStyle.SelectionForeColor = DesignColor; if (BW.IsBusy) { BW.CancelAsync(); Thread.Sleep(3000); } BW.RunWorkerAsync(); }
private void OK_Click(object sender, EventArgs e) { OK.Enabled = false; Controls.Remove(chart1); Controls.Remove(dataGridView); BW.RunWorkerAsync("OK"); }
public bool buildProbe(BW.Unit nexus) { UnitType probe_type = bwapi.getUnitType("Protoss Probe"); if (nexus != null) return nexus.theUnit.train(probe_type); return false; }
private void start_Click(object sender, EventArgs e) { //выкл кнопку Cancel.Enabled = true; start.Enabled = false; Controls.Remove(chart1); Controls.Remove(dataGridView); BW.RunWorkerAsync("START");//запуск кода в обработчике do_work, выполняется в отдельном потоке }
private void button2_Click(object sender, System.EventArgs e) { ma2Start.Enabled = false; ma2End.Enabled = false; rsiStart.Enabled = false; rsiEnd.Enabled = false; maStart.Enabled = false; maEnd.Enabled = false; BW.RunWorkerAsync(); }
private void Form1_Load(object sender, EventArgs e) { maStart.Value = 10; maEnd.Value = 20; rsiStart.Value = 8; rsiEnd.Value = 12; ma2Start.Value = 12; ma2End.Value = 15; BW.RunWorkerAsync(); }
public EcoBaseAI(GameState state, BaseLocation location, BW.Unit nexus) { State = state; this.nexus = nexus; Probes = new List<BW.Unit>(); BaseMinerals = new List<BW.Unit>(); Location = location; foreach (var patch in location.getStaticMinerals()) { BaseMinerals.Add(new BW.Unit(patch)); } }
//========================================================== public void GetWithdrawalHistory(Bittrex B, String Currency) { BittrexResult <List <BittrexWithdrawal> > Withdrawals = B.GetWithdrawalHistory(Currency); if (GetIsResultValid(Withdrawals)) { foreach (BittrexWithdrawal BW in Withdrawals.Result) { Console.WriteLine(BW.ToString()); } } }
/// <summary> /// Rename files /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BTRename_Click(object sender, EventArgs e) { // Rename if files if (LVFiles.Items.Count > 0) { DialogResult dialogResult = MessageBox.Show($"{LVFiles.Items.Count} files are about to be renamed. Do you want to continue ?", "Rename files", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (dialogResult == DialogResult.Yes) { // Start (processing files) thread loading = true; new Thread(Loading).Start(); BW.RunWorkerAsync(); BTClear.Enabled = false; BTRename.Enabled = false; } } }
private async void UserWindow_Load(object sender, EventArgs e) { // SelectedUser был без ID , тут мы его всего забираем из базы Variable.SelectedUser = ServiceClient.FindUser(Variable.SelectedUser); // подгрузить заметки юзера Variable.Notes = await ServiceClient.GetNotesOfUser(Variable.SelectedUser.Id_); listBoxNotesOfUser.Items.AddRange(Variable.Notes.Select(x => x.Title).ToArray()); // Хаб для SignalR hubConnection = new HubConnection("http://localhost:36932/"); stockTickerHubProxy = hubConnection.CreateHubProxy("SignalRHub"); stockTickerHubProxy.On("Update", () => BW.RunWorkerAsync());// BW - BackgroundWorker hubConnection.Start().Wait(); // BackgroundWorker для клиентской обработки серверного метода от SignalR BW.DoWork += update; BW.RunWorkerCompleted += BW_RunWorkerCompleted; }
private void BW_DoWork(object sender, DoWorkEventArgs e) { while (currChapter != "-1") { try { //string url = txt_Url.Text; //BW.ReportProgress(0, "开始下载..."); string url = @"http://a.heiyan.com/ajax/chapter/content/{0}?callback=jQuery183042279977366378296_1489487599999&_=1489487600401"; url = string.Format(url, currChapter); if (!string.IsNullOrEmpty(url)) { string html = httper.GetHtml(new HttpItem() { URL = url }); //txt_Content.Text = HttpHelper.GetUrl(url); if (!string.IsNullOrEmpty(html)) { int startIndex = html.IndexOf("({") + 1; html = html.Substring(startIndex, html.Length - 1 - startIndex); var book_chapter = JsonConvert.DeserializeObject <heiyan_chapter>(html); var title = book_chapter.chapter.title; var content = book_chapter.chapter.htmlContent; content = content.Replace("“", "“").Replace("”", "”"); content = content.Replace("<p>", "").Replace(@"</p>", "\r\n"); content = content.Replace("…", "...").Replace(@"—", "-"); bookStr += string.Format("{0}\r\n\r\n{1}\r\n\r\n", title, content); //txt_Content.Text = bookStr; currChapter = book_chapter.nextChapterId; BW.ReportProgress(100, book_chapter.chapter.title); } } } catch (Exception ex) { //MessageBox.Show(ex.Message); currChapter = "-1"; } } }
public override void RunUpload(IEnumerable <PictureItem> items, BackgroundWorker bw) { this.BW = bw; this.RootFolder = FTPSettings.Server + FTPSettings.InternalFTPFolder; CreateDirectory(this.RootFolder); string rootF = RootFolder + @"/" + this.UploadFolder; CreateDirectory(rootF); RootFolder = rootF + @"/"; BW.ReportProgress(0, "Сохранение фото..."); ProgressTicker ticker = new ProgressTicker(items.Count(), 20); ticker.ProgressChanged += Ticker_ProgressChanged; foreach (var item in items) { try { if (!ImageDownloadHelper.IsUrlImage((item.Address))) { throw new Exception("Скачиваемый контент не является графическим изображением."); } byte[] imageByteArray = ImageDownloadHelper.DownloadData(item.Address); string ext = imageByteArray.GetExtention(); string pictureName = $"{item.Name}.{ext}"; item.Address = UploadPicture(imageByteArray, pictureName); item.Status = true; ticker.Tick(); } catch (Exception ex) { item.Status = false; item.Address += $" Ошибка: {ex.Message}."; } } ticker = null; }
public virtual void onMyUnitCreated(BW.Unit unit) { if (unit.theUnit.getType().isBuilding()) { var item = State.buildingQueue.Where(x => x.Type == unit.Type).OrderBy(x => x.TilePosition.getDistance(unit.theUnit.getTilePosition())).First(); item.buildingTask.SetResult(unit); // State.popItem(unit.theUnit.getType(), unit.theUnit.getTilePosition()); State.popItem(item); transferUnitTo(getBuildingProbe(), EcoAI); buildingProbeId = 0; } if (unit.Type == "Protoss Probe") { EcoAI.Probes.Add(unit); } }
public void ReceiveUnit(BW.Unit unit) { if (unit.theUnit.getType().getName() == "Protoss Probe") { Probes.Add(unit); } else { throw new NotImplementedException("AI cannot receive non-Probe units"); } }
private void GatherNextMineral(BW.Unit unit) { if (BaseMinerals.Any()) { var patch = BaseMinerals[currentPatchIndex].theUnit; if (patch.isVisible(bwapi.Broodwar.self())) unit.Gather(patch); else unit.theUnit.move(patch.getInitialPosition()); currentPatchIndex = (currentPatchIndex + 1) % BaseMinerals.Count; } }
public void onfoundMinerals(BW.Unit unit) { AIState.onFoundMinerals(unit); }
private void ParseConfig() { try { this.SpiChannel = (SpiChannel)Pi.Spi.GetProperty(this.config["spichan"]); this.PinChipSelect = (GpioPin)Pi.Gpio[Int32.Parse(this.config["pin_sspin"])]; //Physical pin 24, BCM pin 8, Wiring Pi pin 10 (SPI0 CE0) this.PinReset = (GpioPin)Pi.Gpio[Int32.Parse(this.config["pin_rst"])]; //Physical pin 29, BCM pin 5, Wiring Pi pin 21 (GPCLK1) if (this.config.ContainsKey("frequency0")) { this._radioEnabled[0] = true; this._radioFrequency[0] = UInt32.Parse(this.config["frequency0"]); } if (this.config.ContainsKey("frequency1")) { this._radioEnabled[1] = true; this._radioFrequency[1] = UInt32.Parse(this.config["frequency1"]); } for (Byte i = 0; i < 10; i++) { if (this.config.ContainsKey("interface" + i + "frequency")) { Int32 offset = Int32.Parse(this.config["interface" + i + "frequency"]); if (offset >= -500000 && offset <= 500000) { this._interfaceFrequency[i] = offset; } else { throw new ArgumentException("interface" + i + "frequency: Offset " + offset + " is not allowed!"); } this._interfaceEnabled[i] = true; Byte chain = Byte.Parse(this.config["interface" + i + "chain"]); if (chain == 0) { this._interfaceChain[i] = Reciever.Chain0; } else if (chain == 1) { this._interfaceChain[i] = Reciever.Chain1; } else { throw new ArgumentException("interface" + i + "chain: Chain " + chain + " is not allowed!"); } } } Int32 lbwc = Int32.Parse(this.config["lorabandwith"]); this._loraBandwidth = lbwc <= 7800 ? BW.BW_7K8HZ : lbwc <= 15600 ? BW.BW_15K6HZ : lbwc <= 31250 ? BW.BW_31K2HZ : lbwc <= 62500 ? BW.BW_62K5HZ : lbwc <= 125000 ? BW.BW_125KHZ : lbwc <= 250000 ? BW.BW_250KHZ : BW.BW_500KHZ; Int32 sbwc = Int32.Parse(this.config["sendbw"]); this._loraSendBandwidth = sbwc <= 7800 ? BW.BW_7K8HZ : sbwc <= 15600 ? BW.BW_15K6HZ : sbwc <= 31250 ? BW.BW_31K2HZ : sbwc <= 62500 ? BW.BW_62K5HZ : sbwc <= 125000 ? BW.BW_125KHZ : sbwc <= 250000 ? BW.BW_250KHZ : BW.BW_500KHZ; Byte sf = Byte.Parse(this.config["loraspreadingfactor"]); this._loraSpreadingFactor = sf <= 7 ? SF.DR_LORA_SF7 : sf <= 8 ? SF.DR_LORA_SF8 : sf <= 9 ? SF.DR_LORA_SF9 : sf <= 10 ? SF.DR_LORA_SF10 : sf <= 11 ? SF.DR_LORA_SF11 : SF.DR_LORA_SF12; Byte ssf = Byte.Parse(this.config["sendsf"]); this._loraSendSpreadingFactor = ssf <= 7 ? SF.DR_LORA_SF7 : ssf <= 8 ? SF.DR_LORA_SF8 : ssf <= 9 ? SF.DR_LORA_SF9 : ssf <= 10 ? SF.DR_LORA_SF10 : ssf <= 11 ? SF.DR_LORA_SF11 : SF.DR_LORA_SF12; Int32 fbwc = Int32.Parse(this.config["fskbandwith"]); this._fskBandwidth = fbwc <= 7800 ? BW.BW_7K8HZ : fbwc <= 15600 ? BW.BW_15K6HZ : fbwc <= 31250 ? BW.BW_31K2HZ : fbwc <= 62500 ? BW.BW_62K5HZ : fbwc <= 125000 ? BW.BW_125KHZ : fbwc <= 250000 ? BW.BW_250KHZ : BW.BW_500KHZ; this._loraSendCodeRate = Byte.Parse(this.config["sendcr"]) switch { 5 => CR.CR_LORA_4_5, 6 => CR.CR_LORA_4_6, 7 => CR.CR_LORA_4_7, 8 => CR.CR_LORA_4_8, _ => throw new Exception("sendcr only can 5-8") }; this._loraSendPreeamble = Byte.Parse(this.config["sendpreamble"]); this._fskDatarate = UInt32.Parse(this.config["fskdatarate"]); this._CrcEnabled = Boolean.Parse(this.config["crc"]); this._lorawan_public = Boolean.Parse(this.config["lorawan"]); Console.WriteLine("Fraunhofer.Fit.Iot.Lora.lib.Ic880a.Ic880a.ParseConfig(): board configuration: lorawan_public:" + this._lorawan_public + ", clksrc:1"); for (Byte i = 0; i < 2; i++) { Console.WriteLine("Fraunhofer.Fit.Iot.Lora.lib.Ic880a.Ic880a.ParseConfig(): rf_chain " + i + " configuration; en:" + this._radioEnabled[i] + " freq:" + this._radioFrequency[i] + " rssi_offset:" + this._rf_rssi_offset[i] + " radio_type:" + this._rf_radio_type[i] + " tx_enable:" + this._radioEnableTx[i] + " tx_notch_freq:" + this._rf_tx_notch_freq[i]); } for (Byte i = 0; i < 8; i++) { Console.WriteLine("Fraunhofer.Fit.Iot.Lora.lib.Ic880a.Ic880a.ParseConfig(): LoRa 'multi' if_chain " + i + " configuration; en:" + this._interfaceEnabled[i] + " freq:" + this._interfaceFrequency[i] + " SF_mask:0x7E"); } Console.WriteLine("Fraunhofer.Fit.Iot.Lora.lib.Ic880a.Ic880a.ParseConfig(): LoRa 'std' if_chain 8 configuration; en:" + this._interfaceEnabled[8] + " freq:" + this._interfaceFrequency[8] + " bw:" + this._loraBandwidth + " dr:" + this._loraSpreadingFactor); Console.WriteLine("Fraunhofer.Fit.Iot.Lora.lib.Ic880a.Ic880a.ParseConfig(): FSK if_chain 9 configuration; en:" + this._interfaceEnabled[9] + " freq:" + this._interfaceFrequency[9] + " bw:" + this._fskBandwidth + " dr:" + this._fskDatarate + " (" + this._fskDatarate * 2 + " real dr) sync:0xC194C1"); } catch (Exception e) { throw new ArgumentException("Some Argument is not set in settings.ini: " + e.Message); } }
private void UserList_Load(object sender, EventArgs e) { BW.RunWorkerAsync(); }
public virtual void onFoundMinerals(BW.Unit unit) { }
private void btn_Get_Click(object sender, EventArgs e) { currChapter = first; BW.RunWorkerAsync(); }
//Načtení anime private void BW_DoWork(object sender, DoWorkEventArgs e) { DataTable DT = DatabaseSelect("SELECT TOP " + SQLCount + " * FROM (SELECT TOP " + SQLCount + " * FROM (SELECT TOP " + (SQLPage * SQLCount) + " * FROM anime ORDER BY CStr([anime]![anime_nazevjap]) ASC) ORDER BY CStr([anime]![anime_nazevjap]) DESC) ORDER by CStr([anime]![anime_nazevjap]) ASC", null, false); for (int i = 0; i < DT.Rows.Count; i++) { if (BW.CancellationPending) { break; } Loading = false; AnimeID.Add(DT.Rows[i]["id_anime"].ToString()); if (File.Exists(GlobalAdresar + @"Accounts\!imgs\" + DT.Rows[i]["anime_obr"].ToString())) { StreamReader cti = new StreamReader(GlobalAdresar + @"Accounts\!imgs\" + DT.Rows[i]["anime_obr"].ToString()); Image img = Image.FromStream(cti.BaseStream); if (BW.CancellationPending) { break; } img = RoundCorners(img, 10, Color.Transparent); if (BW.CancellationPending) { break; } img = resizeImage(img, new Size(250, 200)); if (BW.CancellationPending) { break; } img = Lighter(img); if (BW.CancellationPending) { break; } BW.ReportProgress(i, img); cti.Close(); } else { BW.ReportProgress(i, new Bitmap(1, 1)); } while (true) { if (Loading) { break; } if (BW.CancellationPending) { break; } Thread.Sleep(1); } } }
public override void onMyUnitCreated(BW.Unit unit) { if (unit.Type == "Protoss Zealot") { myArmy.Add(unit); } base.onMyUnitCreated(unit); }
public virtual void onMyUnitMorph(BW.Unit unit) { if (unit.theUnit.getType().getName() == "Protoss Assimilator") { var item = State.buildingQueue.Where(x => x.Type == unit.Type).OrderBy(x => x.TilePosition.getDistance(unit.theUnit.getTilePosition())).First(); item.buildingTask.SetResult(unit); // State.popItem(unit.theUnit.getType(), unit.theUnit.getTilePosition()); State.popItem(item); transferUnitTo(getBuildingProbe(), EcoAI); buildingProbeId = 0; } }
private void Cancel_Click(object sender, EventArgs e) { //отмена фоновой операции BW.CancelAsync(); }
public async Task RevealPosition(BW.Unit unit, TilePosition position) { var tcs = new TaskCompletionSource<bool>(); unit.theUnit.move(new Position(position)); RevelationTasks.Add(position, tcs); await (Task)tcs.Task; }
// #region ModuleInteraction protected virtual void transferUnitTo(BW.Unit unit, IAIModule module) { module.ReceiveUnit(unit); bwapi.Broodwar.printf("Unit transferred to : " + module.ToString()); }
public void ReceiveUnit(BW.Unit unit) { ScoutingProbe = unit; }
/// <summary> /// Checks if the <see cref="g1"/> version (or subset versions) is equivalent to <see cref="g2"/>. /// </summary> /// <param name="g1">Version (set)</param> /// <param name="g2">Individual version</param> public static bool Contains(this GameVersion g1, GameVersion g2) { if (g1 == g2 || g1 == Any) { return(true); } switch (g1) { case RB: return(g2 == RD || g2 == BU || g2 == GN); case Stadium: case EventsGBGen1: case VCEvents: case RBY: return(RB.Contains(g2) || g2 == YW); case Gen1: return(RBY.Contains(g2) || g2 == Stadium || g2 == EventsGBGen1 || g2 == VCEvents); case GS: return(g2 == GD || g2 == SV); case Stadium2: case EventsGBGen2: case GSC: return(GS.Contains(g2) || g2 == C); case Gen2: return(GSC.Contains(g2) || g2 == Stadium2 || g2 == EventsGBGen2); case GBCartEraOnly: return(g2 == Stadium || g2 == Stadium2 || g2 == EventsGBGen1 || g2 == EventsGBGen2); case RS: return(g2 == R || g2 == S); case RSE: return(RS.Contains(g2) || g2 == E); case FRLG: return(g2 == FR || g2 == LG); case COLO: case XD: return(g2 == CXD); case CXD: return(g2 == COLO || g2 == XD); case RSBOX: return(RS.Contains(g2) || g2 == E || FRLG.Contains(g2)); case Gen3: return(RSE.Contains(g2) || FRLG.Contains(g2) || CXD.Contains(g2) || g2 == RSBOX); case DP: return(g2 == D || g2 == P); case HGSS: return(g2 == HG || g2 == SS); case DPPt: return(DP.Contains(g2) || g2 == Pt); case BATREV: return(DP.Contains(g2) || g2 == Pt || HGSS.Contains(g2)); case Gen4: return(DPPt.Contains(g2) || HGSS.Contains(g2) || g2 == BATREV); case BW: return(g2 == B || g2 == W); case B2W2: return(g2 == B2 || g2 == W2); case Gen5: return(BW.Contains(g2) || B2W2.Contains(g2)); case XY: return(g2 == X || g2 == Y); case ORAS: return(g2 == OR || g2 == AS); case Gen6: return(XY.Contains(g2) || ORAS.Contains(g2)); case SM: return(g2 == SN || g2 == MN); case USUM: return(g2 == US || g2 == UM); case GG: return(g2 == GP || g2 == GE || g2 == GO); case Gen7: return(SM.Contains(g2) || USUM.Contains(g2) || GG.Contains(g2)); default: return(false); } }
private void MainMenu_Load(object sender, EventArgs e) { BW.RunWorkerAsync(); }
public override void onMyUnitCreated(BW.Unit unit) { base.onMyUnitCreated(unit); }
public static bool IsWallpaperRed(GameVersion version, int wallpaperID) { switch (version.GetGeneration()) { case 3: if (CXD.Contains(version)) { return(wallpaperID == 7); // flame pattern in XD } switch (wallpaperID) { case 5: // Volcano return(true); case 13: // PokéCenter return(E == version); default: return(false); } case 4: switch (wallpaperID) { case 5: // Volcano case 12: // Checks case 13: // PokéCenter case 22: // Special return(true); default: return(false); } case 5: switch (wallpaperID) { case 5: // Volcano case 12: // Checks return(true); case 19: // PWT case 22: // Reshiram return(B2W2.Contains(version)); case 21: // Zoroark case 23: // Musical return(BW.Contains(version)); default: return(false); } case 6: case 7: switch (wallpaperID) { case 5: // Volcano case 12: // PokéCenter case 20: // Special5 Flare/Magma return(true); default: return(false); } default: return(false); } }