id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
898bd535-dcc3-41f2-9e07-3f011000c5fa | public void interfaceGui(Container pane) {
// Definição de ABAS
JTabbedPane tabs = new JTabbedPane();
final String TAB1 = "Adicionar .REL";
final String TAB2 = "Adicionar .DAT";
final String TAB3 = "Gerar Arquivo de Entrada";
// ABA1
JPanel panel1 = new JPanel();
panel1.add(diretorioRELLabel);
panel1.add(diretorioREL);
panel1.add(procurarREL);
panel1.add(limparaba1);
// ABA2
JPanel panel2 = new JPanel();
panel2.add(diretorioDATLabel);
panel2.add(diretorioDAT);
panel2.add(procurarDAT);
panel2.add(limparaba2);
// ABA3
JPanel panel3 = new JPanel();
panel3.add(destinoSalvarLabel);
panel3.add(destinoSalvar);
panel3.add(procurarDestinoSalvar);
panel3.add(limparaba3);
panel3.add(gerarArquivos);
// Organiza��o das abas
tabs.add(panel1, TAB1);
tabs.add(panel2, TAB2);
tabs.add(panel3, TAB3);
pane.add(tabs, BorderLayout.CENTER);
procurarREL.addActionListener(new FormActionListener(FormActionListener.PROCURAR_REL,fchooser,frame, diretorioREL));
procurarDAT.addActionListener(new FormActionListener(FormActionListener.PROCURAR_DAT,fchooser,frame, diretorioDAT));
procurarDestinoSalvar.addActionListener(new FormActionListener(FormActionListener.PROCURAR_DESTINO,fchooser,frame, destinoSalvar));
//Limpar
limparaba1.addActionListener(new FormActionListener(FormActionListener.LIMPAR,fchooser,frame, diretorioREL));
limparaba2.addActionListener(new FormActionListener(FormActionListener.LIMPAR,fchooser,frame, diretorioDAT));
limparaba3.addActionListener(new FormActionListener(FormActionListener.LIMPAR,fchooser,frame, destinoSalvar));
//Gerar
gerarArquivos.addActionListener(new GuiLeitorREL.gerarArquivosAL());
} |
83df87b5-0454-45e7-9fa1-163186eb5a12 | public void itemStateChanged(ItemEvent evt) {
CardLayout cl = (CardLayout) (aba.getLayout());
cl.show(aba, (String) evt.getItem());
} |
0f6a15bd-e553-413e-a1b5-55dd6fc666d6 | private static void executarSistema() {
JFrame frame = new JFrame(":: GERADOR DO ARQUIVO DE ENTRADA ::");
frame.setDefaultCloseOperation(3);
frame.setLocation(420, 250);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GuiLeitorREL exe = new GuiLeitorREL();
exe.interfaceGui(frame.getContentPane());
frame.pack();
frame.setVisible(true);
} |
f5a59bc3-1290-40a2-8096-1bf1f13a8d28 | @SuppressWarnings("static-access")
public void actionPerformed(ActionEvent e){
ValidaFormUtil formUtil = new ValidaFormUtil(frame);
if(formUtil.validaCampos(diretorioREL.getText(), diretorioDAT.getText(),destinoSalvar.getText())){
List<FileREL> listFileREL = new Reader().getListFileREL(diretorioREL.getText());
FileDAT fileDAT = new Reader().getFileDAT(diretorioDAT.getText());
String path = destinoSalvar.getText();
int index = 1;
for (FileREL fileREL : listFileREL) {
if(formUtil.validaFileREL(fileREL)){
String pathCaso = path.concat("/CASO-0"+index);
File pastaCaso = new File(pathCaso);
pastaCaso.mkdir();
FileXLS fileXLS = new FileXLS();
fileXLS.setPath(pathCaso+"/"+fileREL.getFile().getName().replace(".rel", "")+".xls");
fileXLS.setSheetName("Tabela Verificação");
Formatter formatter = new Formatter(fileREL, fileDAT);
fileXLS.setListContent(formatter.FormatterXLS(new FileREL(), new FileDAT()));
Writer writer = new Writer();
writer.generateXLS(fileXLS);
index++;
}
}
JOptionPane.showMessageDialog(frame, "Arquivos gerados com sucesso na pasta: "+destinoSalvar.getText());
}
} |
6d230d08-98a6-45d4-9e36-87a5cc1b811a | public static void main(String[] args) {
try {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
} catch (UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
} catch (IllegalAccessException ex) {
ex.printStackTrace();
} catch (InstantiationException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
UIManager.put("swing.boldMetal", Boolean.FALSE);
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
executarSistema();
}
});
} |
e63b4b47-d50b-4821-b6ea-278412ce8bd8 | public void run() {
executarSistema();
} |
65afdc24-5b9e-4372-8d1d-f5b25025c9da | public FormActionListener(String action, JFileChooser jFileChooser, JFrame jFrame, JTextField jField) {
this.action = action;
fchooser = jFileChooser;
frame = jFrame;
field = jField;
} |
17c24150-74f6-48a3-84d2-3e3dcae8dea6 | public void actionPerformedREL(ActionEvent e) {
FileNameExtensionFilter filter = new FileNameExtensionFilter("Arquivos .REL","rel");
fchooser = new JFileChooser();
fchooser.setFileFilter(filter);
fchooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fchooser.enableInputMethods(true);
fchooser.showSaveDialog(frame);
field.setText(fchooser.getSelectedFile().getAbsolutePath());
} |
918487ba-9c10-4043-93f1-8e9fd36cefcb | public void actionPerformedDAT(ActionEvent e) {
FileNameExtensionFilter filter = new FileNameExtensionFilter("Arquivos .DAT","dat");
fchooser = new JFileChooser();
fchooser.setFileFilter(filter);
fchooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fchooser.enableInputMethods(true);
fchooser.showSaveDialog(frame);
field.setText(fchooser.getSelectedFile().getAbsolutePath());
} |
bb39197a-27f2-460c-83f3-50f3e58c91b3 | public void actionPerformedDestino(ActionEvent e) {
fchooser = new JFileChooser();
fchooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fchooser.enableInputMethods(true);
fchooser.showSaveDialog(frame);
field.setText(fchooser.getSelectedFile().getAbsolutePath());
} |
fcffa300-63b3-44fa-9dd6-98b149507a5e | private void actionPerformedLimpar(ActionEvent e) {
field.setText("");
} |
a055a4d5-c74f-41d6-8268-53dcf93087eb | @Override
public void actionPerformed(ActionEvent e) {
switch (action) {
case PROCURAR_REL:
this.actionPerformedREL(e);
break;
case PROCURAR_DAT:
this.actionPerformedDAT(e);
break;
case PROCURAR_DESTINO:
this.actionPerformedDestino(e);
break;
case LIMPAR:
this.actionPerformedLimpar(e);
break;
}
} |
dfad26f7-aba7-499a-a406-444b1bd2a4a1 | public static void main(String args[]) {
GameFrame f = new GameFrame();
f.setVisible(true);
} |
d4e1394c-9bed-4ca6-a52c-217a600c548a | public DataManager() {
try {
imgMenuBackground = ImageIO.read(new File("graphics\\menu\\menu.jpg"));
imgBackgroundCloud = ImageIO.read(new File("graphics\\background\\cloud.jpg"));
imgPlayer = new Image[10];
for (int i=0;i<10;i++) {
imgPlayer[i] = ImageIO.read(new File("graphics\\player\\player"+i+".png"));
}
imgPlayerHp = ImageIO.read(new File("graphics\\player\\hp.png"));
} catch (IOException e) {
e.printStackTrace();
}
} |
99355f3d-7c8d-4366-815f-34eced6c4d4b | public GameManager() {
dm = new DataManager();
menuScene = new MenuScene(dm.imgMenuBackground, null);
gameBackground = new GameBackground(dm.imgBackgroundCloud);
player = new GamePlayer(dm.imgPlayer, dm.imgPlayerHp);
} |
0ebd5941-0c98-4586-bb53-be5c19c36ed2 | @Override
public void logic() {
switch (gameState) {
case GAME_MENU:
break;
case GAME_IN:
gameBackground.logic();
player.logic();
break;
case GAME_WIN:
break;
case GAME_LOST:
break;
case GAME_PAUSE:
break;
}
} |
4fad472c-8f43-4793-9e81-e672e112fedb | @Override
public void draw(Graphics g) {
switch (gameState) {
case GAME_MENU:
menuScene.draw(g);
break;
case GAME_IN:
gameBackground.draw(g);
player.draw(g);
break;
case GAME_WIN:
break;
case GAME_LOST:
break;
case GAME_PAUSE:
break;
}
} |
ffd655ca-e714-4d5a-83ff-6b7d182c95cd | @Override
public void onKeyType(KeyEvent e) {
switch (gameState) {
case GAME_MENU:
break;
case GAME_IN:
break;
case GAME_WIN:
break;
case GAME_LOST:
break;
case GAME_PAUSE:
break;
}
} |
1e9b8bcb-8a0f-4498-8b50-6e6a27267af4 | @Override
public void onKeyDown(KeyEvent e) {
switch (gameState) {
case GAME_MENU:
menuScene.onKeyDown(e);
break;
case GAME_IN:
player.onKeyDown(e);
break;
case GAME_WIN:
break;
case GAME_LOST:
break;
case GAME_PAUSE:
break;
}
} |
d813c7ec-e211-4748-9f18-c0cef2cffdcc | @Override
public void onKeyUp(KeyEvent e) {
switch (gameState) {
case GAME_MENU:
break;
case GAME_IN:
player.onKeyUp(e);
break;
case GAME_WIN:
break;
case GAME_LOST:
break;
case GAME_PAUSE:
break;
}
} |
dec218bb-56a5-454e-b936-08d8e71d0051 | public void onKeyDown(KeyEvent e); |
2ec783b1-443b-4e07-8e79-db8159888958 | public void onKeyUp(KeyEvent e); |
0ba54007-94d3-49ed-9fc0-380ab81ce4a5 | public void onKeyType(KeyEvent e); |
17c56fa6-2a81-46b8-9e3a-088361638bdc | public void logic(); |
fac31167-df35-4106-a5a2-ec8fec7ef73d | public void draw(Graphics g); |
3bd9918b-7b34-4e10-bf5c-f34e5a0fed3e | public MenuScene(Image imgMB, Image imgSB) {
imgMenuBackground = imgMB;
//imgStartButton = imgSB;
//btnX = GameFrame.WIDTH / 2 - imgStartButton.getWidth(null) / 2;
//btnY = GameFrame.HEIGHT - imgStartButton.getHeight(null);
} |
abc1ab1c-5e11-46ee-ad98-586c7eb902a1 | public void draw(Graphics g) {
g.drawImage(imgMenuBackground, 0, 0, null);
g.drawString("Press Enter to start.", GameFrame.WIDTH / 2, GameFrame.HEIGHT / 2);
//g.drawImage(imgStartButton, btnX, btnY, null);
} |
37a3a654-17b8-44b3-98a4-43bdcabff4b6 | public void onKeyDown(KeyEvent e) {
if (e.getKeyCode()==KeyEvent.VK_ENTER) {
GameManager.gameState = GameManager.GAME_IN;
}
} |
1f7e9fe6-982c-4717-9e59-631dba405074 | public GameCharacter() {
hp = 1;
x = 0;
y = 0;
speed = 5;
} |
3cdf67d1-2258-47a0-822a-cf52aff2e407 | @Override
public abstract void logic(); |
b0a7cc4c-c496-42e2-90e7-e85add03dbaa | @Override
public abstract void draw(Graphics g); |
2ea319b2-e32e-4c1b-b4c0-c4af26cdb784 | public int getSpeed() {return speed;} |
0646e545-9750-42f3-8421-f473bbf54fc7 | public void setSpeed(int sp) {speed=sp;} |
e76291c6-b4e6-4225-a75f-77e8419c7d50 | public void setPos(int x,int y) {this.x=x;this.y=y;} |
ed0ab3e9-5feb-4a62-a8a1-acc11d98ae75 | public void setPosX(int x) {this.x=x;} |
6c90cf6b-6d88-4813-99e6-4f3d1069080b | public void setPosY(int y) {this.y=y;} |
d27977eb-e5ed-443c-b8fa-6bd5167ec660 | public int getPosX() {return x;} |
99a50056-01d3-4030-9dd8-6d8abcc17b70 | public int getPosY() {return y;} |
0479ab01-112d-4573-a778-94e26677c3d3 | public void setHp(int x) {hp=x;} |
283bfb22-409f-4908-8b61-0010a82d0abf | public int getHp(int x) {return hp;} |
6058393a-6b91-4a88-949c-a7e9d219a4d3 | public GamePlayer(Image img[],Image hpimg) {
super();
playerImage = img;
hpImage=hpimg;
this.setHp(5);
this.setPos(GameFrame.WIDTH/2,GameFrame.HEIGHT/8*7);
} |
4d53cbe1-72aa-4cba-a760-c8e4d18aed5a | @Override
public void logic() {
//System.out.println(isUp+" "+isDown+" "+isLeft+" "+isRight);
if (isUp) y-=speed;
if (isDown) y+=speed;
if (isLeft) x-=speed;
if (isRight) x+=speed;
} |
af387fda-be99-4e1f-96e1-6196dbab55a5 | @Override
public void draw(Graphics g) {
if (isLeft&&!isRight) {
g.drawImage(playerImage[8], x, y, null);
}
else if (isRight&&!isLeft) {
g.drawImage(playerImage[9], x, y, null);
}
else{
g.drawImage(playerImage[imgCnt], x, y, null);
count++;
if (count>=maxCount){
imgCnt=(imgCnt+1)%8;
count=0;
}
}
for (int i=0;i<hp;i++) {
g.drawImage(hpImage, i*hpImage.getWidth(null)+10, GameFrame.HEIGHT-hpImage.getHeight(null)-10, null);
}
} |
ba5f97af-eead-475a-82bd-7f902774228c | @Override
public void onKeyDown(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_UP:
isUp = true;
break;
case KeyEvent.VK_DOWN:
isDown = true;
break;
case KeyEvent.VK_LEFT:
isLeft = true;
break;
case KeyEvent.VK_RIGHT:
isRight = true;
break;
}
} |
79235fb7-026c-45d4-9a60-2bebf747c3fd | @Override
public void onKeyUp(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_UP:
isUp = false;
break;
case KeyEvent.VK_DOWN:
isDown = false;
break;
case KeyEvent.VK_LEFT:
isLeft = false;
break;
case KeyEvent.VK_RIGHT:
isRight = false;
break;
}
} |
62a18732-7dcd-46b7-8cfe-2c5065da9358 | @Override
public void onKeyType(KeyEvent e) {} |
d1dac37f-1baa-44c9-8340-eda10640c18b | public GameBackground(Image img) {
this.imgBackGround1 = img;
this.imgBackGround2 = img;
imgHeight = imgBackGround1.getHeight(null);
bg1x = 0;
bg1y = -Math.abs( imgHeight - GameFrame.HEIGHT);
bg2x = 0;
bg2y = bg1y - imgBackGround1.getHeight(null) + 1;
} |
e5e63965-648d-48eb-b72d-2c594c749636 | public void logic() {
bg1y += speed;
bg2y += speed;
if (bg1y > GameFrame.HEIGHT) {
bg1y = bg2y - imgHeight + 1;
}
if (bg2y > GameFrame.HEIGHT) {
bg2y = bg1y - imgHeight + 1;
}
} |
a7d2d745-a08b-4e46-886a-4b0038eb204b | public void draw(Graphics g) {
g.drawImage(imgBackGround1, bg1x, bg1y, null);
g.drawImage(imgBackGround2, bg2x, bg2y, null);
} |
c2c1cf7e-2978-4f26-a78e-1b4f6e3c573e | public int getSpeed() {
return speed;
} |
41bf1fd3-6601-4779-a98e-73648c88f295 | public void setSpeed(int sp) {
speed = sp;
} |
7458aaa4-12a7-482c-aad9-c081eca94fae | public GameEnemy() {
// TODO Auto-generated constructor stub
} |
5cdee90c-3244-44ea-8f9a-60447378a013 | @Override
public void logic() {
// TODO Auto-generated method stub
} |
f4a8a2cd-7994-4e6f-9037-0c9f7240a556 | @Override
public void draw(Graphics g) {
// TODO Auto-generated method stub
} |
9eaee1a3-349c-4155-afff-cb26de424204 | public static void search(SearchNode root) {
//use hash set for the fringe
Set<SearchNode> fringe = new HashSet<SearchNode>();
fringe.add(root);
while(!fringe.isEmpty()){
//find the min h+g for the nodes in the fringe
SearchNode curr = findMinGPlusH(fringe);
if(!curr.getState().isGoal()){
//generate the successor nodes
List<? extends SearchNode> succList = curr.getSuccessors();
for(int i = 0; i < succList.size(); i++){
SearchNode succ = succList.get(i);
if(!fringe.contains(succ)) fringe.add(succ);
}
}
// find the goal state
else{
curr.printSolution();
return;
}
}
System.out.println("Error! No solution found!");
} |
0c95aebd-fbfb-483a-a846-11d6934383db | private static SearchNode findMinGPlusH(Set<SearchNode> fringe) {
int min = Integer.MAX_VALUE;
SearchNode ans = null;
for(SearchNode check: fringe){
int checkI = check.getGPlusH();
if( checkI < min) {
min = checkI;
ans = check;
}
}
fringe.remove(ans);
return ans;
} |
495438d3-3b79-4b31-8973-67d96b0d957f | public FifteenState(int[][] board){
this.board = board;
} |
6b626129-08a9-49a6-bc65-3bc9bdea20d6 | public int[][] getBoard() {return board;} |
32dd9943-ac98-485a-be3f-e7fe98f12333 | public int[] getKDist(){return kDist;} |
91eba657-2422-45b7-8bcb-7f50be9691b0 | @Override
boolean isGoal() {
if((board.length != GOAL.length) || (board[0].length != GOAL[0].length)) return false;
for(int i = 0; i < board.length; i++){
for(int j = 0; j < board[0].length; j++){
if(board[i][j] != GOAL[i][j]) return false;
}
}
return true;
} |
a2067e7f-2210-4993-bca9-321c3939b4ed | @Override
int getSize(){return DIMENTION;} |
e4064a73-9944-443c-a88f-25ba9ac0b7dd | @Override
public List<StringBuffer> printState() {
List<StringBuffer> wState = new ArrayList<StringBuffer>();
for(int i = 0; i < DIMENTION; i++){
StringBuffer temp = new StringBuffer();
for(int j = 0; j < DIMENTION; j++){
temp.append(this.board[i][j] + ",");
}
temp.replace(temp.length()-1, temp.length(), "\n");
wState.add(temp);
}
return wState;
} |
fe8c9581-feda-4dfa-a8a8-0ac574b7507c | public static int[][] parseInitialState(String filename) throws IOException{
Scanner scanner = new Scanner(new File(filename)).useDelimiter(",|\\n");;
int[][] initialState = new int[DIMENTION][DIMENTION];
for(int i = 0; i < DIMENTION; i++){
for(int j = 0; j < DIMENTION; j++){
if(scanner.hasNextInt())
initialState[i][j] = scanner.nextInt();
}
}
return initialState;
} |
cd50f91b-8880-45d9-88a6-f8e63d7360ee | public SuperqueensState(int n) {
this.queenPositions = new ArrayList<Integer>();
this.n = n;
} |
8dd25210-2519-4eb1-8b2b-e5e974a458fb | public SuperqueensState(List<Integer> queenPositions, int n) {
this.queenPositions = queenPositions;
this.n = n;
} |
853a93f1-482c-466c-a0b4-e20f2ec31c2b | public int getQueenNum(){return n;} |
c148ba3c-acad-41db-a510-cc063f420f83 | @Override
public boolean isGoal() {return queenPositions.size() == n;} |
cc09b805-7ea9-40c9-b1fc-aa20c5c3bc3f | @Override
public int getSize(){return queenPositions.size();} |
ff1b2c3e-ddff-4ae6-9cca-d27b19f881e2 | public List<Integer> getQueensPositions(){return queenPositions;} |
95d37ce0-4e76-4a6b-94a8-9a338952a082 | @Override
public List<StringBuffer> printState() {
List<StringBuffer> wState = new ArrayList<StringBuffer>();
for (int i = 0; i < n; i++) {
StringBuffer temp = new StringBuffer();
for (int j = 0; j < n; j++) {
if (j < queenPositions.size() && queenPositions.get(j) == i) {
temp.append("Q");
} else {
temp.append("_");
}
temp.append(",");
}
temp.append("\n");
wState.add(temp);
}
return wState;
} |
44279629-cd32-4166-98b2-e12de2cc6be4 | abstract boolean isGoal(); |
b9e41958-3e3b-4882-87f3-1443bc8ead63 | abstract int getSize(); |
9e7981e3-8cdb-4385-bc59-01cccd2d09a1 | abstract List<StringBuffer> printState(); |
62e7c378-6739-4ffd-bf9d-aaba66c1b419 | public static void main(String[] args) throws IOException, NumberFormatException {
if (args.length < 1) {
System.out.println("Please use command \n"
+"java -jar yc173.jar \"tilepuzyc173\" \"tilepuzinput.txt\"\n"
+"or\n"
+"java -jar yc173.jar \"queensyc173\" n \n"
+"to run the jar file");
return;
}
if (args[0].equals("tilepuzyc173")) {
if (args.length < 2) {
System.out.println("Please input the input file name: tilepuzinput.txt");
return;
}
String filename = args[1];
int[][] intialState = FifteenState.parseInitialState(filename);
AStarSearch.search(FifteenSearchNode.generateRoot(intialState));
} else if (args[0].equals("queensyc173")) {
if (args.length < 2) {
System.out.println("Please input an int n for the number of queens");
return;
}
int nQueens = Integer.parseInt(args[1]);
AStarSearch.search(SuperqueensSearchNode.generateRoot(nQueens));
} else {
System.out.println("Unknown problem name: " + args[0]);
}
} |
79c4a333-18b7-4caa-81bc-ffbb7babd46b | protected SuperqueensSearchNode(State state, SearchNode parent, int gValue) {
super((SuperqueensState)state, parent, gValue);
} |
39adb3ca-5930-4c36-90a5-a98b6079cee3 | public static SuperqueensSearchNode generateRoot(int n){
SuperqueensState state = new SuperqueensState(n);
return new SuperqueensSearchNode(state,null, 0);
} |
b2cd928c-4ae6-4643-a178-bc399cdbe487 | @Override
//set heuristic value
protected int setHValue() {
int conflict = 0;
int n = state.getSize();
List<Integer> queensPositions = ((SuperqueensState)state).getQueensPositions();
for(int i = 0; i < n-1; i++){
for(int j = i+1; j < n; j++){
if(checkConflict(queensPositions.get(i), i, queensPositions.get(j), j))
conflict++;
}
}
return conflict;
} |
e3779af4-03d4-434e-893d-28e16c1dc38f | private boolean checkConflict(int x1, int y1, int x2, int y2) { // y1 < y2
// check same row
if (x1 == x2) return true;
// check diagonal move
if (Math.abs(x1 - x2) == Math.abs(y1 - y2)) return true;
// check knight's move
if (Math.abs(x1 - x2) + Math.abs(y1 - y2) == 3) return true;
return false;
} |
8c507584-a22f-4954-8a10-4a3e1cd1fc32 | @Override
public List<? extends SearchNode> getSuccessors() {
List<SuperqueensSearchNode> succList = new ArrayList<SuperqueensSearchNode>();
int n = ((SuperqueensState)state).getQueenNum();
for(int j = 0;j < n; j++){
List<Integer> childPositions = new ArrayList<Integer>(((SuperqueensState)state).getQueensPositions());
if(!childPositions.contains(j)){
childPositions.add(j);
SuperqueensState childState = new SuperqueensState(childPositions, n);
SuperqueensSearchNode childNode = new SuperqueensSearchNode
(childState, this, 0);
succList.add(childNode);
}
else continue;
}
return succList;
} |
2e2ea883-5a62-43c3-9012-3133a44bf428 | @Override
public boolean printSolution() {
System.out.println("numbers of queens that attack each other: "+getGPlusH());
List<StringBuffer> wState = ((SuperqueensState) this.getState()).printState();
writeToFile(wState);
return true;
} |
1f7941fa-5570-4bfe-b0fc-4ab266c9e41d | private boolean writeToFile(List<StringBuffer> wState) {
try {
File statText = new File("queens-yc173.csv");
FileOutputStream is = new FileOutputStream(statText);
OutputStreamWriter osw = new OutputStreamWriter(is);
Writer w = new BufferedWriter(osw);
for(int j = 0; j < wState.size(); j++){
w.write(wState.get(j).toString());
}
w.write("\n");
w.close();
} catch (IOException e) {
System.err.println("Can not write to the queens-yc173.csv");
}
return true;
} |
9d349627-6a1a-4d8b-ada4-e0dddd912122 | protected SearchNode(State state, SearchNode parent, int gValue){
this.state = state;
this.parent = parent;
this.gValue = gValue;
this.nodeNum = nodeCount++;
} |
ba70445f-c7e4-4b75-ad12-276660f7688d | public State getState(){return state;} |
f3b3d029-22ce-46fb-b744-dab8eae9b00c | public SearchNode getParent(){return parent;} |
8429826f-06b5-44a3-9bde-3b82a1c56a05 | public int getNodeNum(){return nodeNum;} |
8b2034fd-902e-47a8-bd90-85d7344d381e | public int getGValue(){return gValue;} |
31c4474f-5da1-4506-83ca-90627a4e9591 | public int getGPlusH(){
GPlusH = setHValue()+ getGValue();
return GPlusH;
} |
9ae2730a-b447-4291-97a9-70612fccf147 | abstract protected int setHValue(); |
fa34f1ba-0514-4767-aac1-ce72f9c82be9 | abstract public List<? extends SearchNode> getSuccessors(); |
69bdf93f-7ba9-4256-8eee-c68529c29ab4 | public Comparator<SearchNode> getComparator(){
return new Comparator<SearchNode>() {
public int compare(SearchNode n1, SearchNode n2){
if(n1.getGPlusH() < n2.getGPlusH()) return -1;
else if (n1.getGPlusH() > n2.getGPlusH()) return 1;
else if(n1.getGValue() > n2.getGValue() ) return -1;
else if(n1.getGValue() < n2.getGValue() ) return 1;
else if(n1.getNodeNum() < n2.getNodeNum()) return -1;
else return 1;
}
};
} |
73c45f59-37e5-4abc-b005-1d15fbdf0241 | public int compare(SearchNode n1, SearchNode n2){
if(n1.getGPlusH() < n2.getGPlusH()) return -1;
else if (n1.getGPlusH() > n2.getGPlusH()) return 1;
else if(n1.getGValue() > n2.getGValue() ) return -1;
else if(n1.getGValue() < n2.getGValue() ) return 1;
else if(n1.getNodeNum() < n2.getNodeNum()) return -1;
else return 1;
} |
a7623029-2aaa-453f-97d5-c16acce87146 | abstract public boolean printSolution(); |
afa8a68f-6b7a-4ac3-8bb6-59b8eed93729 | public FifteenSearchNode(State state, SearchNode parent, int gValue) {
super((FifteenState)state, parent, gValue);
} |
d745c36d-0089-4402-8d17-f9b6d35ebbf5 | public static FifteenSearchNode generateRoot(int[][] board){
FifteenState state = new FifteenState(board);
return new FifteenSearchNode(state,null, 0);
} |
a49a301d-800a-4269-b2c4-a61abc87fd17 | @Override
protected int setHValue() {
int dimension = state.getSize();
int[][] board = ((FifteenState)state).getBoard();
int[] kDist = ((FifteenState)state).getKDist();
hValue = 0;
for (int i = 0; i < dimension; i++) {
for (int j = 0; j < dimension; j++) {
if (board[i][j] != 0) {
int x = board[i][j]-1, y = 4*i+j;
hValue += kDist[16*x+y];
}
}
}
return hValue;
} |
d4e98183-a89c-4902-9e61-0021321b7cbf | @Override
public List<? extends SearchNode> getSuccessors() {
int dimension = state.getSize();
int[][] board = ((FifteenState)state).getBoard();
int hole = getHole(dimension,board);
int holeI = hole / dimension, holeJ = hole % dimension;
List<FifteenSearchNode> succList = new ArrayList<FifteenSearchNode>();
// the other can come to the hole
// llu
if( holeI < 3 && holeJ < 2)
swapAndStore(board,holeI+1,holeJ+2, holeI,holeJ, succList);
//luu
if( holeI < 2 && holeJ < 3)
swapAndStore(board,holeI+2,holeJ+1, holeI,holeJ, succList);
//rru
if( holeI < 3 && holeJ > 1)
swapAndStore(board,holeI+1,holeJ-2, holeI,holeJ, succList);
//ruu
if( holeI < 2 && holeJ >0)
swapAndStore(board,holeI+2,holeJ-1, holeI,holeJ, succList);
//lld
if( holeI > 0 && holeJ < 2)
swapAndStore(board,holeI-1,holeJ+2, holeI,holeJ, succList);
//ldd
if( holeI > 1 && holeJ < 3)
swapAndStore(board,holeI-2,holeJ+1, holeI,holeJ, succList);
//rrd
if( holeI > 0 && holeJ > 1)
swapAndStore(board,holeI-1,holeJ-2, holeI,holeJ, succList);
//rdd
if( holeI > 1 && holeJ > 0)
swapAndStore(board,holeI-2,holeJ-1, holeI,holeJ, succList);
return succList;
} |
f71a18d9-e0e8-4247-8376-69c24482936e | private int getHole(int dimension, int[][] board){//find position of zero
int index = 0;
for (int i = 0; i < dimension; i++) {
for (int j = 0; j < dimension; j++) {
if (board[i][j] == 0) return index;
else index++;
}
}
return index;
} |
1e641012-74f9-4775-ba49-13a6e8c37233 | private void swapAndStore(int[][] board, int aI, int aJ, int bI, int bJ, List<FifteenSearchNode> succList){
int[][] succ = copyBoard(board);
int temp = succ[aI][aJ];
succ[aI][aJ] = succ[bI][bJ];
succ[bI][bJ] = temp;
int newGValue = 0;
if(this != null) newGValue = this.gValue+1;
succList.add(new FifteenSearchNode(new FifteenState(succ), this, newGValue));
} |
104f6c84-d934-45c0-b2e1-1b380cb72476 | private int[][] copyBoard(int[][] board){
int[][]copy = new int[board.length][board[0].length];
for(int i = 0; i < board.length; i++){
for(int j = 0; j < board[0].length; j++){
copy[i][j] = board[i][j];
}
}
return copy;
} |
584f97d7-fec8-4feb-941a-1edc6997420d | @Override
public boolean printSolution(){
List<FifteenSearchNode> path = new ArrayList<FifteenSearchNode>();
FifteenSearchNode currNode = this;
while(currNode != null){
path.add(0,currNode);
currNode = (FifteenSearchNode) currNode.parent;
}
System.out.println("The total number of moves:" + this.getGValue());
writeToFile(path);
return true;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.