diff --git a/src/main/java/net/berack/upo/ai/decision/PrototypeGUI.java b/src/main/java/net/berack/upo/ai/decision/PrototypeGUI.java index 607eb0a..1bf2281 100644 --- a/src/main/java/net/berack/upo/ai/decision/PrototypeGUI.java +++ b/src/main/java/net/berack/upo/ai/decision/PrototypeGUI.java @@ -2,6 +2,7 @@ package net.berack.upo.ai.decision; import javax.swing.JMenu; import javax.swing.JMenuItem; +import javax.swing.JOptionPane; import net.berack.upo.ai.gui.MyDecisionPanel; import net.berack.upo.ai.problem3.SmileLib; @@ -30,6 +31,13 @@ public class PrototypeGUI extends MyDecisionPanel { var item = new JMenuItem("Reset"); item.addActionListener(a -> { this.net.clearAllEvidence(); this.updateAll(); }); menu.add(item); + item = new JMenuItem("Help"); + item.addActionListener(a -> JOptionPane.showMessageDialog(this, + "Click on the decision and see the changes in the net\n" + + "The BOLD marked outcomes are the best decision calculated by the model\n" + + "At the end it will be displayed the expected utility of all the decisions." + )); + menu.add(item); return menu; } } diff --git a/src/main/java/net/berack/upo/ai/decision/VehicleGUI.java b/src/main/java/net/berack/upo/ai/decision/VehicleGUI.java index 138a4f7..47649aa 100644 --- a/src/main/java/net/berack/upo/ai/decision/VehicleGUI.java +++ b/src/main/java/net/berack/upo/ai/decision/VehicleGUI.java @@ -1,6 +1,8 @@ package net.berack.upo.ai.decision; import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; import net.berack.upo.ai.gui.MyDecisionPanel; import net.berack.upo.ai.problem3.SmileLib; @@ -28,7 +30,20 @@ public class VehicleGUI extends MyDecisionPanel { @Override public JMenu getMenu() { - return null; + var menu = new JMenu("Network"); + var item = new JMenuItem("Reset"); + item.addActionListener(a -> { this.net.clearAllEvidence(); this.updateAll(); }); + menu.add(item); + item = new JMenuItem("Help"); + item.addActionListener(a -> JOptionPane.showMessageDialog(this, + "Click on the decision and see the changes in the net\n" + + "The BOLD marked outcomes are the best decision calculated by the model\n" + + "At the end it will be displayed the expected utility of all the decisions.\n\n" + + "NOTE: this model is hard to compute, so after making a decision\n" + + "it might freeze the window while it's calculating the results" + )); + menu.add(item); + return menu; } } diff --git a/src/main/java/net/berack/upo/ai/gui/MainGUI.java b/src/main/java/net/berack/upo/ai/gui/MainGUI.java index 545e149..6c452cd 100644 --- a/src/main/java/net/berack/upo/ai/gui/MainGUI.java +++ b/src/main/java/net/berack/upo/ai/gui/MainGUI.java @@ -2,9 +2,11 @@ package net.berack.upo.ai.gui; import java.awt.BorderLayout; import java.awt.Dimension; +import java.awt.GridBagLayout; import javax.swing.BorderFactory; import javax.swing.JFrame; +import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; @@ -47,6 +49,11 @@ public class MainGUI extends JFrame { this.buildMenu(); this.setJMenuBar(menuBar); + var label = new JLabel("Use the menù 'view' to choose what to do"); + var panel = new JPanel(new GridBagLayout()); + panel.add(label); + this.setContentPane(panel); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(this.size); this.setResizable(false); diff --git a/src/main/java/net/berack/upo/ai/problem1/Puzzle8GUI.java b/src/main/java/net/berack/upo/ai/problem1/Puzzle8GUI.java index c1d81cd..6d3da93 100644 --- a/src/main/java/net/berack/upo/ai/problem1/Puzzle8GUI.java +++ b/src/main/java/net/berack/upo/ai/problem1/Puzzle8GUI.java @@ -9,6 +9,8 @@ import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JMenu; import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JSeparator; import net.berack.upo.ai.gui.MyPanel; import net.berack.upo.ai.problem1.Puzzle8.Move; @@ -165,13 +167,24 @@ public class Puzzle8GUI extends MyPanel { @Override public JMenu getMenu() { var menu = new JMenu("Game"); - var item1 = new JMenuItem("Shuffle"); - item1.addActionListener(action -> this.shuffleGame()); - menu.add(item1); + var item = new JMenuItem("Shuffle"); + item.addActionListener(action -> this.shuffleGame()); + menu.add(item); - var item2 = new JMenuItem("Show solution"); - item2.addActionListener(action -> this.solveGame()); - menu.add(item2); + item = new JMenuItem("Show solution"); + item.addActionListener(action -> this.solveGame()); + menu.add(item); + + menu.add(new JSeparator()); + + item = new JMenuItem("Help"); + item.addActionListener(a -> JOptionPane.showMessageDialog(this, + "This is a recreation of the game of the 8 tiles\n" + + "To win the game you must sort the tiles in ascending order\n" + + "with the empty tile at the end.\n" + + "The empty space is used to move all the other tiles." + )); + menu.add(item); return menu; } diff --git a/src/main/java/net/berack/upo/ai/problem2/TrisGUI.java b/src/main/java/net/berack/upo/ai/problem2/TrisGUI.java index e80bf7d..c255cfa 100644 --- a/src/main/java/net/berack/upo/ai/problem2/TrisGUI.java +++ b/src/main/java/net/berack/upo/ai/problem2/TrisGUI.java @@ -9,6 +9,7 @@ import javax.swing.JButton; import javax.swing.JCheckBoxMenuItem; import javax.swing.JMenu; import javax.swing.JMenuItem; +import javax.swing.JOptionPane; import javax.swing.JSeparator; import net.berack.upo.ai.gui.MyPanel; @@ -138,12 +139,11 @@ public class TrisGUI extends MyPanel { @Override public JMenu getMenu() { var menu = new JMenu("Game"); - var item1 = new JMenuItem("Reset"); - item1.addActionListener(action -> this.reset()); - menu.add(item1); + var item = new JMenuItem("Reset"); + item.addActionListener(action -> this.reset()); + menu.add(item); - var separator = new JSeparator(); - menu.add(separator); + menu.add(new JSeparator()); var item2 = new JCheckBoxMenuItem("AI Enabled"); item2.setSelected(this.ai != null); @@ -154,6 +154,19 @@ public class TrisGUI extends MyPanel { this.aiFirst.setSelected(false); menu.add(this.aiFirst); + menu.add(new JSeparator()); + + item = new JMenuItem("Help"); + item.addActionListener(a -> JOptionPane.showMessageDialog(this, + "This is a recreation of the game of Tris\n" + + "If you start first you will have the X symbol, otherwise you will have the O symbol.\n" + + "To win the game you must make 3 consecutive symbols. (horizontally/vertically/diagonally)\n" + + "You will have an opponent, AI based or human (you can choose it in the menù),\n" + + "that have the same objective as you have, but of opposite symbol.\n" + + "When someone wins the game is stopped and the tris is highlighted in red" + )); + menu.add(item); + return menu; } } diff --git a/src/main/java/net/berack/upo/ai/problem3/LikelihoodWeightingGUI.java b/src/main/java/net/berack/upo/ai/problem3/LikelihoodWeightingGUI.java index b91b10f..b967e36 100644 --- a/src/main/java/net/berack/upo/ai/problem3/LikelihoodWeightingGUI.java +++ b/src/main/java/net/berack/upo/ai/problem3/LikelihoodWeightingGUI.java @@ -2,12 +2,14 @@ package net.berack.upo.ai.problem3; import java.awt.Component; import java.awt.FileDialog; +import java.awt.GridBagLayout; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuItem; +import javax.swing.JOptionPane; import javax.swing.JSeparator; import net.berack.upo.ai.gui.MyDecisionPanel; @@ -33,6 +35,10 @@ public class LikelihoodWeightingGUI extends MyDecisionPanel { this.setFont(totLabel); this.setExtraComponents(new Component[] { totLabel, totValue }); this.buildPanel(null); + + var label = new JLabel("Use the menù 'File' to open a net"); + this.setLayout(new GridBagLayout()); + this.add(label); } /** @@ -98,20 +104,28 @@ public class LikelihoodWeightingGUI extends MyDecisionPanel { var open = new JMenuItem("Open"); open.addActionListener(action -> this.openFile()); + menu.add(open); + menu.add(new JSeparator()); var nets = new JMenuItem[3]; nets[0] = new JMenuItem("Alarm net"); nets[0].addActionListener(action -> this.openFile("lw/Alarm.xdsl")); - nets[1] = new JMenuItem("WetGrass net"); nets[1].addActionListener(action -> this.openFile("lw/WetGrass.xdsl")); - nets[2] = new JMenuItem("Malaria net"); nets[2].addActionListener(action -> this.openFile("lw/Malaria.xdsl")); - menu.add(open); - menu.add(new JSeparator()); for(var net : nets) menu.add(net); + menu.add(new JSeparator()); + + var item = new JMenuItem("Help"); + item.addActionListener(a -> JOptionPane.showMessageDialog(this, + "Here you can see the likleihood weighting algoritm.\n" + + "To do it you have to load a net from the samples provided,\n" + + "or you can open a custom net.\n\n" + + "NOTE: this algorithm do not support decision nodes yet" + )); + menu.add(item); return menu; }