protected override void CheckingNewRevealed(Vector2Int currentnewrevealed) { //count the number of neighbores of this tile List <Vector2Int> newClosedHiddenNeighbors = new List <Vector2Int>(); ClosedHiddenNeighbores.Add(currentnewrevealed, newClosedHiddenNeighbors); for (int j = 0; j < Operators.Length; j++) { Vector2Int current = currentnewrevealed + Operators[j]; if (Flaged.Contains(current)) { Closed[currentnewrevealed]--; } else if (MinesweeperElementInfo.InBounds(current, BoardSize.x, BoardSize.y)) { if (Open.ContainsKey(current) || Safe.Contains(current) || Mine.Contains(current)) { newClosedHiddenNeighbors.Add(current); List <Vector2Int> clist = HiddenClosedRelations[current]; clist.Add(currentnewrevealed); } else if (!InvalidTiles[current.x, current.y] && !Closed.ContainsKey(current)) { Open.Add(current, 0); newClosedHiddenNeighbors.Add(current); List <Vector2Int> clist = new List <Vector2Int>(); HiddenClosedRelations.Add(current, clist); clist.Add(currentnewrevealed); } } } }
/// <summary> /// >=1 means added /// 0 means last element updated /// -1 means nothing changed /// </summary> /// <param name="t"></param> /// <param name="o"></param> /// <param name="h"></param> /// <param name="l"></param> /// <param name="c"></param> /// <param name="v"></param> /// <param name="isTriggerDataAdded"></param> /// <returns></returns> public int AddUpdate(long t, double o, double h, double l, double c, double v, bool isTriggerDataAdded = false) { if (this.Count == 0 || t > this.LastTime) { Open.Add(o); High.Add(h); Low.Add(l); Close.Add(c); Volume.Add(v); Time.Add(t); if (isTriggerDataAdded) { OnDataAddedOrUpdated?.Invoke(this, this, 1); } return(1); } else if (t == this.LastTime) { Open[this.Count - 1] = o; High[this.Count - 1] = h; Low[this.Count - 1] = l; Close[this.Count - 1] = c; Volume[this.Count - 1] = v; if (isTriggerDataAdded) { OnDataAddedOrUpdated?.Invoke(this, this, 0); } return(0); } return(-1); }
private void InsertPoint(EndPoint p) { if (p.Begin) { bool inserted = false; for (int index = 0; index < Open.Count; index++) { Segment test = Open[index]; if (Segment.IsInFrontOf(p.Segment, test, Center) != Segment.IntersectionResult.InFront) { Open.Insert(index, p.Segment); inserted = true; break; } } if (!inserted) { Open.Add(p.Segment); } } else { Open.Remove(p.Segment); } }
protected virtual void ProcessChildNode(NodeRecord bestNode, NavigationGraphEdge connectionEdge) { //this is where you process a child node var childNode = GenerateChildNodeRecord(bestNode, connectionEdge); //Get the cost estimate for the end node NavigationGraphNode endNode = connectionEdge.ToNode; float endNodeCost = bestNode.gValue + connectionEdge.Cost; //If the node is closed we may have to skip, or remove it from the close list. if (Closed.contains(endNode)) { NodeRecord endNodeRecord = Closed.find(endNode); //should find this in the closed list if (endNodeRecord.gValue <= endNodeCost) { continue; } Closed.Remove(endNodeRecord); float endNodeHeuristic = endNodeRecord.fValue - endNodeRecord.gValue; } else if (Open.contains(endNode)) { NodeRecord endNodeRecord = Open.find(endNode); if (endNodeRecord.gValue <= endNodeCost) { continue; } float endNodeHeuristic = endNodeRecord.fValue - endNodeRecord.gValue; } else { NodeRecord endNodeRecord = new NodeRecord(); endNodeRecord.node = endNode; var endNodeHeuristic = this.Heuristic.H(endNode, GoalNode); endNodeRecord.gValue = endNodeCost; endNodeRecord.parent = bestNode; endNodeRecord.fValue = endNodeCost + endNodeHeuristic; if (!Open.contains(endNode)) { Open.Add(endNodeRecord); } } }
public int AddUpdate(string symbol, int interval, long t, double o, double h, double l, double c, double v, bool isTriggerDataAdded = false) { if (this.Symbol != symbol || this.Interval < interval || this.Interval % interval != 0) { return(0); } var time = t / this.Interval * this.Interval; if (this.Count == 0 || time > this.LastTime) { Open.Add(o); High.Add(h); Low.Add(l); Close.Add(c); Volume.Add(v); Time.Add(time); if (isTriggerDataAdded) { OnDataAddedOrUpdated?.Invoke(this, this, 1); } return(1); } else if (time == this.LastTime) { High[this.Count - 1] = Math.Max(h, High[this.Count - 1]); Low[this.Count - 1] = Math.Min(Low[this.Count - 1], l); Close[this.Count - 1] = c; if (interval == this.Interval) { Volume[this.Count - 1] = v; } else { Volume[this.Count - 1] += v; } if (isTriggerDataAdded) { OnDataAddedOrUpdated?.Invoke(this, this, 0); } return(0); } return(-1); }
/// <summary> /// Iterates through 'currentnewrevealed', checking if 'currentnewrevealed' can be discarded, /// while adding new open tile /// </summary> /// <param name="currentnewrevealed"></param> protected virtual void CheckingNewRevealed(Vector2Int currentnewrevealed) { for (int j = 0; j < Operators.Length; j++) { Vector2Int current = currentnewrevealed + Operators[j]; if (Flaged.Contains(current)) { Closed[currentnewrevealed]--; } else if (MinesweeperElementInfo.InBounds(current, BoardSize.x, BoardSize.y)) { //i wanted to make the minesweeper and the solver independent from eachother, thats why i didn't simply passed the minesweeperelementinfo object at 'current' tile if (!InvalidTiles[current.x, current.y] && !Open.ContainsKey(current) && !Closed.ContainsKey(current) && !Safe.Contains(current) && !Mine.Contains(current)) { Open.Add(current, 0); } } } }
/* * A-Star Algorithm * Open- List of opened nodes * Closed- List of closed nodes * InOpen: returns a node if it is present in Open, else null * InClosed: returns a node if it is present in Closed, else null */ static Node AStar(Node root) { Open.Add(root); while (Open.Count != 0) { var node = Open.First(); Closed.Add(node); Open.RemoveAt(0); if (node.HeuristicValue == 0) { return(node); } foreach (var child in node.GenerateChildren()) { var InOpen = Open.Where(x => x.IsEqual(child)).FirstOrDefault(); var InClosed = Closed.Where(x => x.IsEqual(child)).FirstOrDefault(); if (child.HeuristicValue == 0) { return(child); } if (InClosed != null && InClosed.Level > child.Level) { Closed.Remove(InClosed); Open.Add(child); } else if (InOpen != null && InOpen.Level > child.Level) { InOpen.Level = child.Level; InOpen.Parent = child.Parent; } else { Open.Add(child); } } Open = Open.OrderBy(x => x.FScore).ToList(); } return(null); }
/// <summary> /// This method was used before Invalidtiles /// </summary> /// <param name="answer">Data received from AIRequestProvider.GetRequestedMinesweeperElementInfos method</param> public void AnswerProcecessor(KeyValuePair <AIDataType, KeyValuePair <Vector2Int, MinesweeperElementInfo>[]>[] answer) { for (int i = 0; i < answer.Length; i++) { AIDataType requestType = answer[i].Key; KeyValuePair <Vector2Int, MinesweeperElementInfo>[] currentanswer = answer[i].Value; for (int j = 0; j < currentanswer.Length; j++) { Vector2Int currenttile = currentanswer[j].Key; MinesweeperElementInfo currentmsei = currentanswer[j].Value; if (currentmsei.hidden) { switch (requestType) { case AIDataType.Open: { //for safety, i only allow tiles to be considered safe if they were previusly open //so here i check if they belong to 'Safe' if (NextToInvalidTile(currenttile)) { Safe.Add(currenttile); } else { Open.Add(currenttile, 0); } break; } case AIDataType.Safe: { Safe.Add(currenttile); break; } } } } } }
public override void Visit(Open open) { // include links to all the query dsl usage and aggregation usage pages on the landing query dsl and aggregations pages, respectively. string usageFilePath; if (IncludeDirectories.TryGetValue(_destination.Name, out usageFilePath)) { var usageDoc = Document.Load(Path.Combine(Program.OutputDirPath, usageFilePath)); var includeAttribute = usageDoc.Attributes.FirstOrDefault(a => a.Name == "includes-from-dirs"); if (includeAttribute != null) { var directories = includeAttribute.Value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var list = new UnorderedList(); foreach (var directory in directories) { foreach (var file in Directory.EnumerateFiles(Path.Combine(Program.OutputDirPath, directory), "*usage.asciidoc", SearchOption.AllDirectories)) { var fileInfo = new FileInfo(file); var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.Name); list.Items.Add(new UnorderedListItem { new Paragraph(new InternalAnchor(fileNameWithoutExtension, fileNameWithoutExtension.LowercaseHyphenToPascal())) }); } } open.Add(list); } } base.Visit(open); }
/// <summary> /// Checks the whole board /// </summary> /// <param name="table"> The whole minesweeper table</param> public override void GetBoard(MinesweeperElementInfo[,] table) { List <Vector2Int> newpositions = new List <Vector2Int>(); for (int y = 0; y < table.GetLength(1); y++) { for (int x = 0; x < table.GetLength(0); x++) { MinesweeperElementInfo current = table[x, y]; Vector2Int currentpos = new Vector2Int(x, y); if (!current.hidden && current.value > 0) { if (!Closed.ContainsKey(currentpos)) { newpositions.Add(currentpos); } } } } for (int i = 0; i < newpositions.Count; i++) { for (int j = 0; j < Operators.Length; j++) { Vector2Int current = newpositions[i] + Operators[j]; //in bounds if (current.x >= 0 && current.y >= 0 && current.x < table.GetLength(1) && current.y < table.GetLength(0)) { if (table[current.x, current.y].hidden && !table[current.x, current.y].flaged && !Open.ContainsKey(current)) { Open.Add(current, 0); } } } Closed.Add(newpositions[i], table[newpositions[i].x, newpositions[i].y].value); } }
protected override void OnBarUpdate() { DateTime dtBegin = DateTime.MaxValue; switch (IntervalType) { case EnumIntervalType.Sec: dtBegin = MinBar.D.Date.AddHours(MinBar.D.Hour).AddMinutes(MinBar.D.Minute).AddSeconds(MinBar.D.Second / Interval * Interval); break; case EnumIntervalType.Min: dtBegin = MinBar.D.Date.AddHours(MinBar.D.Hour).AddMinutes(MinBar.D.Minute / Interval * Interval); break; case EnumIntervalType.Hour: dtBegin = MinBar.D.Date.AddHours(MinBar.D.Hour / Interval * Interval); break; case EnumIntervalType.Day: dtBegin = DateTime.ParseExact(MinBar.TradingDay.ToString(), "yyyyMMdd", null); break; case EnumIntervalType.Week: dtBegin = DateTime.ParseExact(MinBar.TradingDay.ToString(), "yyyyMMdd", null); dtBegin = dtBegin.Date.AddDays(1 - (byte)dtBegin.DayOfWeek); break; case EnumIntervalType.Month: dtBegin = DateTime.ParseExact(MinBar.TradingDay.ToString(), "yyyyMMdd", null); dtBegin = new DateTime(dtBegin.Year, dtBegin.Month, 1); break; case EnumIntervalType.Year: dtBegin = DateTime.ParseExact(MinBar.TradingDay.ToString(), "yyyyMMdd", null); dtBegin = new DateTime(dtBegin.Year, 1, 1); break; default: throw new Exception("参数错误"); } if (bar == null) //首次调用 { bar = new Bar { D = dtBegin, I = MinBar.I, V = MinBar.V, // kOld.preVol == 0 ? 0 : _tick.Volume - kOld.preVol; }; bar.H = MinBar.H; bar.L = MinBar.L; bar.O = MinBar.O; bar.C = MinBar.C; newbar = true; } else { if (bar.D == dtBegin) //在当前K线范围内 { newbar = false; bar.H = Math.Max(bar.H, MinBar.H); bar.L = Math.Min(bar.L, MinBar.L); bar.C = MinBar.C; bar.V = bar.V + MinBar.V; bar.I = MinBar.I; } else if (dtBegin > bar.D) { newbar = true; bar.D = dtBegin; bar.V = MinBar.V; bar.I = MinBar.I; bar.O = MinBar.O; bar.H = MinBar.H; bar.L = MinBar.L; bar.C = MinBar.C; } } if (newbar) { Date.Add(double.Parse(bar.D.ToString("yyyyMMdd"))); Time.Add(double.Parse(bar.D.ToString("0.HHmmss"))); Open.Add(bar.O); High.Add(bar.H); Low.Add(bar.L); Close.Add(bar.C); Volume.Add(bar.V); OpenInterest.Add(bar.I); } else { High[0] = bar.H; Low[0] = bar.L; Close[0] = bar.C; Volume[0] = bar.V; OpenInterest[0] = bar.I; } }
protected override void OnBarUpdate() { DateTime dtBegin = DateTime.MaxValue; switch (IntervalType) { case IntervalType.Sec: dtBegin = MinBar.Time.Date.AddHours(MinBar.Time.Hour).AddMinutes(MinBar.Time.Minute).AddSeconds(MinBar.Time.Second / Interval * Interval); break; case IntervalType.Min: dtBegin = MinBar.Time.Date.AddHours(MinBar.Time.Hour).AddMinutes(MinBar.Time.Minute / Interval * Interval); break; case IntervalType.Hour: dtBegin = MinBar.Time.Date.AddHours(MinBar.Time.Hour / Interval * Interval); break; case IntervalType.Day: dtBegin = DateTime.ParseExact(MinBar.TradingDay.ToString(), "yyyyMMdd", null); break; case IntervalType.Week: dtBegin = DateTime.ParseExact(MinBar.TradingDay.ToString(), "yyyyMMdd", null); dtBegin = dtBegin.Date.AddDays(1 - (byte)dtBegin.DayOfWeek); break; case IntervalType.Month: dtBegin = DateTime.ParseExact(MinBar.TradingDay.ToString(), "yyyyMMdd", null); dtBegin = new DateTime(dtBegin.Year, dtBegin.Month, 1); break; case IntervalType.Year: dtBegin = DateTime.ParseExact(MinBar.TradingDay.ToString(), "yyyyMMdd", null); dtBegin = new DateTime(dtBegin.Year, 1, 1); break; default: throw new Exception("参数错误"); } if (bar == null) //首次调用 { bar = new Bar { Time = dtBegin, Volume = MinBar.Volume, // kOld.preVol == 0 ? 0 : _tick.Volume - kOld.preVol; }; bar.High = MinBar.High; bar.Low = MinBar.Low; bar.Open = MinBar.Open; bar.Close = MinBar.Close; newbar = true; } else { if (bar.Time == dtBegin) //在当前K线范围内 { newbar = false; bar.High = Math.Max(bar.High, MinBar.High); bar.Low = Math.Min(bar.Low, MinBar.Low); bar.Close = MinBar.Close; bar.Volume = bar.Volume + MinBar.Volume; } else if (dtBegin > bar.Time) { newbar = true; bar.Time = dtBegin; bar.Volume = MinBar.Volume; bar.Open = MinBar.Open; bar.High = MinBar.High; bar.Low = MinBar.Low; bar.Close = MinBar.Close; } } if (newbar) { Date.Add(double.Parse(bar.Time.ToString("yyyyMMdd"))); Time.Add(double.Parse(bar.Time.ToString("0.HHmmss"))); Open.Add(bar.Open); High.Add(bar.High); Low.Add(bar.Low); Close.Add(bar.Close); Volume.Add(bar.Volume); } else { High[0] = bar.High; Low[0] = bar.Low; Close[0] = bar.Close; Volume[0] = bar.Volume; } }