Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int islandCurrentX = -1;
- int islandCurrentY = -1;
- string direction = "Left";
- int count = 0;
- string pth = "";
- //testing
- currentTrackless.Width = 20;
- currentTrackless.Height = 20;
- //
- while ((islandCurrentX != islandStartX || islandCurrentY != islandStartY) && count < 500)
- {
- int tempIslandX = (islandCurrentX == -1 ? islandStartX : islandCurrentX);
- int tempIslandY = (islandCurrentY == -1 ? islandStartY : islandCurrentY);
- //break;
- count++;
- if (islandCurrentX == 144 && islandCurrentY == 420)
- //if(islandCurrentX==120 && islandCurrentY==233)
- {
- }
- if (direction == "Left")//left
- {
- DataRow[] drBetweenBridging = dtCurrentPattern.Select("" +
- "Starting_Y+Image_Length=" + tempIslandY + " and " +
- "Starting_X<" + tempIslandX + " and " +
- "Starting_X+Image_Width>" + tempIslandX + "");
- DataRow[] drNearestLeftwardsBRDG = dtCurrentPattern.Select("" +
- "Starting_Y=" + tempIslandY + " and " +
- "Starting_X<" + tempIslandX + "" +
- "" +
- "");
- drNearestLeftwardsBRDG = drNearestLeftwardsBRDG.OrderByDescending(row => (DataHelper.GetInt(row["Starting_X"]))).ToArray<DataRow>();
- DataRow[] drNearestLeftwards = dtCurrentPattern.Select("" +
- "Starting_Y+Image_Length=" + tempIslandY + " and " +
- "Starting_X+Image_Width=" + tempIslandX + "" +
- "" +
- "");
- DataRow[] drNearestLeftwards0 = dtCurrentPattern.Select("" +
- "Starting_Y=" + tempIslandY + " and " +
- "Starting_X+Image_Width<" + tempIslandX + "" +
- "" +
- "");
- drNearestLeftwards0 = drNearestLeftwards0.OrderByDescending(row => DataHelper.GetInt(row["Starting_X"])).ToArray<DataRow>();
- DataRow[] drNearestDownwards = dtCurrentPattern.Select("" +
- "Starting_Y<=" + tempIslandY + " and " +
- "Starting_Y+Image_Length>" + tempIslandY + " and " +
- "Starting_X+Image_Width=" + tempIslandX + "" +
- "" +
- "");
- DataRow[] drNearestDownwards0 = dtCurrentPattern.Select("" +
- "Starting_Y>" + tempIslandY + " and " +
- //"Starting_Y+Image_Length>=" + tempIslandY + " and " +
- "Starting_X=" + tempIslandX + "" +
- "" +
- "");
- drNearestDownwards0 = drNearestDownwards0.OrderBy(row => DataHelper.GetInt(row["Starting_Y"])).ToArray<DataRow>();
- DataRow[] drNearestUpwards = dtCurrentPattern.Select("" +
- "Starting_X=" + tempIslandX + " and " +
- "Starting_Y+Image_Length=" + tempIslandY + "" +
- "" +
- "");
- if((tempIslandX > 0 && drNearestDownwards.Length > 0))
- {
- islandCurrentX = tempIslandX;
- islandCurrentY = (DataHelper.GetInt(drNearestDownwards[0]["Starting_Y"]) + DataHelper.GetInt(drNearestDownwards[0]["Image_Length"]));
- direction = "Down";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drNearestLeftwards.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drNearestLeftwards[0]["Starting_X"]));
- islandCurrentY = tempIslandY;
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (((tempIslandX > 0 && drNearestDownwards.Length > 0) || (tempIslandX == 0 && drNearestDownwards0.Length > 0)|| (tempIslandY == 0 && drNearestLeftwards0.Length > 0)))// && drNearestLeftwards.Length == 0 )
- {
- if (tempIslandY == 0 && drNearestLeftwards0.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drNearestLeftwards0[0]["Starting_X"]) + DataHelper.GetInt(drNearestLeftwards0[0]["Image_Width"]));
- direction = "Down";
- }
- else
- {
- islandCurrentX = tempIslandX;
- if (tempIslandX == 0)
- islandCurrentY = (DataHelper.GetInt(drNearestDownwards0[0]["Starting_Y"]));
- else
- islandCurrentY = (DataHelper.GetInt(drNearestDownwards[0]["Starting_Y"]) + DataHelper.GetInt(drNearestDownwards[0]["Image_Length"]));
- if (islandCurrentX == 0)
- direction = "Right";
- else
- direction = "Down";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drNearestUpwards.Length > 0 && tempIslandX > 0)
- {
- islandCurrentX = tempIslandX;
- islandCurrentY = (DataHelper.GetInt(drNearestUpwards[0]["Starting_Y"]));
- direction = "Up";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drBetweenBridging.Length > 0)
- {
- if (drNearestLeftwardsBRDG.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drNearestLeftwardsBRDG[0]["Starting_X"]) + DataHelper.GetInt(drNearestLeftwardsBRDG[0]["Image_Width"]));
- islandCurrentY = (DataHelper.GetInt(drNearestLeftwardsBRDG[0]["Starting_Y"]) );
- direction = "Up";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else
- {
- islandCurrentX = 0;
- direction = "Up";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- }
- else
- {
- DataRow[] drMonai = dtCurrentPattern.Select("Starting_X=" + islandCurrentX + "" +
- " and Starting_Y=" + islandCurrentY + "");
- if (drMonai.Length > 0)
- {
- direction = "Right";
- }
- else
- {
- //islandCurrentX = 0;
- //islandCurrentY = tempIslandY;
- direction = "Down";
- }
- }
- pth += "\n"+islandCurrentX + ":" + islandCurrentY + ":" + "Left;";
- currentTrackless.Left = islandCurrentX;
- currentTrackless.Top = islandCurrentY;
- //MessageBox.Show(":" + currentTrackless.Left + ":" + currentTrackless.Top + ":");
- }
- else if (direction == "Down")//down
- {
- DataRow[] drBetweenBridging = dtCurrentPattern.Select("" +
- "Starting_X=" + tempIslandX + " and " +
- "Starting_Y<" + tempIslandY + " and " +
- "Starting_Y+Image_Length>" + tempIslandY + "");
- DataRow[] drNearestDownwardsBRDG = dtCurrentPattern.Select("" +
- "Starting_X=" + tempIslandX + " and " +
- "Starting_Y>" + tempIslandY + "" +
- "" +
- "");
- drNearestDownwardsBRDG = drNearestDownwardsBRDG.OrderBy(row => (DataHelper.GetInt(row["Starting_Y"]))).ToArray<DataRow>();
- DataRow[] drNearestDownwards = dtCurrentPattern.Select("" +
- "Starting_Y=" + tempIslandY + " and " +
- "Starting_X+Image_Width=" + tempIslandX + "" +
- "" +
- "");
- DataRow[] drNearestRightwards = dtCurrentPattern.Select("" +
- "Starting_Y=" + tempIslandY + " and " +
- "Starting_X<=" + tempIslandX + " and " +
- "Starting_X+Image_Width>" + tempIslandX + "" +
- "" +
- "");
- DataRow[] drNearestRightwards0 = dtCurrentPattern.Select("" +
- "Starting_Y=" + tempIslandY + " and " +
- "Starting_X>" + tempIslandX + " " +
- //"and " +
- //"Starting_X+Image_Width>=" + tempIslandX + "" +
- "" +
- "");//wrong
- drNearestRightwards0 = drNearestRightwards0.OrderBy(row => (DataHelper.GetInt(row["Starting_X"]))).ToArray<DataRow>();
- DataRow[] drNearestLeftwards = dtCurrentPattern.Select("" +
- "Starting_X+Image_Width=" + tempIslandX + " and " +
- "Starting_Y+Image_Length=" + tempIslandY + "" +
- "" +
- "");
- if (tempIslandY < pictureBox2.Height && drNearestRightwards.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drNearestRightwards[0]["Starting_X"]) + DataHelper.GetInt(drNearestRightwards[0]["Image_Width"]));
- direction = "Right";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drNearestDownwards.Length > 0)
- {
- islandCurrentX = tempIslandX;
- islandCurrentY = (DataHelper.GetInt(drNearestDownwards[0]["Starting_Y"]) + DataHelper.GetInt(drNearestDownwards[0]["Image_Length"]));
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (((tempIslandY < pictureBox2.Height && drNearestRightwards.Length > 0) || (tempIslandY == pictureBox2.Height && drNearestRightwards0.Length > 0)) && drNearestDownwards.Length == 0)
- {
- if (tempIslandY == pictureBox2.Height)
- islandCurrentX = (DataHelper.GetInt(drNearestRightwards0[0]["Starting_X"]));
- //islandCurrentX = (DataHelper.GetInt(drNearestRightwards[0]["Starting_X"]) + DataHelper.GetInt(drNearestRightwards[0]["Image_Width"]));
- else
- islandCurrentX = (DataHelper.GetInt(drNearestRightwards[0]["Starting_X"]) + DataHelper.GetInt(drNearestRightwards[0]["Image_Width"]));
- islandCurrentX = tempIslandX; ;
- if (tempIslandY == pictureBox2.Height)
- direction = "Right";
- else
- direction = "Right";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drNearestLeftwards.Length > 0 && tempIslandY < pictureBox2.Height)
- {
- islandCurrentX = (DataHelper.GetInt(drNearestLeftwards[0]["Starting_X"]));
- islandCurrentY = tempIslandY;
- direction = "Left";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drBetweenBridging.Length > 0)
- {
- if (drNearestDownwardsBRDG.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drNearestDownwardsBRDG[0]["Starting_X"]));
- islandCurrentY = (DataHelper.GetInt(drNearestDownwardsBRDG[0]["Starting_Y"]) );
- direction = "Up";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else
- {
- islandCurrentX = pictureBox2.Width;
- direction = "Up";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- }
- else
- {
- DataRow[] drMonai = dtCurrentPattern.Select("Starting_X=" + islandCurrentX + "" +
- " and Starting_Y+Image_Length=" + islandCurrentY + "");
- if (drMonai.Length > 0)
- {
- direction = "Right";
- }
- else
- //islandCurrentX = tempIslandX;
- //islandCurrentY = pictureBox2.Height;
- direction = "Down";
- //direction = "Up";prevCorr
- }
- pth += "\n" + islandCurrentX + ":" + islandCurrentY + ":" + "down;";
- currentTrackless.Left = islandCurrentX;
- currentTrackless.Top = islandCurrentY;
- //MessageBox.Show(":" + currentTrackless.Left + ":" + currentTrackless.Top + ":");
- }
- else if (direction == "Right")//right
- {
- DataRow[] drBetweenBridging = dtCurrentPattern.Select("" +
- "Starting_Y=" + tempIslandY + " and " +
- "Starting_X<" + tempIslandX + " and " +
- "Starting_X+Image_Width>" + tempIslandX + "");
- DataRow[] drNearestRightwardsBRDG = dtCurrentPattern.Select("" +
- "Starting_Y+Image_Length=" + tempIslandY + " and " +
- "Starting_X>" + tempIslandX + "" +
- "" +
- "");
- drNearestRightwardsBRDG = drNearestRightwardsBRDG.OrderBy(row => (DataHelper.GetInt(row["Starting_X"]) )).ToArray<DataRow>();
- DataRow[] drNearestRightwards = dtCurrentPattern.Select("" +
- "Starting_Y=" + tempIslandY + " and " +
- "Starting_X=" + tempIslandX + "" +
- "" +
- "");
- DataRow[] drNearestUpwards = dtCurrentPattern.Select("" +
- "Starting_Y<" + tempIslandY + " and " +
- "Starting_Y+Image_Length>=" + tempIslandY + " and " +
- "Starting_X=" + tempIslandX + "" +
- "" +
- "");
- DataRow[] drNearestUpwards0 = dtCurrentPattern.Select("" +
- "Starting_Y<" + tempIslandY + " and " +
- //"Starting_Y+Image_Length>=" + tempIslandY + " and " +
- "Starting_X+Image_Width=" + tempIslandX + "" +
- "" +
- "");
- drNearestUpwards0 = drNearestUpwards0.OrderByDescending(row => (DataHelper.GetInt(row["Starting_Y"])+ DataHelper.GetInt(row["Image_Length"]))).ToArray<DataRow>();
- DataRow[] drNearestDownwards = dtCurrentPattern.Select("" +
- "Starting_X+Image_Width=" + tempIslandX + " and " +
- "Starting_Y=" + tempIslandY + "" +
- "" +
- "");
- if((tempIslandX < pictureBox2.Width && drNearestUpwards.Length > 0))
- {
- islandCurrentY = (DataHelper.GetInt(drNearestUpwards[0]["Starting_Y"]));
- direction = "Up";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drNearestRightwards.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drNearestRightwards[0]["Starting_X"]) + DataHelper.GetInt(drNearestRightwards[0]["Image_Width"]));
- islandCurrentY = tempIslandY;
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (((tempIslandX < pictureBox2.Width && drNearestUpwards.Length > 0) || (tempIslandX == pictureBox2.Width && drNearestUpwards0.Length > 0)) && drNearestRightwards.Length == 0)
- {
- if (tempIslandX == pictureBox2.Width)
- islandCurrentY = (DataHelper.GetInt(drNearestUpwards0[0]["Starting_Y"]) + DataHelper.GetInt(drNearestUpwards0[0]["Image_Length"]));
- else
- islandCurrentY = (DataHelper.GetInt(drNearestUpwards[0]["Starting_Y"]) );
- islandCurrentX = tempIslandX;
- if (tempIslandX == pictureBox2.Width)
- direction = "Left";
- else
- direction = "Up";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drNearestDownwards.Length > 0 && tempIslandX < pictureBox2.Width)
- {
- islandCurrentX = tempIslandX;
- islandCurrentY = (DataHelper.GetInt(drNearestDownwards[0]["Starting_Y"])+ DataHelper.GetInt(drNearestDownwards[0]["Image_Length"]));
- //direction = 1;
- direction = "Down";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if(drBetweenBridging.Length>0)
- {
- if (drNearestRightwardsBRDG.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drNearestRightwardsBRDG[0]["Starting_X"]));
- islandCurrentY = (DataHelper.GetInt(drNearestRightwardsBRDG[0]["Starting_Y"]) + DataHelper.GetInt(drNearestRightwardsBRDG[0]["Image_Length"]));
- direction = "Up";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else
- {
- islandCurrentX = pictureBox2.Width;
- direction = "Up";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- }
- else
- {
- //islandCurrentX = pictureBox2.Width;
- //islandCurrentY = tempIslandY;
- //direction = "Down";
- DataRow[] drMonai = dtCurrentPattern.Select("Starting_X+Image_Width=" + islandCurrentX + "" +
- " and Starting_Y+Image_Length=" + islandCurrentY + "");
- if (drMonai.Length > 0)
- {
- direction = "Up";
- }
- else
- //direction = "Down";prevCorr
- direction = "Left";
- }
- //points.Add(new Point(islandCurrentX, islandCurrentY));
- pth += "\n" + islandCurrentX + ":" + islandCurrentY + ":" + "right;";
- currentTrackless.Left = islandCurrentX;
- currentTrackless.Top = islandCurrentY;
- //MessageBox.Show(":" + currentTrackless.Left + ":" + currentTrackless.Top + ":");
- }
- else if (direction == "Up")//all wrong//UP
- {
- DataRow[] drBetweenBridging = dtCurrentPattern.Select("" +
- "Starting_X+Image_width=" + tempIslandX + " and " +
- "Starting_Y<" + tempIslandY + " and " +
- "Starting_Y+Image_Length>" + tempIslandY + "");
- DataRow[] drNearestUpwardsBRDG = dtCurrentPattern.Select("" +
- "Starting_X+Image_width=" + tempIslandX + " and " +
- "Starting_Y<" + tempIslandY + "" +
- "" +
- "");
- drNearestUpwardsBRDG = drNearestUpwardsBRDG.OrderByDescending(row => (DataHelper.GetInt(row["Starting_Y"])+ DataHelper.GetInt(row["Image_Length"]))).ToArray<DataRow>();
- DataRow[] drNearestUpwards = dtCurrentPattern.Select("" +
- "Starting_Y+Image_Length=" + tempIslandY + " and " +
- "Starting_X=" + tempIslandX + "" +
- "" +
- "");
- DataRow[] drNearestLeftwards = dtCurrentPattern.Select("" +
- "Starting_X<=" + tempIslandX + " and " +
- "Starting_X+Image_Width>" + tempIslandX + " and " +
- "Starting_Y+Image_Length=" + tempIslandX + "" +
- "" +
- "");
- DataRow[] drNearestLeftwards0 = dtCurrentPattern.Select("" +
- "Starting_Y=" + tempIslandY + " and " +
- //"Starting_Y+Image_Length>=" + tempIslandY + " and " +
- "Starting_X<" + tempIslandX + "" +
- "" +
- "");
- drNearestLeftwards0 = drNearestLeftwards0.OrderByDescending(row => (DataHelper.GetInt(row["Starting_X"])+ DataHelper.GetInt(row["Image_Width"]))).ToArray<DataRow>();
- DataRow[] drNearestRightwards = dtCurrentPattern.Select("" +
- "Starting_X=" + tempIslandX + " and " +
- "Starting_Y=" + tempIslandY + "" +
- "" +
- "");
- if (tempIslandY > 0 && drNearestLeftwards.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drNearestLeftwards[0]["Starting_X"]));
- direction = "Right";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drNearestUpwards.Length > 0)
- {
- islandCurrentX = tempIslandX;
- islandCurrentY = DataHelper.GetInt(drNearestUpwards[0]["Starting_Y"]);
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- if (((tempIslandY > 0 && drNearestLeftwards.Length > 0) || (tempIslandY == 0 && drNearestLeftwards0.Length > 0))&& drNearestUpwards.Length == 0)
- {
- if (tempIslandY == 0)
- islandCurrentX = (DataHelper.GetInt(drNearestLeftwards0[0]["Starting_X"]) + DataHelper.GetInt(drNearestLeftwards0[0]["Image_Width"]));
- else
- islandCurrentX = (DataHelper.GetInt(drNearestLeftwards[0]["Starting_X"]) );
- islandCurrentY = tempIslandY;
- if (tempIslandY == 0)
- direction = "Down";
- else
- direction = "Right";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drNearestLeftwards.Length > 0 && tempIslandY > 0)
- {
- islandCurrentX = DataHelper.GetInt(drNearestLeftwards[0]["Starting_X"]);
- islandCurrentY = tempIslandY;
- direction = "Left";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drBetweenBridging.Length > 0)
- {
- if (drNearestUpwardsBRDG.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drNearestUpwardsBRDG[0]["Starting_X"]) + DataHelper.GetInt(drNearestUpwardsBRDG[0]["Image_Width"]));
- islandCurrentY = (DataHelper.GetInt(drNearestUpwardsBRDG[0]["Starting_Y"])+ DataHelper.GetInt(drNearestUpwardsBRDG[0]["Image_Length"]));
- direction = "Up";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else
- {
- islandCurrentX = 0;
- direction = "Up";
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- }
- else
- {
- DataRow[] drMonai = dtCurrentPattern.Select("Starting_X+Image_Width=" + islandCurrentX + "" +
- " and Starting_Y=" + islandCurrentY + "");
- if (drMonai.Length > 0)
- {
- direction = "Left";
- }
- //islandCurrentX = tempIslandX;
- //islandCurrentY = 0;
- else
- //direction = "Left";//prevCorr
- direction = "Down";
- }
- pth += "\n" + islandCurrentX + ":" + islandCurrentY + ":" + "up;";
- currentTrackless.Left = islandCurrentX;
- currentTrackless.Top = islandCurrentY;
- //MessageBox.Show(":" + currentTrackless.Left + ":" + currentTrackless.Top + ":");
- }
- pth += "\n" + islandCurrentX + ":" + islandCurrentY + ":" + "up;";
- currentTrackless.Left = islandCurrentX;
- currentTrackless.Top = islandCurrentY;
- //MessageBox.Show(":" + currentTrackless.Left + ":" + currentTrackless.Top + ":");
- }
- }
Add Comment
Please, Sign In to add comment