Example #1
0
 private void toolStripButtonFetchMapBox_Click(object sender, EventArgs e)
 {
     if (!base.CheckLoginState())
     {
         return;
     }
     DoTask(() =>
     {
         var result = PH.GenerateMapTrusureBox(base.MyCookie);
         if (result.Content[0].boxVO == null)
         {
             if (result.Content[0].targetStep == 0)
             {
                 DoOutput("获取地图宝箱已达到上限!");
             }
             else
             {
                 DoOutput("必须达到" + result.Content[0].targetStep + "步才能领取宝箱!");
             }
         }
         else
         {
             var fetchResult = PH.FetchMapTrusureBox(base.MyCookie, result.Content[0].boxVO.id, result.Content[0].boxVO.lng, result.Content[0].boxVO.lat);
             MessageBox.Show("获取健康金:" + fetchResult.Content[0].boxGiftList[0].gold * 0.01);
         }
     }, "领取失败");
 }
Example #2
0
        private void toolStripButtonQuery_Click(object sender, EventArgs e)
        {
            if (!CheckLoginState())
            {
                return;
            }

            new Thread(() =>
            {
                try
                {
                    base.ClearListView(this.listView1);
                    var list = PH.QueryPrizeList(base.MyCookie);
                    for (int i = 0; i < list.Content[0].prizes.Count; i++)
                    {
                        var item = list.Content[0].prizes[i];
                        base.AddListViewmItem(this.listView1, new object[]
                        {
                            i + 1,
                            item.name,
                            item.costGold + "金/次",
                            ""
                        });
                        base.SetListViewItemTag(this.listView1, i, item);
                    }
                }
                catch (Exception ex)
                {
                    MsgBox.ShowInfo("查询失败," + ex.Message);
                }
            })
            {
                IsBackground = true
            }.Start();
        }
Example #3
0
        public void PH_Parsing_Success_Test_3()
        {
            string testPHRaw = "teststring test</ph>";

            PH parsedPH = new PH(testPHRaw);

            Assert.AreEqual(false, parsedPH.ParsingSuccess);
        }
Example #4
0
        public void PH_Parsing_Success_Test_2()
        {
            string testPHRaw = "<ph id=\"1\">";

            PH parsedPH = new PH(testPHRaw);

            Assert.AreEqual(false, parsedPH.ParsingSuccess);
        }
Example #5
0
        /// <summary>
        /// 查看我的宝箱详情
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripLabel1_Click(object sender, EventArgs e)
        {
            DoTask(() => {
                var result = PH.GetMyBoxDetail(base.MyCookie);

                var frm = new FrmMyBoxDetail(result.Content[0].Value);
                frm.ShowDialog();
                frm.Dispose();
            }, "查看失败", false);
        }
Example #6
0
 }                                                           // calculated at turn start
 public void SetInboundShips(IEnumerable <Ship> ships)
 {
     HealthAtTurnKnown         = new Dictionary <int, (float health, int?owner, bool ownerChanged)>(NeighbouringPlanetsDistanceTurns?.Last()?.TurnsToReach ?? 0);
     InboundShips              = ships.OrderBy(s => s.TurnsToReachTarget).ToList();
     InboundHostileShips       = InboundShips.Where(s => PH.IsHostile(s)).ToList();
     HealthDiffInboundForTurns =
         InboundShips.GroupBy(s => s.TurnsToReachTarget, s => s).ToDictionary(g => g.Key,
                                                                              g => g.GroupBy(s2 => s2.Owner).Select(s => (s.Key, s.Sum(s2 => s2.Power))).ToList()
                                                                              );
 }
Example #7
0
        public void PH_Initialize_Test_3()
        {
            string testPHRaw = "<ph></ph>";
            string innerText = string.Empty;

            PH parsedPH = new PH(testPHRaw);

            Assert.AreEqual(-1, parsedPH.ID);
            Assert.AreEqual(innerText, parsedPH.Content);
        }
Example #8
0
        public void PH_Initialize_Test_1()
        {
            string testPHRaw = "<ph id=\"1\">&lt;afr story=\"ub35\" id=\"ub32\"/&gt;</ph>";
            string innerText = "&lt;afr story=\"ub35\" id=\"ub32\"/&gt;";

            PH parsedPH = new PH(testPHRaw);

            Assert.AreEqual(1, parsedPH.ID);
            Assert.AreEqual(innerText, parsedPH.Content);
        }
