Академический Документы
Профессиональный Документы
Культура Документы
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Stack;
import javax.imageio.ImageIO;
import javax.swing.*;
public String flood(int j, int i) { // ini kordinat hitam pertama pas dapet
String code = "";
Stack<Point> currNode = new Stack<>();
currNode.push(new Point(j, i));
while (!currNode.isEmpty()) {
Point curr = currNode.peek();
int x = (int) curr.getX();
int y = (int) curr.getY();
if (x < t[0]) {
t[0] = x;
}
if (y < t[1]) {
t[1] = y;
}
if (x > t[2]) {
t[2] = x;
}
if (y > t[3]) {
t[3] = y;
}
mark[x][y] = true;
if (isReadyToRun(x + 1, y - 1)) {
code += "1";
currNode.push(new Point(x + 1, y - 1));
} else if (isReadyToRun(x + 1, y)) {
code += "2";
currNode.push(new Point(x + 1, y));
} else if (isReadyToRun(x + 1, y + 1)) {
code += "3";
currNode.push(new Point(x + 1, y + 1));
} else if (isReadyToRun(x, y + 1)) {
code += "4";
currNode.push(new Point(x, y + 1));
} else if (isReadyToRun(x - 1, y + 1)) {
code += "5";
currNode.push(new Point(x - 1, y + 1));
} else if (isReadyToRun(x - 1, y)) {
code += "6";
currNode.push(new Point(x - 1, y));
} else if (isReadyToRun(x - 1, y - 1)) {
code += "7";
currNode.push(new Point(x - 1, y - 1));
} else if (isReadyToRun(x, y - 1)) {
code += "8";
currNode.push(new Point(x, y - 1));
} else {
currNode.pop();
}
}
return code;
}
}
}
}
}
}