//Updates a value on the table, or creates a new one in case it doesn't exist public void Update(Connection c, string s) { DataRow foundRows; string search = "Type = " + c.categorie.ToString() + " and Direction = " + c.side.ToString() + " and Distance = " + c.Distance().ToString(); foundRows = table.Select(search).FirstOrDefault(); if (foundRows != null) { foundRows["Solution"] = s; //changes the Solution } else { table.Rows.Add(c.categorie.ToString(), c.side.ToString(), c.Distance(), s); } }
public void InitializePathfindingSearch(RectangleCharacter startPosition) { Point initp = new Point(WM, WM.Character.xPos, WM.Character.yPos); Point aux = new Point(WM, 9999, 9999); float dist = 99999999999; foreach (Point p in WM.Mesh) { float auxd = initp.DistanceTo(p); if (auxd <= dist) { aux = p; dist = auxd; } } Connection c = new Connection(WM, initp, aux); c.categorie = c.SLIDEONPLATFORM; initp.addConnection(c); NodeRecord nri = new NodeRecord(); nri.node = initp; nri.gValue = 0; nri.hValue = 0; nri.fValue = 0; nri.Points = 0; var bestNode = nri; this.StartNode = initp; this.InProgress = true; this.TotalProcessedNodes = 0; this.MaxOpenNodes = 0; this.Open.Initialize(); this.Open.AddToOpen(bestNode); this.Closed.Initialize(); }
protected virtual NodeRecord GenerateChildNodeRecord(NodeRecord parent, Connection connectionEdge) { var childNodeRecord = new NodeRecord { node = connectionEdge.Destination, parent = parent, gValue = parent.gValue + connectionEdge.Destination.DistanceTo(parent.node) }; childNodeRecord.hValue = this.Heuristic.H(childNodeRecord); childNodeRecord.fValue = F(childNodeRecord); return childNodeRecord; }
public String getSolution(Connection cc) { DataRow foundRows; string search = "Type = " + cc.categorie.ToString() + " and Direction = " + cc.side.ToString(); foundRows = table.Select(search).FirstOrDefault(); if (foundRows != null) { return foundRows["Solution"].ToString(); } else { return null; } }
protected void ProcessChildNode(NodeRecord bestNode, Connection connectionEdge) { float f; float g; float h; var childNode = connectionEdge.Destination; //var childNodeRecord = this.NodeRecordArray.GetNodeRecord(childNode); var childNodeRecord = new NodeRecord(); childNodeRecord.node = childNode; childNodeRecord.parent = bestNode; childNodeRecord.parentConnection = connectionEdge; if (childNode.categorie == childNode.STAR_POINT) { int i = 0; foreach(NodeRecord nr in lstars) { if (childNodeRecord.Equals(nr)) { i = -1; break; } i++; } if(i >= 0) { lstars.Add(childNodeRecord); childNodeRecord.Points = i+1; } else { childNodeRecord.Points = childNodeRecord.parent.Points; } } else { childNodeRecord.Points = childNodeRecord.parent.Points; } // implement the rest of your code here if (childNodeRecord.status == NodeStatus.Closed) return; g = bestNode.gValue +1; h = this.Heuristic.H(childNodeRecord); f = F(g,h); if (childNodeRecord.status == NodeStatus.Open) { if (f <= childNodeRecord.fValue) { childNodeRecord.gValue = g; childNodeRecord.hValue = h; childNodeRecord.fValue = f; this.NodeRecordArray.Replace(childNodeRecord,childNodeRecord); } } else { childNodeRecord.gValue = g; childNodeRecord.hValue = h; childNodeRecord.fValue = f; childNodeRecord.status = NodeStatus.Open; this.NodeRecordArray.AddToOpen(childNodeRecord); } }
public String getAlternative(Connection cc) { DataRow[] foundRows; DataRow newRow; string search = "Type = " + cc.categorie.ToString() + " and Direction = " + cc.side.ToString(); foundRows = table.Select(search); newRow = table.Select(search).FirstOrDefault(); if (foundRows != null) { foreach (DataRow row in foundRows) { int a = Convert.ToInt32(row["Distance"]); int b = Convert.ToInt32(newRow["Distance"]); int c = cc.Distance(); if (Math.Abs(c - b) > Math.Abs(c - a)) { newRow = row; } } } return newRow["Solution"].ToString(); }
public void removeConnection(Connection con) { throw new NotImplementedException(); }
public void addConnection(Connection con) { this.ConnectionList.Add(con); }
public bool existConnection(Connection con) { throw new NotImplementedException(); }
public void GenerateConnections() { List<Point> tempMesh = new List<Point>(); while (this.OpenPoints.All().Count != 0) { Point op = this.OpenPoints.GetBestAndRemove(); if (this.OpenPoints.All().Count == 0) { } else { Point nop = this.OpenPoints.PeekBest(); //Right if (op.yMatrix == nop.yMatrix) { if (!this.WM.Matrix.CheckWallBetween(op, nop)) { if (this.WM.Matrix.CheckHoleBetween(op, nop)) { if (op.DistanceToInX(nop) <= 3 * this.WM.Matrix.WORLD_UNIT_SIZE) { Connection c = new Connection(WM, op, nop); c.categorie = c.SLIDEONHOLE; op.addConnection(c); c = new Connection(WM, nop, op); c.categorie = c.SLIDEONHOLE; nop.addConnection(c); } } else { Connection c = new Connection(WM, op, nop); c.categorie = c.SLIDEONPLATFORM; op.addConnection(c); c = new Connection(WM, nop, op); c.categorie = c.SLIDEONPLATFORM; nop.addConnection(c); } } } if (this.WM.Matrix.IsCollectible(op)) { if (!this.WM.Matrix.CheckPlatformBeneath(op)) { Point pf = this.WM.Matrix.GenerateNewPointFalling(op, this.WM.Matrix.DOWN); if (op.DistanceToInY(pf) <= 4 * this.WM.Matrix.WORLD_UNIT_SIZE) { Connection c = new Connection(WM, op, pf); c.categorie = c.FALLING; op.addConnection(c); c = new Connection(WM, pf, op); c.categorie = c.GRAB; pf.addConnection(c); pf.categorie = pf.GRAB_POINT; } else { Connection c = new Connection(WM, op, pf); c.categorie = c.FALLING; op.addConnection(new Connection(WM, op, pf)); } this.OpenPoints.AddToOpen(pf); } } else if (this.WM.Matrix.CheckPointForFalling(op)) { Point pf = this.WM.Matrix.GenerateNewPointFalling(op, this.WM.Matrix.DOWN); if (WM.Matrix.CheckDownForStar(op)) { Point ps = WM.Matrix.GenerateNewPointFallingStar(op); if (op.DistanceToInY(pf) >= 3 * this.WM.Matrix.WORLD_UNIT_SIZE) { ps = OpenPoints.SearchInOpen(ps); Connection c = new Connection(WM, op, ps); c.categorie = c.FALLING; op.addConnection(c); } else { Connection c = new Connection(WM, op, pf); c.categorie = c.FALLING; op.addConnection(c); c = new Connection(WM, pf, op); c.categorie = c.CLIMB; pf.categorie = pf.STAIR_POINT; pf.addConnection(c); } } else { //stair or gem TODO if (op.DistanceToInY(pf) <= 3 * this.WM.Matrix.WORLD_UNIT_SIZE) { Connection c = new Connection(WM, op, pf); c.categorie = c.FALLING; op.addConnection(c); c = new Connection(WM, pf, op); c.categorie = c.CLIMB; pf.categorie = pf.STAIR_POINT; pf.addConnection(c); } //fall else { Connection c = new Connection(WM, op, pf); c.categorie = c.FALLING; op.addConnection(c); } } op.categorie = op.CLIFF_POINT; this.OpenPoints.AddToOpen(pf); } } tempMesh.Add(op); } this.WM.Mesh = tempMesh.ToArray(); }
public bool isOutConn(Connection cc) { float xPos = this.CurrentRectangle.xPos; float yPos = this.CurrentRectangle.yPos; if (cc.side == cc.LEFT) if (xPos > cc.Origin.xPos + this.WM.Matrix.WORLD_UNIT_SIZE || xPos < cc.Destination.xPos - this.WM.Matrix.WORLD_UNIT_SIZE) return true; else if (xPos < cc.Origin.xPos - this.WM.Matrix.WORLD_UNIT_SIZE || xPos > cc.Destination.xPos + this.WM.Matrix.WORLD_UNIT_SIZE) return true; return false; }