Example #9
0
        private void toolStripButtonLottery_Click(object sender, EventArgs e)
        {
            if (!CheckLoginState())
            {
                return;
            }

            if (this.listView1.CheckedItems.Count < 1)
            {
                MsgBox.ShowInfo("请勾选需要抽奖的项目!");
                return;
            }

            List <int> list = new List <int>();

            for (int i = 0; i < this.listView1.CheckedItems.Count; i++)
            {
                list.Add(this.listView1.CheckedItems[i].Index);
            }

            new Thread(() =>
            {
                SetControlEnabled(this.toolStrip1, false);
                SetControlEnabled(this.listView1, false);
                foreach (var index in list)
                {
                    SetListViewItemValue(this.listView1, index, 3, "正在抽奖...");
                    try
                    {
                        var info   = GetListViewItemTag <PajkPrizeItemInfo>(this.listView1, index);
                        var result = PH.DoLottery(base.MyCookie, info.id.ToString());
                        if (result.Content[0].isPrized ||
                            result.Content[0].prize ||
                            result.Content[0].prized)
                        {
                            SetListViewItemValue(this.listView1, index, 3, "抽奖成功," + result.Content[0].winRecordId);
                        }
                        else
                        {
                            SetListViewItemValue(this.listView1, index, 3, "抽奖失败");
                        }
                    }
                    catch (Exception ex)
                    {
                        SetListViewItemValue(this.listView1, index, 3, "抽奖失败," + ex.Message);
                    }
                    Thread.Sleep(500);
                }
                SetControlEnabled(this.toolStrip1, true);
                SetControlEnabled(this.listView1, true);
            })
            {
                IsBackground = true
            }.Start();
        }
Example #10
0
 /// <summary>
 /// 砸蛋
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void toolStripButton7_Click(object sender, EventArgs e)
 {
     if (!base.CheckLoginState())
     {
         return;
     }
     DoTask(() =>
     {
         var result = PH.ZaEgg(base.MyCookie);
         ShowZaEggResult(result);
     }, "领取失败");
 }
Example #11
0
 /// <summary>
 /// 逛商场
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void toolStripButton3_Click(object sender, EventArgs e)
 {
     if (!base.CheckLoginState())
     {
         return;
     }
     DoTask(() =>
     {
         var result = PH.FetchBoxByWalkMall(base.MyCookie);
         ShowFetchBoxResult(result);
     }, "领取失败");
 }
Example #12
0
    public void Bitmap2BitmapImageTest()
    {
        var bitmap = Image.FromFile(GetFile("17"));

        bitmap = BitmapHelper.ChangeColor2(bitmap, System.Drawing.Color.Black, ColorH.RandomColor(false).ToSystemDrawing());

        BitmapImage biVsLogo = BitmapImageHelper.Bitmap2BitmapImage(bitmap);

        var outFile = GetFile("out");

        BitmapImageHelper.Save(biVsLogo, outFile);
        PH.Start(outFile);
    }
        public String ToJSONString()
        {
            var phStr   = "PH: " + PH.ToString("F5");
            var doStr   = "DO: " + DO.ToString("F5");
            var bod5Str = "BOD5: " + BOD5.ToString("F5");
            var codStr  = "COD: " + COD.ToString("F5");
            var nh4nStr = "NH4-N: " + NH4N.ToString("F5");
            var no2nStr = "NO2-N: " + NO2N.ToString("F5");
            var no3nStr = "NO3-N: " + NO3N.ToString("F5");
            var ssStr   = "SS: " + SS.ToString("F5");
            var clStr   = "CL: " + CL.ToString("F5");
            var cbStr   = "CB: " + CB.ToString("F5");

            return(phStr + ", " + doStr + ", " + bod5Str + ", " + codStr + ", " + nh4nStr + ", " + no2nStr + ", " + no3nStr + ", " + ssStr + ", " + clStr + ", " + cbStr);
        }
