package basic;
import java.util.List;
import search.Search;
import puzzle.SubProblem;
public abstract class Problem {
State initialState;
List actions;
GoalTest goaltest;
public Problem(){
};
public void Set(State initialS, List actionslist, GoalTest gtest)
{
initialState = initialS;
goaltest = gtest;
actions = actionslist;
};
public Solution solve(Search buscador) {
Node root = new Node(getInitialState());
return buscador.findSolution(root,getActions(),getGoaltest());
}
/**
* @return Returns the initialState.
*/
public State getInitialState() {
return initialState;
}
/**
* @return Returns the actions.
*
*/
public List getActions() {
return actions;
}
/**
* @return Returns the goaltest.
*/
public GoalTest getGoaltest() {
return goaltest;
}
}
// interfaz State
package basic;
public interface State {
public boolean possible(Accion action);
public State successor(Accion action);
public State copy();
public int compareTo(State state);
}
// interfaz Goaltest
package basic;
import java.util.List;
public interface GoalTest {
public boolean isGoalState(State state);
public State hasGoalState(List states);
}
// JFrame principal
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package puzzle;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
/**
*
* @author Asus
*/
public class Puzzle_JF extends javax.swing.JFrame {
// Parametros
int n;
byte matrizPuzzleInicial[][], matrizPuzzleFinal[][];
List listaAcciones;
/**
* Creates new form Puzzle_JF
*/
public Puzzle_JF() {
initComponents();
this.setLocationRelativeTo(null);
n=3;
matrizPuzzleInicial = new byte[n][n];
matrizPuzzleFinal = new byte[n][n];
listaAcciones = new ArrayList<String>();
listaAcciones.add("DER");
listaAcciones.add("IZQ");
listaAcciones.add("ARRIB");
listaAcciones.add("ABAJ");
// problem = new Problem();
// problem.Set(createBoard(n), listaAcciones, createBoard(n));
//
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
pnlContainer = new java.awt.Panel();
pnlTitle = new java.awt.Panel();
lblTitle = new java.awt.Label();
btnSalir = new org.edisoncor.gui.button.ButtonTextDown();
lblMetodoSolucion = new java.awt.Label();
lblSolucion = new java.awt.Label();
cbxMetodoSolucion = new javax.swing.JComboBox<>();
lblPuzzleFinal = new java.awt.Label();
pnlPuzzleFinal = new org.edisoncor.gui.panel.PanelNice();
btnPF23 = new javax.swing.JButton();
btnPF12 = new javax.swing.JButton();
btnPF11 = new javax.swing.JButton();
btnPF13 = new javax.swing.JButton();
btnPF32 = new javax.swing.JButton();
btnPF31 = new javax.swing.JButton();
btnPF22 = new javax.swing.JButton();
btnPF21 = new javax.swing.JButton();
btnPF33 = new javax.swing.JButton();
pnlPuzzleInicial = new org.edisoncor.gui.panel.PanelNice();
btnPI23 = new javax.swing.JButton();
btnPI12 = new javax.swing.JButton();
btnPI11 = new javax.swing.JButton();
btnPI13 = new javax.swing.JButton();
btnPI32 = new javax.swing.JButton();
btnPI31 = new javax.swing.JButton();
btnPI22 = new javax.swing.JButton();
btnPI21 = new javax.swing.JButton();
btnPI33 = new javax.swing.JButton();
lblPuzzleInicial = new java.awt.Label();
lblInformacion = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
txaInformacion = new javax.swing.JTextArea();
jScrollPane1 = new javax.swing.JScrollPane();
txaSolucion = new javax.swing.JTextArea();
jLabel2 = new javax.swing.JLabel();
jComboBox2 = new javax.swing.JComboBox<>();
btnCargaPuzzle = new org.edisoncor.gui.button.ButtonTextDown();
btnLimpiar = new org.edisoncor.gui.button.ButtonTextDown();
BtnResolver = new org.edisoncor.gui.button.ButtonTextDown();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setUndecorated(true);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
pnlContainer.setBackground(new java.awt.Color(215, 228, 233));
pnlContainer.setName("pnlFondo"); // NOI18N
pnlTitle.setBackground(new java.awt.Color(57, 83, 108));
lblTitle.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
lblTitle.setFont(new java.awt.Font("Yu Gothic UI Semilight", 1, 18)); // NOI18N
lblTitle.setForeground(new java.awt.Color(222, 230, 234));
lblTitle.setText("Puzzle IA");
btnSalir.setBackground(new java.awt.Color(57, 36, 68));
btnSalir.setForeground(new java.awt.Color(222, 230, 234));
btnSalir.setText("Salir");
btnSalir.setFont(new java.awt.Font("Yu Gothic UI Semilight", 1, 14)); // NOI18N
btnSalir.setName("btnSalir"); // NOI18N
btnSalir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSalirActionPerformed(evt);
}
});
javax.swing.GroupLayout pnlTitleLayout = new javax.swing.GroupLayout(pnlTitle);
pnlTitle.setLayout(pnlTitleLayout);
pnlTitleLayout.setHorizontalGroup(
pnlTitleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlTitleLayout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(lblTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pnlTitleLayout.setVerticalGroup(
pnlTitleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlTitleLayout.createSequentialGroup()
.addContainerGap()
.addGroup(pnlTitleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblTitle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(pnlTitleLayout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
lblMetodoSolucion.setFont(new java.awt.Font("Yu Gothic UI Semilight", 0, 14)); // NOI18N
lblMetodoSolucion.setForeground(new java.awt.Color(93, 69, 66));
lblMetodoSolucion.setName("lblMetodoSolucion"); // NOI18N
lblMetodoSolucion.setText("Metodo de Solución");
lblSolucion.setFont(new java.awt.Font("Yu Gothic UI Semilight", 0, 14)); // NOI18N
lblSolucion.setForeground(new java.awt.Color(93, 69, 66));
lblSolucion.setName("lblSolucion"); // NOI18N
lblSolucion.setText("Solución");
cbxMetodoSolucion.setFont(new java.awt.Font("Yu Gothic UI Semilight", 1, 12)); // NOI18N
cbxMetodoSolucion.setForeground(new java.awt.Color(20, 32, 39));
cbxMetodoSolucion.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Seleccionar...", "Amplitud", "Profundidad", "Profundidad Limitada", "Profundidad Iterativa", "Voraz", "A*" }));
cbxMetodoSolucion.setName("cbxMetodoSolucion"); // NOI18N
lblPuzzleFinal.setFont(new java.awt.Font("Yu Gothic UI Semilight", 0, 14)); // NOI18N
lblPuzzleFinal.setForeground(new java.awt.Color(93, 69, 66));
lblPuzzleFinal.setName("lblPuzzleFinal:"); // NOI18N
lblPuzzleFinal.setText("Puzzle Final");
pnlPuzzleFinal.setForeground(new java.awt.Color(255, 255, 255));
pnlPuzzleFinal.setName("pnlPuzzleFinal"); // NOI18N
btnPF23.setText("?");
btnPF23.setName("btnpf6"); // NOI18N
btnPF23.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPF23ActionPerformed(evt);
}
});
btnPF12.setText("?");
btnPF12.setName("btnpf2"); // NOI18N
btnPF12.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPF12ActionPerformed(evt);
}
});
btnPF11.setText("?");
btnPF11.setName("btnpf1"); // NOI18N
btnPF11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPF11ActionPerformed(evt);
}
});
btnPF13.setText("?");
btnPF13.setName("btnpf3"); // NOI18N
btnPF13.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPF13ActionPerformed(evt);
}
});
btnPF32.setText("?");
btnPF32.setName("btnpf8"); // NOI18N
btnPF32.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPF32ActionPerformed(evt);
}
});
btnPF31.setText("?");
btnPF31.setName("btnpf7"); // NOI18N
btnPF31.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPF31ActionPerformed(evt);
}
});
btnPF22.setText("?");
btnPF22.setName("btnpf5"); // NOI18N
btnPF22.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPF22ActionPerformed(evt);
}
});
btnPF21.setText("?");
btnPF21.setName("btnpf4"); // NOI18N
btnPF21.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPF21ActionPerformed(evt);
}
});
btnPF33.setText("?");
btnPF33.setName("btnpf9"); // NOI18N
btnPF33.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPF33ActionPerformed(evt);
}
});
javax.swing.GroupLayout pnlPuzzleFinalLayout = new javax.swing.GroupLayout(pnlPuzzleFinal);
pnlPuzzleFinal.setLayout(pnlPuzzleFinalLayout);
pnlPuzzleFinalLayout.setHorizontalGroup(
pnlPuzzleFinalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlPuzzleFinalLayout.createSequentialGroup()
.addContainerGap()
.addGroup(pnlPuzzleFinalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlPuzzleFinalLayout.createSequentialGroup()
.addComponent(btnPF11, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPF12, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPF13, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(pnlPuzzleFinalLayout.createSequentialGroup()
.addComponent(btnPF21, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPF22, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPF23, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(pnlPuzzleFinalLayout.createSequentialGroup()
.addComponent(btnPF31, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPF32, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPF33, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pnlPuzzleFinalLayout.setVerticalGroup(
pnlPuzzleFinalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlPuzzleFinalLayout.createSequentialGroup()
.addContainerGap()
.addGroup(pnlPuzzleFinalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnPF11)
.addComponent(btnPF13)
.addComponent(btnPF12))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlPuzzleFinalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnPF21)
.addComponent(btnPF22)
.addComponent(btnPF23))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlPuzzleFinalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnPF31)
.addComponent(btnPF32)
.addComponent(btnPF33))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
btnPF11.getAccessibleContext().setAccessibleName("btnpi1");
pnlPuzzleInicial.setForeground(new java.awt.Color(255, 255, 255));
pnlPuzzleInicial.setName("pnlPuzzleInicial"); // NOI18N
btnPI23.setText("?");
btnPI23.setName("btnpi6"); // NOI18N
btnPI23.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPI23ActionPerformed(evt);
}
});
btnPI12.setText("?");
btnPI12.setName("btnpi2"); // NOI18N
btnPI12.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPI12ActionPerformed(evt);
}
});
btnPI11.setText("?");
btnPI11.setName("btnpi1"); // NOI18N
btnPI11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPI11ActionPerformed(evt);
}
});
btnPI13.setText("?");
btnPI13.setName("btnpi3"); // NOI18N
btnPI13.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPI13ActionPerformed(evt);
}
});
btnPI32.setText("?");
btnPI32.setName("btnpi8"); // NOI18N
btnPI32.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPI32ActionPerformed(evt);
}
});
btnPI31.setText("?");
btnPI31.setName("btnpi7"); // NOI18N
btnPI31.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPI31ActionPerformed(evt);
}
});
btnPI22.setText("?");
btnPI22.setName("btnpi5"); // NOI18N
btnPI22.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPI22ActionPerformed(evt);
}
});
btnPI21.setText("?");
btnPI21.setName("btnpi4"); // NOI18N
btnPI21.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPI21ActionPerformed(evt);
}
});
btnPI33.setText("?");
btnPI33.setName("btnpi9"); // NOI18N
btnPI33.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPI33ActionPerformed(evt);
}
});
javax.swing.GroupLayout pnlPuzzleInicialLayout = new javax.swing.GroupLayout(pnlPuzzleInicial);
pnlPuzzleInicial.setLayout(pnlPuzzleInicialLayout);
pnlPuzzleInicialLayout.setHorizontalGroup(
pnlPuzzleInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlPuzzleInicialLayout.createSequentialGroup()
.addContainerGap()
.addGroup(pnlPuzzleInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlPuzzleInicialLayout.createSequentialGroup()
.addComponent(btnPI11, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPI12, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPI13, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(pnlPuzzleInicialLayout.createSequentialGroup()
.addComponent(btnPI21, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPI22, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPI23, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(pnlPuzzleInicialLayout.createSequentialGroup()
.addComponent(btnPI31, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPI32, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPI33, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pnlPuzzleInicialLayout.setVerticalGroup(
pnlPuzzleInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlPuzzleInicialLayout.createSequentialGroup()
.addContainerGap()
.addGroup(pnlPuzzleInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnPI11)
.addComponent(btnPI13)
.addComponent(btnPI12))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlPuzzleInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnPI21)
.addComponent(btnPI22)
.addComponent(btnPI23))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlPuzzleInicialLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnPI31)
.addComponent(btnPI32)
.addComponent(btnPI33))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
lblPuzzleInicial.setFont(new java.awt.Font("Yu Gothic UI Semilight", 0, 14)); // NOI18N
lblPuzzleInicial.setForeground(new java.awt.Color(93, 69, 66));
lblPuzzleInicial.setName("lblPuzzleInicial"); // NOI18N
lblPuzzleInicial.setText("Puzzle Inicial:");
lblInformacion.setFont(new java.awt.Font("Yu Gothic UI Semilight", 0, 14)); // NOI18N
lblInformacion.setForeground(new java.awt.Color(20, 32, 39));
lblInformacion.setText("Estadisticas");
lblInformacion.setName("lblEstadistica"); // NOI18N
txaInformacion.setColumns(20);
txaInformacion.setRows(5);
jScrollPane2.setViewportView(txaInformacion);
txaSolucion.setColumns(20);
txaSolucion.setRows(5);
jScrollPane1.setViewportView(txaSolucion);
jLabel2.setFont(new java.awt.Font("Yu Gothic UI Semilight", 0, 14)); // NOI18N
jLabel2.setForeground(new java.awt.Color(20, 32, 39));
jLabel2.setText("Tipo Puzzle :");
jLabel2.setName("lblTipoPuzzle"); // NOI18N
jComboBox2.setFont(new java.awt.Font("Yu Gothic UI Semilight", 1, 12)); // NOI18N
jComboBox2.setForeground(new java.awt.Color(20, 32, 39));
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Seleccionar...", "Puzzle 4", "Puzzle 8", "Puzzle 16", " " }));
jComboBox2.setName("cbxTipoPuzzle"); // NOI18N
btnCargaPuzzle.setBackground(new java.awt.Color(83, 86, 96));
btnCargaPuzzle.setForeground(new java.awt.Color(222, 230, 234));
btnCargaPuzzle.setText("Change");
btnCargaPuzzle.setFont(new java.awt.Font("Yu Gothic UI Semilight", 1, 14)); // NOI18N
btnCargaPuzzle.setName("btnChange"); // NOI18N
btnLimpiar.setBackground(new java.awt.Color(83, 86, 96));
btnLimpiar.setForeground(new java.awt.Color(222, 230, 234));
btnLimpiar.setText("Limpiar");
btnLimpiar.setFont(new java.awt.Font("Yu Gothic UI Semilight", 1, 14)); // NOI18N
btnLimpiar.setName("btnLimpiar"); // NOI18N
btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnLimpiarActionPerformed(evt);
}
});
BtnResolver.setBackground(new java.awt.Color(83, 86, 96));
BtnResolver.setForeground(new java.awt.Color(222, 230, 234));
BtnResolver.setFont(new java.awt.Font("Yu Gothic UI Semilight", 1, 14)); // NOI18N
BtnResolver.setLabel("Resolver");
BtnResolver.setName("btnResolver"); // NOI18N
BtnResolver.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnResolverActionPerformed(evt);
}
});
javax.swing.GroupLayout pnlContainerLayout = new javax.swing.GroupLayout(pnlContainer);
pnlContainer.setLayout(pnlContainerLayout);
pnlContainerLayout.setHorizontalGroup(
pnlContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(pnlTitle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(pnlContainerLayout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(pnlContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlContainerLayout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 330, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(pnlContainerLayout.createSequentialGroup()
.addGroup(pnlContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblSolucion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(pnlContainerLayout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(26, 26, 26)
.addComponent(btnCargaPuzzle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(pnlContainerLayout.createSequentialGroup()
.addGroup(pnlContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblPuzzleInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(pnlPuzzleInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(11, 11, 11)
.addGroup(pnlContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlContainerLayout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(lblPuzzleFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(pnlPuzzleFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(18, 18, 18)
.addGroup(pnlContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(cbxMetodoSolucion, 0, 182, Short.MAX_VALUE)
.addComponent(lblMetodoSolucion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnLimpiar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lblInformacion)
.addComponent(BtnResolver, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addGap(0, 21, Short.MAX_VALUE))
);
pnlContainerLayout.setVerticalGroup(
pnlContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlContainerLayout.createSequentialGroup()
.addComponent(pnlTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlContainerLayout.createSequentialGroup()
.addGroup(pnlContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlContainerLayout.createSequentialGroup()
.addGroup(pnlContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(16, 16, 16))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlContainerLayout.createSequentialGroup()
.addComponent(btnCargaPuzzle, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)))
.addGroup(pnlContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblPuzzleFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblPuzzleInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(2, 2, 2)
.addGroup(pnlContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(pnlPuzzleFinal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlPuzzleInicial, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(pnlContainerLayout.createSequentialGroup()
.addComponent(lblMetodoSolucion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbxMetodoSolucion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(BtnResolver, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(pnlContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblSolucion, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblInformacion))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 354, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(17, Short.MAX_VALUE))
);
lblMetodoSolucion.getAccessibleContext().setAccessibleName("lblMetodoSolucion");
lblSolucion.getAccessibleContext().setAccessibleName("lblPuzzleInicial");
getContentPane().add(pnlContainer, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 590, 650));
pack();
}// </editor-fold>
private void btnPI11ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButon(btnPI11, 0,0);
}
private void btnPI12ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButon(btnPI12,0, 1);
}
private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
private void BtnResolverActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(cbxMetodoSolucion.getSelectedItem() == "Amplitud"){
}
else if (cbxMetodoSolucion.getSelectedItem() == "Profundidad") {
}
else if (cbxMetodoSolucion.getSelectedItem() == "Profundidad Limitada") {
}
else if (cbxMetodoSolucion.getSelectedItem() == "Profundidad Iterativa"){
}
else if (cbxMetodoSolucion.getSelectedItem() == "Voraz"){
}
else if (cbxMetodoSolucion.getSelectedItem() == "A*"){
}
else if (cbxMetodoSolucion.getSelectedItem() == "Seleccionar..."){
JOptionPane.showMessageDialog(this, "Debe seleccionar un Metodo de solución", "Metodos de solución", JOptionPane.INFORMATION_MESSAGE);
}
}
private void btnPI13ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButon(btnPI13, 0, 2);
}
private void btnPI21ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButon(btnPI21, 1, 0);
}
private void btnPI22ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButon(btnPI22, 1, 1);
}
private void btnPI23ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButon(btnPI23, 1, 2);
}
private void btnPI31ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButon(btnPI31, 2, 0);
}
private void btnPI32ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButon(btnPI32, 2, 1);
}
private void btnPI33ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButon(btnPI33, 2, 2);
}
private void btnPF11ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButonPF(btnPF11,0, 0);
}
Integer fi = 0, co = 0;
private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// String pI = "", pF = "";
// txaSolucion.append("pI pF\n");
// for (int i = 0; i < matrizPuzzleInicial.length; i++) {
// for (int j = 0; j < matrizPuzzleInicial.length; j++) {
//
// pI = pI + matrizPuzzleInicial[i][j].toString() + " ";
// pF = pF + matrizPuzzleFinal[i][j].toString() + " ";
//
// if(matrizPuzzleInicial[i][j] == 0){
// fi = i;
// co = j;
// }
// }
// txaSolucion.append(pI + " " + pF);
// txaSolucion.append("\n");
// pI = "";
// pF = "";
// }
//
// Integer val;
// if (movDer()){
//
// val = matrizPuzzleInicial[fi][co+1];
// matrizPuzzleInicial[fi][co+1] = 0;
//
// matrizPuzzleInicial[fi][co] = val;
//
// co++;
// }
//
// txaSolucion.append("pI pF\n");
// for (int i = 0; i < matrizPuzzleInicial.length; i++) {
// for (int j = 0; j < matrizPuzzleInicial.length; j++) {
//
// pI = pI + matrizPuzzleInicial[i][j].toString() + " ";
// pF = pF + matrizPuzzleFinal[i][j].toString() + " ";
//
// if(matrizPuzzleInicial[i][j] == 0){
// fi = i;
// co = j;
// }
// }
// txaSolucion.append(pI + " " + pF);
// txaSolucion.append("\n");
// pI = "";
// pF = "";
// }
}
public boolean movDer (){
return co < 2;
}
public boolean movIzq (){
return co > 0;
}
public boolean movArri (){
return fi > 0;
}
public boolean movAbaj (){
return fi < 2;
}
private void btnPF12ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButonPF(btnPF12,0,1);
}
private void btnPF13ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButonPF(btnPF13, 0, 2);
}
private void btnPF21ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButonPF(btnPF21,1, 0);
}
private void btnPF22ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButonPF(btnPF22, 1, 1);
}
private void btnPF23ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButonPF(btnPF23, 1, 2);
}
private void btnPF31ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButonPF(btnPF31, 2, 0);
}
private void btnPF32ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButonPF(btnPF32, 2, 1);
}
private void btnPF33ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.guardarActualizarNumeroButonPF(btnPF33, 2, 2);
}
/**
* @param args the command line arguments
*/
//Metodo Main
public static void main(String[] args) {
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Puzzle_JF().setVisible(true);
}
});
}
private void guardarActualizarNumeroButon(JButton selectBoton, Integer positionFila,Integer PositionColumn){
String valorObtenido = JOptionPane.showInputDialog(this, "ingrese el valor");
if(valorObtenido != null){
byte valorInteger = Byte.parseByte(valorObtenido);
matrizPuzzleInicial[positionFila][PositionColumn] = valorInteger;
selectBoton.setText(valorObtenido);
//JOptionPane.showMessageDialog(this, "el numero guardado es: "+ matrizPuzzleInicial[positionFila][PositionColumn].toString(),"Numero Asignado", JOptionPane.INFORMATION_MESSAGE);
}
}
private void guardarActualizarNumeroButonPF(JButton selectBoton, Integer positionFila,Integer PositionColumn){
String valorObtenido = JOptionPane.showInputDialog(this, "ingrese el numero aquí","Valor de la cuadricula ",JOptionPane.PLAIN_MESSAGE);
if(valorObtenido != null){
byte valorInteger;
valorInteger = Byte.parseByte(valorObtenido);
matrizPuzzleFinal[positionFila][PositionColumn] = valorInteger;
selectBoton.setText(valorObtenido);
//JOptionPane.showMessageDialog(this, "el numero guardado es: "+ matrizPuzzleInicial[positionFila][PositionColumn].toString(),"Numero Asignado", JOptionPane.INFORMATION_MESSAGE);
}
}
// Variables declaration - do not modify
private org.edisoncor.gui.button.ButtonTextDown BtnResolver;
private org.edisoncor.gui.button.ButtonTextDown btnCargaPuzzle;
private org.edisoncor.gui.button.ButtonTextDown btnLimpiar;
private javax.swing.JButton btnPF11;
private javax.swing.JButton btnPF12;
private javax.swing.JButton btnPF13;
private javax.swing.JButton btnPF21;
private javax.swing.JButton btnPF22;
private javax.swing.JButton btnPF23;
private javax.swing.JButton btnPF31;
private javax.swing.JButton btnPF32;
private javax.swing.JButton btnPF33;
private javax.swing.JButton btnPI11;
private javax.swing.JButton btnPI12;
private javax.swing.JButton btnPI13;
private javax.swing.JButton btnPI21;
private javax.swing.JButton btnPI22;
private javax.swing.JButton btnPI23;
private javax.swing.JButton btnPI31;
private javax.swing.JButton btnPI32;
private javax.swing.JButton btnPI33;
private org.edisoncor.gui.button.ButtonTextDown btnSalir;
private javax.swing.JComboBox<String> cbxMetodoSolucion;
private javax.swing.JComboBox<String> jComboBox2;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JLabel lblInformacion;
private java.awt.Label lblMetodoSolucion;
private java.awt.Label lblPuzzleFinal;
private java.awt.Label lblPuzzleInicial;
private java.awt.Label lblSolucion;
private java.awt.Label lblTitle;
private java.awt.Panel pnlContainer;
private org.edisoncor.gui.panel.PanelNice pnlPuzzleFinal;
private org.edisoncor.gui.panel.PanelNice pnlPuzzleInicial;
private java.awt.Panel pnlTitle;
private javax.swing.JTextArea txaInformacion;
private javax.swing.JTextArea txaSolucion;
// End of variables declaration
}