Example #14
0
        /// <summary>
        /// “上传走步数据”按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButtonUploadStepData_Click(object sender, EventArgs e)
        {
            if (!CheckLoginState())
            {
                return;
            }

            var frmStepDataGen = new FrmStepDataGen();

            if (frmStepDataGen.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            string certPath = MyCertPath;

            if (certPath == null || !System.IO.File.Exists(certPath)) // 证书路径不存在,则重新选择
            {
                if (this.openFileDialog1.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                certPath = this.openFileDialog1.FileName;
            }

            try
            {
                var result = PH.UploadWalkData(MyUserInfo.id.ToString(), MyCookie, certPath, frmStepDataGen.StepCount);
                if (result == null)
                {
                    SetMyCertPath(null);
                    MsgBox.ShowInfo("无效证书!");
                    return;
                }
                if (result.Content[0].Value)
                {
                    MsgBox.ShowInfo("上传成功!");
                }
                SetMyCertPath(certPath);
            }
            catch (Exception ex)
            {
                SetMyCertPath(null);
                MsgBox.ShowInfo("上传失败," + ex.Message);
            }
            UpdateCertPathDisplay();
        }
Example #15
0
 public MyObjective(PH.Mission.BaseObjective obj)
 {
     objective = obj;
     if (objective is PH.Mission.NavigationObjective)
     {
         foreach (PH.Mission.NavPoint navPoint in ((PH.Mission.NavigationObjective)objective).NavPoints)
         {
             pointsToVisit.Add(navPoint);
         }
     }
     else
     {
         if (objective is PH.Mission.UniqueNavigationObjective)
         {
             foreach (PH.Mission.NavPoint navPoint in ((PH.Mission.UniqueNavigationObjective)objective).NavPoints)
             {
                 pointsToVisit.Add(navPoint);
             }
         }
     }
     //this.pointsToVisit = this.OrderPointsToVisit(pointsToVisit);
 }
Example #16
0
        /// <summary>
        /// 查询礼品
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (!base.CheckLoginState())
            {
                return;
            }
            this.listView1.Items.Clear();
            DoTask(() =>
            {
                var result = base.PH.GetDepot(base.MyCookie);
                result.Content[0].depotItems = result.Content[0].depotItems.OrderByDescending(s => s.OwnNum * 1.0 / s.NeedNum).ToArray(); // 按完成率降序排列
                double percent    = 0;
                string percentStr = string.Empty;
                for (int i = 0; i < result.Content[0].depotItems.Length; i++)
                {
                    var depoItem = result.Content[0].depotItems[i];
                    percent      = depoItem.OwnNum * 1.0 / depoItem.NeedNum * 100;
                    percentStr   = percent.ToString("0");
                    base.AddListViewmItem(this.listView1, new object[] {
                        i + 1,
                        depoItem.SpuTitle,
                        depoItem.PriceGold * 0.01,
                        depoItem.NeedNum,
                        depoItem.OwnNum,
                        percentStr
                    });
                    base.SetListViewItemTag(this.listView1, i, depoItem);
                    if (percent >= 100)
                    {
                        base.HighlightListViewRow(this.listView1, i);
                    }
                }

                // 获取碎片数
                var result2 = PH.FetchMyBoxNum(base.MyCookie);
                this.toolStripLabel1.Text = "我的碎片数:" + result2.Content[0].TotalBox;
            }, "查询失败");
        }
Example #17
0
        /// <summary>
        /// 兑换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 兑换ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count < 1)
            {
                return;
            }

            var item     = this.listView1.SelectedItems[0];
            var itemInfo = item.Tag as PajkGetDepotResultItem;

            if (itemInfo.NeedNum > itemInfo.OwnNum)
            {
                MsgBox.ShowInfo("碎片个数不够,无法兑换!");
                return;
            }

            if (MsgBox.ShowOkCancel("确定要兑换-" + itemInfo.SpuTitle + "?", "提示") != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            DoTask(() =>
            {
                ProductInfo info = new ProductInfo();
                info.name        = itemInfo.SpuTitle;
                info.id          = itemInfo.SkuId;

                var frm          = new FrmCreateOrder(info);
                frm.CreateOrder += (o, args) => {
                    var obj = o as FrmCreateOrder;
                    GlobalContext.Output("正在下单...");
                    PH.CreateOrder2(base.MyCookie, itemInfo.SkuId.ToString(), obj.SelectedMobile, obj.SelectedAddress);
                    GlobalContext.Output("已下单,详情请在【订单信息】中查询!");
                };
                frm.ShowDialog();
            }, "兑换失败");
        }
Example #18
0
        /// <summary>
        /// “获取走步数据”按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButtonDownloadStepData_Click(object sender, EventArgs e)
        {
            if (!CheckLoginState())
            {
                return;
            }

            string certPath = MyCertPath;

            if (certPath == null || !System.IO.File.Exists(certPath)) // 证书路径不存在,则重新选择
            {
                if (this.openFileDialog1.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                certPath = this.openFileDialog1.FileName;
            }

            try
            {
                var result = PH.DownloadWalkData(MyUserInfo.id.ToString(), MyCookie, certPath);

                if (result == null)
                {
                    base.SetMyCertPath(null);
                    MsgBox.ShowInfo("无效证书!");
                    return;
                }

                if (result.Content == null ||
                    result.Content.Count < 1 ||
                    result.Content[0].walkDataInfos == null ||
                    result.Content[0].walkDataInfos.Count < 1)
                {
                    // 没有数据
                    MsgBox.ShowInfo("未查询到走步数据!");
                    return;
                }

                var query = from info in result.Content[0].walkDataInfos
                            orderby info.walkDate descending
                            select info;

                this.listView1.Items.Clear();
                int index = 0;
                foreach (var item in query)
                {
                    var lvItem = new ListViewItem(new string[]
                    {
                        (++index).ToString(),
                        item.id.ToString(),
                        item.walkDate.ToString(),
                        item.distance * 0.001 + "",
                        item.stepCount.ToString(),
                        ToDateTime(item.walkTime).ToString(),
                        item.calories.ToString(),
                        item.targetStepCount.ToString()
                    });
                    this.listView1.Items.Add(lvItem);
                }

                SetMyCertPath(certPath);
            }
            catch (Exception ex)
            {
                SetMyCertPath(null);
                MsgBox.ShowInfo("查询失败," + ex.Message);
            }
            UpdateCertPathDisplay();
        }
Example #19
0
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            if (this.listView1.CheckedItems.Count < 1)
            {
                MsgBox.ShowInfo("请勾选账号!");
                return;
            }

            List <int> checkedRows = new List <int>();

            for (int i = 0; i < this.listView1.CheckedItems.Count; i++)
            {
                checkedRows.Add(this.listView1.CheckedItems[i].Index);
            }

            ThreadPool.QueueUserWorkItem(o =>
            {
                SetControlEnabled(this.toolStrip1, false);
                for (int i = 0; i < checkedRows.Count; i++)
                {
                    int index     = checkedRows[i];
                    string cookie = GetListViewItemValue(this.listView1, index, 3);

                    #region 查询余额
                    try
                    {
                        var goldInfo = PH.GetGoldInfo(cookie);
                        SetListViewItemValue(this.listView1, index, 5, goldInfo.balance + "金");
                    }
                    catch (Exception ex)
                    {
                        SetListViewItemValue(this.listView1, index, 5, "余额查询失败");
                    }
                    #endregion

                    #region 查询下次可抢购时间

                    try
                    {
                        var orders = PH.QueryOrders(cookie, OrderType.ALL, 1);
                        if (orders.Count > 0)
                        {
                            DateTime lastOrderCreateTime = PapdHelper.ConvertFromUnixTime(orders[0].createTime);
                            DateTime nextOrderCreateTime = lastOrderCreateTime.AddDays(GlobalContext.CurrentConfigInfo.CreateOrderTimespan);
                            var leftDays = Math.Round((nextOrderCreateTime - DateTime.Now).TotalDays, 1);
                            var msg      = string.Format("{0},下次抢购时间:{1}",
                                                         leftDays > 0 ? ("还有" + leftDays + "天") : "可抢",
                                                         nextOrderCreateTime.ToString("yyyy/MM/dd HH:mm:ss dddd"));
                            SetListViewItemValue(this.listView1, index, 6, msg);
                        }
                        else
                        {
                            SetListViewItemValue(this.listView1, index, 6, "可抢");
                        }
                    }
                    catch (Exception ex)
                    {
                        SetListViewItemValue(this.listView1, index, 6, "查询下次抢购时间失败");
                    }
                    #endregion
                }
                SetControlEnabled(this.toolStrip1, true);
            });
        }
Example #20
0
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            if (this.listView1.CheckedItems.Count < 1)
            {
                MsgBox.ShowInfo("请勾选账号!");
                return;
            }

            List <int> checkedRows = new List <int>();

            for (int i = 0; i < this.listView1.CheckedItems.Count; i++)
            {
                checkedRows.Add(this.listView1.CheckedItems[i].Index);
            }

            ThreadPool.QueueUserWorkItem(o =>
            {
                var configInfo = ConfigStorage.GetInstance().GetConfigInfo();
                SetControlEnabled(this.toolStrip1, false);
                for (int i = 0; i < checkedRows.Count; i++)
                {
                    int index             = checkedRows[i];
                    CookieInfo cookieInfo = GetListViewItemTag <CookieInfo>(this.listView1, index);
                    string cookie         = cookieInfo.Cookie;
                    string id             = cookieInfo.Id.ToString();
                    string cert           = cookieInfo.CertPath;

                    bool fetchYestodayReward = true;
                    if (configInfo.IsAutoFetchYesterdayBonus)
                    {
                        #region 领取昨日奖励
                        SetListViewItemValue(this.listView1, index, 7, "正在领取奖励");
                        try
                        {
                            var rewardInfo = PH.QueryRewardInfo(cookie, 3000);
                            if (!rewardInfo.IsPreMoneyFetch())
                            {
                                var fetchRewardResult = PH.FetchReward(cookie, rewardInfo.preRewardId);
                                SetListViewItemValue(this.listView1, index, 7, "昨日奖励领取成功!");
                            }
                            else
                            {
                                SetListViewItemValue(this.listView1, index, 7, "昨日奖励已领取。");
                            }
                        }
                        catch (Exception ex)
                        {
                            SetListViewItemValue(this.listView1, index, 7, "昨日奖励领取失败!");
                            fetchYestodayReward = false;
                        }
                        #endregion
                    }

                    Thread.Sleep(1000);

                    int grabGoldSuccess = 0;
                    if (configInfo.IsAutoGrabGold)
                    {
                        #region 抢金
                        SetListViewItemValue(this.listView1, index, 7, "正在抢金");
                        try
                        {
                            var grabGoldInfo = PH.GetGrabGoldInfo(cookie, 1);
                            for (int j = 0; j < grabGoldInfo.userRankingList.Length; j++)
                            {
                                var user = grabGoldInfo.userRankingList[j];
                                if (!user.IsGrabGoldAvailable())
                                {
                                    continue;
                                }
                                try
                                {
                                    PH.GrabGoldFromFollower(cookie, user.userInfo.userId);
                                    grabGoldSuccess++;
                                }
                                catch (Exception ex)
                                {
                                    SetListViewItemValue(this.listView1, index, 7, "抢金错误");
                                }
                            }
                            SetListViewItemValue(this.listView1, index, 7, "成功抢金" + grabGoldSuccess + "个好友!");
                        }
                        catch (Exception ex)
                        {
                            SetListViewItemValue(this.listView1, index, 7, "抢金失败");
                        }
                        #endregion
                    }

                    int fetchBoxCount = 0;
                    if (configInfo.IsAutoGrabTreasure)
                    {
                        #region 步步夺宝
                        SetListViewItemValue(this.listView1, index, 7, "正在夺宝...");
                        var fetchBoxFuncList = new List <Func <string, PajkResultList <PajkFetchBoxResult> > >();
                        fetchBoxFuncList.Add(PH.FetchBoxByShareReading);
                        fetchBoxFuncList.Add(PH.FetchBoxByWalkMall);
                        fetchBoxFuncList.Add(PH.FetchBoxByInviteFriend);
                        fetchBoxFuncList.Add(PH.FetchBoxByVideo);
                        for (int j = 0; j < fetchBoxFuncList.Count; j++)
                        {
                            try
                            {
                                var fetchResult = fetchBoxFuncList[j](cookie);
                                Thread.Sleep(1200);
                                SetListViewItemValue(this.listView1, index, 7, "得到宝箱:" + fetchResult.Content[0].BoxGiftList[0].GiftName);
                                fetchBoxCount += fetchResult.Content[0].BoxGiftList.Length;
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                        #endregion
                    }

                    Thread.Sleep(1000);

                    bool uploadWalkData = true;
                    float sc            = 0f;
                    if (configInfo.IsAutoUploadWalkData)
                    {
                        #region   走步数据

                        SetListViewItemValue(this.listView1, index, 7, "正在上传走步数据");
                        try
                        {
                            var downloadResult = PH.DownloadWalkData(id, cookie, cert);
                            if (downloadResult != null)
                            {
                                PajkWalkDataInfo today = null;
                                if (downloadResult.Content[0].walkDataInfos == null ||
                                    (today = downloadResult.Content[0].walkDataInfos.Find(
                                         match => match.walkDate == DateTime.Now.ToString("yyyyMMdd"))) == null)
                                {
                                    int stepCount = new Random((int)DateTime.Now.Ticks).Next(
                                        GlobalContext.CurrentConfigInfo.RandomMinStep,
                                        GlobalContext.CurrentConfigInfo.RandomMaxStep);
                                    sc         = stepCount;
                                    var result = PH.UploadWalkData(id, cookie, cert, stepCount);
                                    if (result.Content[0].Value)
                                    {
                                        SetListViewItemValue(this.listView1, index, 7, "成功上传走步" + stepCount + "!");
                                    }
                                    else
                                    {
                                        throw new Exception(result.Stat.Code.ToString());
                                    }
                                }
                                else
                                {
                                    sc = today.stepCount;
                                    SetListViewItemValue(this.listView1, index, 7, "今天已上传走步" + today.stepCount + "。");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            SetListViewItemValue(this.listView1, index, 7, "上传走步失败");
                            uploadWalkData = false;
                        }
                        #endregion
                    }

                    SetListViewItemValue(this.listView1, index, 7,
                                         string.Format("领取昨日奖励:{0},上传走步:{1},成功抢金:{2}个,得到宝箱:{3}个",
                                                       fetchYestodayReward?"成功":"失败",
                                                       uploadWalkData?sc.ToString():"失败",
                                                       grabGoldSuccess,
                                                       fetchBoxCount));
                }
                SetControlEnabled(this.toolStrip1, true);
            });
        }
Example #21
0
 public void UpdateItem(PH obj)
 {
     ctl.UpdateItem(obj);
 }
Example #22
0
 public void InsertItem(PH obj)
 {
     ctl.InsertItem(obj);
 }
Example #23
0
        /*Constructors*/



        public TransUnitElements(string transUnitText)
        {
            Regex bptTag = new Regex("<bpt.*?id=\"\\d+\"?>.*?</bpt>");
            Regex eptTag = new Regex("<ept.*?id=\"\\d+\"?>.*?</ept>");

            Regex itTag = new Regex("<it.*?(id=\"(\\d+)\")?>.*?</it>");
            Regex phTag = new Regex("<ph.*?(id=\"(\\d+)\")?>.*?</ph>");

            MatchCollection bptMatchList     = bptTag.Matches(transUnitText);
            var             listOfBptStrings = bptMatchList.Cast <Match>().Select(match => match.Value).ToList();

            MatchCollection eptMatchList     = eptTag.Matches(transUnitText);
            var             listOfEptStrings = eptMatchList.Cast <Match>().Select(match => match.Value).ToList();

            MatchCollection itMatchList     = itTag.Matches(transUnitText);
            var             listOfItStrings = itMatchList.Cast <Match>().Select(match => match.Value).ToList();

            MatchCollection phMatchList     = phTag.Matches(transUnitText);
            var             listOfPhStrings = phMatchList.Cast <Match>().Select(match => match.Value).ToList();

            /*I think that here there should be validation added to check if all corresponding elements in the list string
             * have the same index as matcheslist. */

            BPT auxiliaryBpt;
            EPT auxiliaryEpt;

            IT auxiliaryIt;
            PH auxiliaryPh;

            BptEptElement auxiliaryBptEptElement;

            int   auxiliaryIndex;
            Match bptMatch;
            Match eptMatch;

            /*Initializing list of BPT, EPT, PH and IT objects.*/

            foreach (string bpt in listOfBptStrings)
            {
                auxiliaryBpt = new BPT(bpt);
                listOfBpt.Add(auxiliaryBpt);
            }

            foreach (string ept in listOfEptStrings)
            {
                auxiliaryEpt = new EPT(ept);
                listOfEpt.Add(auxiliaryEpt);
            }

            foreach (string ph in listOfPhStrings)
            {
                auxiliaryPh = new PH(ph);
                listOfPh.Add(auxiliaryPh);
            }

            foreach (string it in listOfItStrings)
            {
                auxiliaryIt = new IT(it);
                listOfIt.Add(auxiliaryIt);
            }

            /*All all bpt tag has to have ept tag but not otherwise, so that's why I search through ept list and initialize
             * BptEpt objects.
             * 1 Case - Ept tag list is not empty. We want all pairs bpt-ept in this case.
             * 2 Case - Some Ept doesn't have a paired Bpt tag - so corresponding Bpt tag should be places in some previous
             * trans-unit note. We should be able to save this information.
             * 3 Case - Some Bpt tag doesn't have paired Ept tag so this information should be stored and used in the Case 2.
             * And in case of 2 and 3 we want to create a EptBpt object on the level of Xliff document. */

            if (listOfEpt.Count != 0)
            {
                foreach (EPT ept in listOfEpt)
                {
                    if (listOfBpt.Exists(x => x.ID == ept.ID))
                    {
                        auxiliaryIndex = listOfBpt.FindIndex(x => x.ID == ept.ID);
                        bptMatch       = bptMatchList[auxiliaryIndex];

                        auxiliaryIndex = listOfEpt.FindIndex(x => x.ID == ept.ID);
                        eptMatch       = eptMatchList[auxiliaryIndex];

                        auxiliaryBptEptElement = new BptEptElement(transUnitText.Substring(bptMatch.Index,
                                                                                           eptMatch.Index + eptMatch.Length - bptMatch.Index));

                        listOfBptEpt.Add(auxiliaryBptEptElement);
                    }
                    else
                    {
                        listEptNotPairedIDs.Add(ept.ID);
                    }
                }
            }
            else if (listOfBpt.Count != 0)
            {
                foreach (BPT bpt in listOfBpt)
                {
                    listBptNotPairedIDs.Add(bpt.ID);
                }
            }
        }
Example #24
0
 public int GetEnemyHitPoints(Point location, PH.Common.NanoBotInfo[] enemies)
 {
     foreach (PH.Common.NanoBotInfo nbi in enemies)
     {
         if (nbi.Location == location)
             return nbi.HitPoint;
     }
     return -1;
 }
Example #25
0
 public bool StillExist(Point location, PH.Common.NanoBotInfo[] bots)
 {
     foreach (PH.Common.NanoBotInfo nbi in bots)
     {
         if (location == nbi.Location)
             return true;
     }
     return false;
 }
Example #26
0
 public void InsertItem(PH obj)
 {
     defaultDB.ExecuteNonQuery("sp_PH_Insert"
                               , obj.CodeId, obj.Amount, obj.CurrentAmount, obj.CreateDate, obj.Status);
 }
Example #27
0
        public List <Move> Play(Stopwatch watch)
        {
// first turn: 1 planet each, same size
            // get neutral planets nearest / highest TimeToValue / Biggest!
            // (afhankelijk van hoe ver weg de tegenstander is, Bigger in begin better dan goedkoop klein planeetje vanwege verwachte langere duur spel)
            // TODO iets bedenken voor combinatie TimeToValue en nabijheid vijandelijke forces (of verwachte spelduur?)
            // TODO (neutral) planeet (veroveren) dichterbij vijand beter of juist niet?


            // check planets that turn from owner

            var healthQ = _gameState.GetHealthPlayerTotal(_me) / _gameState.GetHealthPlayerTotal(_enemyPlayer); // > 1 => winning! more aggressive?

            // Meer vanuit meerdere planeten tegelijk denken, vanuit meerdere planeten tegelijk naar 1 gezamenlijke neighbour sturen

            var myPlanets            = _gameState.Planets.Where(PH.IsMine).ToList();
            var planetsThatNeedHelp  = GetPlanetsThatNeedHelp(myPlanets);
            var planetsThatCanAttack = new List <Planet>(myPlanets);

//            Console.WriteLine($"# {watch.ElapsedMilliseconds} Checked helpless");
            HelpPlanets(planetsThatNeedHelp, planetsThatCanAttack);

//            Console.WriteLine($"# {watch.ElapsedMilliseconds} helped helpless");

            var possibleTargets = GetPossibleTargets();

//            Console.WriteLine($"# {watch.ElapsedMilliseconds} Checked targets");
            if (possibleTargets.hostiles.Any()) // TODO twee of meer... op basis van myPlanets.Count? misschien alleen Neutral? <---------------
            {
                var target  = possibleTargets.hostiles.First();
                var sources = target.NeighboringFriendlyPlanets;

                var source       = sources.First();
                var sourceHealth = source.Target.Health - PlanetMinHealth;
                var targetHealth = target.GetHealthAtTurnKnown(source.TurnsToReach).health;
                var powerNeeded  = targetHealth + PlanetMinTakeoverHealth;
                if (CheckIfEnoughHealthToSendShips(powerNeeded, source.Target))
                {
                    // TODO Check voor target.EnemyNeighbours die dichterbij zijn dan source.TurnsToReach  (en extract dit ff naar een method?) <--------------
//                    if (sourceHealth >= powerNeeded) // only if enemy planet can be taken
//                    {
                    AddMove(powerNeeded, source.Target,
                            target); // TODO meer sturen. Als andere enemy planet dichterbij is dan source, dan kunnen we elke turn allebei steeds een beetje sturen en blijft het alsnog van hem
                }

                // TODO loopje
                var source2 = sources.Skip(1).FirstOrDefault();
                if (source2 != null && !source.Target.InboundHostileShips.Any() && !source2.Target.InboundHostileShips.Any())
                {
                    var source2Health = source2.Target.Health - PlanetMinHealth;
                    var targetHealth2 = target.GetHealthAtTurnKnown(source2.TurnsToReach);
                    if (targetHealth2.owner != _me)
                    {
                        var powerNeeded2 = targetHealth2.health + PlanetMinTakeoverHealth;
                        if (sourceHealth + source2Health >= powerNeeded2) // only if enemy planet can be taken
                        {
                            var hq = (powerNeeded2) / (sourceHealth + source2Health);
                            // TODO half/half? dichtste meest? dichtste wachten tot even ver?
                            AddMove(hq * sourceHealth, source.Target,
                                    target); // TODO meer sturen. Als andere enemy planet dichterbij is dan source, dan kunnen we elke turn allebei steeds een beetje sturen en blijft het alsnog van hem
                            AddMove(hq * source2Health, source2.Target,
                                    target); // TODO meer sturen. Als andere enemy planet dichterbij is dan source, dan kunnen we elke turn allebei steeds een beetje sturen en blijft het alsnog van hem
                        }
                    }

//                    }
                }
            }
//            Console.WriteLine($"# {watch.ElapsedMilliseconds} sent to hostiles");

            if (possibleTargets.neutrals.Any())
            {
                var target = possibleTargets.neutrals.First();
                AttackNeutral(target);

                if (myPlanets.Count > 3)
                {
                    var target2 = possibleTargets.neutrals.Skip(1).FirstOrDefault();
                    if (target2 != null)
                    {
                        AttackNeutral(target2);
                    }
                }
            }
//            Console.WriteLine($"# {watch.ElapsedMilliseconds} sent to neutrals");

            // bij checken of je non-friendly planet wil aanvallen ook checken of je er niet al troepen heen hebt gestuurd
            foreach (var planet in planetsThatCanAttack)
            {
//                Console.WriteLine($"# {planet.Id}");
                if (planet.NeighboringPlanets.All(PH.IsMine)) // misschien ook als alleen Mine of Neutral, wanneer er andere planet is die wel NeighbouringEnemyPlanet heeft, om meer te focussen op enemy?
                {                                             // TODO mag ook als 1tje niet van mij is allemaal naar die sturen
//                    Console.WriteLine($"# {planet.Id} surrounded by friendly");
                    if (!planet.InboundHostileShips.Any())    // TODO zend zoveel als overblijft na laatste ship..
                    {
                        // TODO rekening houden met dat 1 van die planeten binnenkort naar de enemy gaat
                        var planetThatNeedsReinforcementsMost =
//                            planet.ShortestPaths.FirstOrDefault(p => PH.IsHostile(p.Target)).Via;
                            planet.NeighboringPlanets.OrderBy(p => p.NearestEnemyPlanetTurns).First(); // TODO which planet is that, houd rekening met HealthMax
                        // TODO divide between multiple planets?
                        var movePower = planet.Health - PlanetMinHealth;
                        AddMove(movePower, planet, planetThatNeedsReinforcementsMost, false);
                    }
                    continue;
                }

                // check of planeet wel health kan missen
//                var enemies = planet.NeighboringHostilePlanets.ToList();
                //planet.HealthPossibleToReceiveInTurns(enemyPlayer);
//                if (enemies.Any())
//                {
//                    foreach (var enemy in enemies)
//                    {
//                        var health = planet.GetHealthAtTurnKnown(enemy.TurnsToReach);
//                        var enemyHealth = enemy.Target.Health;
//                    }
//                }

                var closestEnemy   = planet.NeighbouringPlanetsDistanceTurns.FirstOrDefault(n => PH.IsHostile(n.Target));
                var closestNeutral = planet.NeighbouringPlanetsDistanceTurns.FirstOrDefault(n => PH.IsNeutral(n.Target));
                var target         = closestEnemy ?? closestNeutral; // kan niet null zijn want eerste if checkt alles Mine
//                var healthAtTurn = planet.GetHealthAtTurnKnown(target.TurnsToReach).health;

                var targetHealth = target.Target.GetHealthAtTurnKnown(target.TurnsToReach);
                if (targetHealth.owner == _me)//is al van mij?
                {
                    //choose other planet :) choose planet in loopje?
                    continue;
                }

                var powerNeeded = targetHealth.health + PlanetMinTakeoverHealth;
//                var planetHealth = planet.Health- PlanetMinHealth;
//                Console.WriteLine($"# {planet.Id} targetting {target.Target.Id} with {planetHealth} against {powerNeeded}");
                if (CheckIfEnoughHealthToSendShips(powerNeeded, planet))//planetHealth > powerNeeded && !planet.InboundShips.Any(PH.IsHostile))) // only if enemy planet can be taken
                {
                    AddMove(powerNeeded, planet, target.Target);
                    continue;
                }

                if (planet.HealthLimitAboutToBeExceeded) // too much health!
                {
                    var target2 = planet.NeighboringPlanets.First();
                    AddMove(planet.GrowthSpeed, planet, target2);
                }
            }

            return(_moves);
        }
Example #28
0
 public void UpdateItem(PH obj)
 {
     defaultDB.ExecuteNonQuery("sp_PH_Update"
                               , obj.ID, obj.CodeId, obj.Amount, obj.CurrentAmount, obj.CreateDate, obj.Status);
 }