From: <an...@us...> - 2009-01-21 17:10:02
|
Revision: 7283 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=7283&view=rev Author: anfarr Date: 2009-01-21 17:09:59 +0000 (Wed, 21 Jan 2009) Log Message: ----------- SFOS-1025: Sudoku app as part of constraint enhancement Added Paths: ----------- trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/ trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/BaseSudokuApplication.java trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/BaseSudokuFrontEnd.java trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/HP_ICON.PNG trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplet.java trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplication.java trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplicationClient.java trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplicationServer.java trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplicationServlet.java trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuResource.java trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/TestClient.java trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/hpback.GIF trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/hpback.PNG trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/sflabsng.PNG trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/sudoko9.sf Added: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/BaseSudokuApplication.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/BaseSudokuApplication.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/BaseSudokuApplication.java 2009-01-21 17:09:59 UTC (rev 7283) @@ -0,0 +1,83 @@ +package org.smartfrog.examples.sudoku; + +import java.awt.Image; +import java.net.URL; +import java.util.Properties; +import java.util.Vector; + +import javax.swing.ImageIcon; +import javax.swing.JFrame; + +import org.smartfrog.examples.sudoku.BaseSudokuFrontEnd; +import org.smartfrog.examples.sudoku.BaseSudokuFrontEnd.ProcessSquares; + +abstract public class BaseSudokuApplication extends JFrame implements ProcessSquares { + static String HPICON_PATH = "/org/smartfrog/examples/sudoku/HP_ICON.PNG"; + static String sudoko9 = "/org/smartfrog/examples/sudoku/sudoko9.sf"; + static String SOLVERCLASS_KEY = "org.smartfrog.sfcore.languages.sf.constraints.SolverClassName"; + static String SOLVERCLASS_VAL = "org.smartfrog.sfcore.languages.sf.constraints.eclipse.EclipseSolver"; + static String CDBROWSER_KEY = "org.smartfrog.sfcore.languages.sf.constraints.CDBrowser"; + static String CDBROWSER_VAL = "org.smartfrog.sfcore.languages.sf.constraints.eclipse.EclipseCDBrowser"; + static String THEORYFILE_KEY = "org.smartfrog.sfcore.languages.sf.constraints.theoryFile0"; + static String THEORYFILE_VAL = "core.ecl"; + static String ECLIPSEDIR_KEY = "org.smartfrog.sfcore.languages.sf.constraints.eclipseDir"; + static String ECLIPSEDIR_VAL = "/usr/share/eclipse-clp"; + + BaseSudokuFrontEnd bsfe; { bsfe= new BaseSudokuFrontEnd(this); } + + protected static void properties(){ + Properties sysProps = System.getProperties(); + sysProps.put(ECLIPSEDIR_KEY, ECLIPSEDIR_VAL); + sysProps.put(THEORYFILE_KEY, THEORYFILE_VAL); + sysProps.put(SOLVERCLASS_KEY, SOLVERCLASS_VAL); + sysProps.put(CDBROWSER_KEY, CDBROWSER_VAL); + } + + public static class Location{ + Vector loc = new Vector(); + void put(int r, int c){ + loc.add(new Integer(r)); + loc.add(new Integer(c)); + } + } + + public abstract void process(); + + public static Location convertLocation(int idx){ + Location loc = new Location(); + + int r = idx/27; + int rem = idx - 27*r; + int sq = rem/9; + int remsq = rem - 9*sq; + int y = remsq/3; + int x = remsq - 3*y; + + loc.put(sq*3 + x, r*3 + y); + return loc; + } + + public static int convertLocationToIndex(int row, int col){ + int x = row/3; + int y = col/3; + + int xoff = row- (3*x); + int yoff = col- (3*y); + + int sq = ((y*3 + x)*9) + 3*yoff + xoff; + + return sq; + } + + void app_init(){ + setContentPane(bsfe.init()); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setTitle("Su Doko Solver, powered by SmartFrog"); + URL url = getClass().getResource(HPICON_PATH); + Image image = new ImageIcon(url).getImage(); + setIconImage(image); + pack(); + setVisible(true); + } + +} Property changes on: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/BaseSudokuApplication.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/BaseSudokuFrontEnd.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/BaseSudokuFrontEnd.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/BaseSudokuFrontEnd.java 2009-01-21 17:09:59 UTC (rev 7283) @@ -0,0 +1,224 @@ +package org.smartfrog.examples.sudoku; + +import java.awt.Color; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.GridLayout; +import java.awt.Image; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.net.URL; +import java.util.Properties; +import java.util.Vector; + +import javax.swing.Box; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import org.smartfrog.SFParse; +import org.smartfrog.SFParse.RawParseModifier; +import org.smartfrog.sfcore.common.Context; +import org.smartfrog.sfcore.componentdescription.ComponentDescription; +import org.smartfrog.sfcore.languages.sf.constraints.CoreSolver; + +public class BaseSudokuFrontEnd { + + static String AILLOGO_PATH = "/org/smartfrog/examples/sudoku/sflabsng.PNG"; + static String HPBACK = "/org/smartfrog/examples/sudoku/hpback.PNG"; + + Vector<JTextField> board; + JLabel unsolvable = new JLabel(); + Container pane; + ProcessSquares ps; + + public BaseSudokuFrontEnd(ProcessSquares ps){ + this.ps=ps; + } + + public Container init(){ + pane = new JImagePanel(); + + JPanel centre = new JPanel(); + centre.setOpaque(false); + centre.setSize(300,200); + pane.add(centre); + + Box vbox = Box.createVerticalBox(); + centre.add(vbox); + + Box sbox = Box.createHorizontalBox(); + vbox.add(sbox); + sbox.add(Box.createHorizontalGlue()); + + JLabel sudoko = new JLabel("Su Doku"); + sbox.add(sudoko); + sudoko.setFont(new Font("Helvetica", Font.BOLD, 24)); + sudoko.setForeground(Color.WHITE); + sbox.add(Box.createHorizontalGlue()); + + vbox.add(Box.createVerticalStrut(10)); + + Box ebox = Box.createHorizontalBox(); + vbox.add(ebox); + ebox.add(Box.createHorizontalGlue()); + + JLabel enter = new JLabel("Enter values where pre-defined"); + enter.setFont(new Font("Helvetica", Font.PLAIN, 12)); + enter.setForeground(Color.WHITE); + ebox.add(enter); + + vbox.add(Box.createVerticalStrut(5)); + + board = new Vector<JTextField>(); + + for (int i=0; i<3; i++){ + Box row = Box.createHorizontalBox(); + for (int j=0; j<3; j++){ + + JPanel entergrid = new JPanel(); + entergrid.setOpaque(false); + entergrid.setLayout(new GridLayout(3,3)); + + for (int k=0;k<9;k++){ + JTextField field = new JTextField(1); + board.add(field); + entergrid.add(field); + } + row.add(entergrid); + row.add(Box.createHorizontalStrut(5)); + } + + vbox.add(row); + vbox.add(Box.createVerticalStrut(5)); + } + vbox.add(Box.createVerticalStrut(10)); + + //Prespecifieds... + board.get(3).setText("1"); + board.get(5).setText("6"); + + board.get(10).setText("8"); + board.get(17).setText("6"); + + board.get(18).setText("5"); + board.get(24).setText("2"); + board.get(25).setText("7"); + board.get(26).setText("9"); + + board.get(31).setText("2"); + board.get(33).setText("8"); + board.get(34).setText("5"); + + board.get(39).setText("4"); + board.get(41).setText("9"); + + board.get(46).setText("6"); + board.get(47).setText("1"); + board.get(49).setText("8"); + + board.get(54).setText("9"); + board.get(55).setText("1"); + board.get(56).setText("2"); + board.get(62).setText("8"); + + board.get(63).setText("5"); + board.get(70).setText("4"); + + board.get(75).setText("7"); + board.get(77).setText("2"); + + Box bbox = Box.createHorizontalBox(); + vbox.add(bbox); + bbox.add(Box.createHorizontalGlue()); + JButton solve = new JButton("Solve"); + solve.setFont(new Font("Helvetica", Font.PLAIN, 12)); + solve.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + ps.process(); + } + }); + + bbox.add(solve); + bbox.add(Box.createHorizontalGlue()); + JButton clear = new JButton("Clear"); + clear.setFont(new Font("Helvetica", Font.PLAIN, 12)); + clear.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + clear(); + } + }); + + bbox.add(clear); + bbox.add(Box.createHorizontalGlue()); + + vbox.add(Box.createVerticalStrut(20)); + + Box pmsgbox = Box.createHorizontalBox(); + vbox.add(pmsgbox); + pmsgbox.add(Box.createHorizontalGlue()); + JLabel pmsglabel = new JLabel("Powered by:"); + pmsglabel.setForeground(Color.WHITE); + pmsglabel.setFont(new Font("Helvetica", Font.PLAIN, 10)); + pmsgbox.add(pmsglabel); + pmsgbox.add(Box.createHorizontalGlue()); + + vbox.add(Box.createVerticalStrut(5)); + + URL url = getClass().getResource(AILLOGO_PATH); + ImageIcon powimage = new ImageIcon(url); + + Box powbox = Box.createHorizontalBox(); + vbox.add(powbox); + powbox.add(Box.createHorizontalGlue()); + JLabel powlabel = new JLabel(powimage); + powbox.add(powlabel); + powbox.add(Box.createHorizontalGlue()); + + vbox.add(Box.createVerticalStrut(10)); + + Box failbox = Box.createHorizontalBox(); + vbox.add(failbox); + failbox.add(Box.createHorizontalGlue()); + failbox.add(this.unsolvable); + unsolvable.setFont(new Font("Helvetica", Font.PLAIN, 10)); + unsolvable.setForeground(Color.WHITE); + failbox.add(Box.createHorizontalGlue()); + + //pack(); + + return pane; + } + + + private void clear(){ + for (JTextField square: board){ + square.setText(""); + } + } + + private class JImagePanel extends JPanel { + Image hpback; + + public JImagePanel() { + URL url = getClass().getResource(HPBACK); + hpback = new ImageIcon(url).getImage(); + setPreferredSize(new Dimension(hpback.getWidth(null), hpback.getHeight(null))); + } + + public void paintComponent (Graphics g) { + super.paintComponent(g); + g.drawImage(hpback,0,0,getWidth(),getHeight(),null); + } + } + + public interface ProcessSquares { + void process(); + } + +} Property changes on: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/BaseSudokuFrontEnd.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/HP_ICON.PNG =================================================================== (Binary files differ) Property changes on: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/HP_ICON.PNG ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + application/octet-stream Added: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplet.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplet.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplet.java 2009-01-21 17:09:59 UTC (rev 7283) @@ -0,0 +1,11 @@ +package org.smartfrog.examples.sudoku; + +import javax.swing.JApplet; +import javax.swing.JLabel; + +public class SudokuApplet extends JApplet { + public void init(){ + SudokuApplicationClient sud = new SudokuApplicationClient(); + setContentPane(sud.bsfe.init()); + } +} Property changes on: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplet.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplication.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplication.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplication.java 2009-01-21 17:09:59 UTC (rev 7283) @@ -0,0 +1,62 @@ +package org.smartfrog.examples.sudoku; + +import java.util.Vector; + +import org.smartfrog.SFParse; +import org.smartfrog.SFParse.RawParseModifier; +import org.smartfrog.sfcore.componentdescription.ComponentDescription; + +public class SudokuApplication extends BaseSudokuApplication { + + public void process(){ + //Collect together puzzle input... + final Vector puzzle = new Vector(); + for(int i=0;i<bsfe.board.size();i++){ + Location l = convertLocation(i); + Vector entry = new Vector(); + String text = bsfe.board.get(i).getText(); + if (text.equals("")) continue; + Integer val = Integer.parseInt(text); + entry.add(l.loc); + entry.add(val); + puzzle.add(entry); + } + + ComponentDescription cd = null; + + try { + cd=SFParse.parseFileToDescription(sudoko9, new RawParseModifier(){ + + public void modify(ComponentDescription cd){ + ComponentDescription sfConfig = (ComponentDescription) cd.sfContext().get("sfConfig"); + sfConfig.sfContext().put("puzzle", puzzle); + } + }); + } catch (Throwable t){/*Do nothing*/} + + if (cd!=null){ + Vector result = (Vector) cd.sfContext().get("puzzle"); + + for(int i=0; i<result.size(); i++){ + Vector square = (Vector) result.get(i); + Vector loc = (Vector) square.get(0); + int r = ((Integer)loc.get(0)).intValue(); + int c = ((Integer)loc.get(1)).intValue(); + int sq = convertLocationToIndex(r, c); + int v = ((Integer)square.get(1)).intValue(); + bsfe.board.get(sq).setText(""+v); + } + bsfe.unsolvable.setText(""); + } else { + //System.out.println("No Solution"); + bsfe.unsolvable.setText("No solution found"); + } + } + + public static void main(String[] args){ + properties(); + SudokuApplication frame = new SudokuApplication(); + frame.app_init(); + } + +} Property changes on: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplication.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplicationClient.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplicationClient.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplicationClient.java 2009-01-21 17:09:59 UTC (rev 7283) @@ -0,0 +1,70 @@ +package org.smartfrog.examples.sudoku; + +import org.restlet.Client; +import org.restlet.data.Protocol; +import org.restlet.data.Reference; +import org.restlet.data.Response; + +public class SudokuApplicationClient extends BaseSudokuApplication { + + static public String hostip = "16.25.168.89:8182"; + //static public String hostip = "www-apps.hpl.hp.com"; + + public void process(){ + //Collect together puzzle input... + + //String url="http://"+hostip+"/sudoku/solver"; + String url="http://"+hostip+"/solver"; + + boolean first=true; + + for(int i=0;i<bsfe.board.size();i++){ + String text = bsfe.board.get(i).getText(); + if (text.equals("")) continue; + if (first) { + url+="?"; + first=false; + } + else url+="&"; + Integer val = Integer.parseInt(text); + url+=""+i+"="+val; + } + + //System.out.println(url); + + // Define our Restlet HTTP client. + Client client = new Client(Protocol.HTTP); + + // The URI of the resource "list of items". + Reference reference = new Reference(url); + + Response response = client.get(reference); + + String result = null; + + if (response.getStatus().isSuccess()) { + if (response.isEntityAvailable()) { + try {result = response.getEntity().getText();} catch (Exception e){} + } + } + + if (result!=null){ + while (true){ + int idx = result.indexOf("="); + if (idx==-1) break; + String sq_s = result.substring(0, idx); + int idx1 = result.indexOf("&"); + String val_s = result.substring(idx+1,idx1); + result = result.substring(idx1+1); + Integer sq_i = Integer.parseInt(sq_s); + bsfe.board.get(sq_i.intValue()).setText(val_s); + } + bsfe.unsolvable.setText(""); + } else bsfe.unsolvable.setText("No solution found"); + } + + public static void main(String[] args){ + SudokuApplicationClient frame = new SudokuApplicationClient(); + frame.app_init(); + } +} Property changes on: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplicationClient.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplicationServer.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplicationServer.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplicationServer.java 2009-01-21 17:09:59 UTC (rev 7283) @@ -0,0 +1,56 @@ +package org.smartfrog.examples.sudoku; + +import java.io.IOException; + +import org.restlet.Application; +import org.restlet.Component; +import org.restlet.Directory; +import org.restlet.Restlet; +import org.restlet.Router; +import org.restlet.data.Protocol; + +public class SudokuApplicationServer extends Application { + + /** + * Creates a root Restlet that will receive all incoming calls. + */ + @Override + public synchronized Restlet createRoot() { + // Create a router Restlet that routes each call to a new instance of SudokoResource. + Router router = new Router(getContext()); + + // Defines only one route + String ROOT_URI = "file:///home/andrew/sudrestlet"; + + router.attach("/solver", SudokuResource.class); + router.attach("/sudoku", new Directory(getContext(), ROOT_URI)); + + return router; + } + + + public static void main(String[] args) throws IOException { + try { + + //Set Properties for SF solving... + //BaseSudokuApplication.properties(); + + // Create a new Component. + Component component = new Component(); + + // Add a new HTTP server listening on port 8182. + component.getServers().add(Protocol.HTTP, 8182); + component.getClients().add(Protocol.FILE); + + // Attach the sample application. + component.getDefaultHost().attach(new SudokuApplicationServer()); + + // Start the component. + component.start(); + + } catch (Exception e) { + // Something is wrong. + e.printStackTrace(); + } + } +} Property changes on: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplicationServer.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplicationServlet.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplicationServlet.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuApplicationServlet.java 2009-01-21 17:09:59 UTC (rev 7283) @@ -0,0 +1,27 @@ +package org.smartfrog.examples.sudoku; + +import java.io.IOException; + +import org.restlet.Application; +import org.restlet.Component; +import org.restlet.Directory; +import org.restlet.Restlet; +import org.restlet.Router; +import org.restlet.data.Protocol; + +public class SudokuApplicationServlet extends Application { + + /** + * Creates a root Restlet that will receive all incoming calls. + */ + @Override + public synchronized Restlet createRoot() { + // Create a router Restlet that routes each call to a new instance of SudokoResource. + Router router = new Router(getContext()); + + router.attachDefault(SudokuResource.class); + + return router; + } + +} Added: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuResource.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuResource.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuResource.java 2009-01-21 17:09:59 UTC (rev 7283) @@ -0,0 +1,89 @@ +package org.smartfrog.examples.sudoku; + +import java.util.Vector; + +import org.restlet.Context; +import org.restlet.data.Form; +import org.restlet.data.MediaType; +import org.restlet.data.Parameter; +import org.restlet.data.Request; +import org.restlet.data.Response; +import org.restlet.resource.Representation; +import org.restlet.resource.Resource; +import org.restlet.resource.ResourceException; +import org.restlet.resource.StringRepresentation; +import org.restlet.resource.Variant; +import org.smartfrog.SFParse; +import org.smartfrog.SFParse.RawParseModifier; +import org.smartfrog.examples.sudoku.BaseSudokuApplication.Location; +import org.smartfrog.sfcore.componentdescription.ComponentDescription; + +/** + * Resource which has only one representation. + * +*/ +public class SudokuResource extends Resource { + + public SudokuResource(Context context, Request request, Response response) { + super(context, request, response); + + // This representation has only one type of representation. + getVariants().add(new Variant(MediaType.TEXT_PLAIN)); + } + + /** + * Returns a full representation for a given variant. + */ + @Override + public Representation represent(Variant variant) throws ResourceException { + + //Collect together puzzle input... + final Vector puzzle = new Vector(); + + Form form = getRequest().getResourceRef().getQueryAsForm(); + for (Parameter para : form){ + String sq_s = para.getName(); + String val_s = para.getValue(); + Integer sq_i = Integer.parseInt(sq_s); + Integer val_i = Integer.parseInt(val_s); + Location l = BaseSudokuApplication.convertLocation(sq_i.intValue()); + Vector entry = new Vector(); + entry.add(l.loc); + entry.add(val_i.intValue()); + puzzle.add(entry); + } + + BaseSudokuApplication.properties(); + + ComponentDescription cd = null; + + try { + cd=SFParse.parseFileToDescription(BaseSudokuApplication.sudoko9, new RawParseModifier(){ + + public void modify(ComponentDescription cd){ + ComponentDescription sfConfig = (ComponentDescription) cd.sfContext().get("sfConfig"); + sfConfig.sfContext().put("puzzle", puzzle); + } + }); + } catch (Throwable t){System.out.println("Caught exception");/*Do nothing*/} + + String return_str =""; + + if (cd!=null){ + Vector result = (Vector) cd.sfContext().get("puzzle"); + + for(int i=0; i<result.size(); i++){ + Vector square = (Vector) result.get(i); + Vector loc = (Vector) square.get(0); + int r = ((Integer)loc.get(0)).intValue(); + int c = ((Integer)loc.get(1)).intValue(); + int sq = BaseSudokuApplication.convertLocationToIndex(r, c); + int v = ((Integer)square.get(1)).intValue(); + return_str += sq+"="+v+"&"; + } + } + + Representation representation = new StringRepresentation(return_str, MediaType.TEXT_PLAIN); + return representation; + } +} \ No newline at end of file Property changes on: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/SudokuResource.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/TestClient.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/TestClient.java (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/TestClient.java 2009-01-21 17:09:59 UTC (rev 7283) @@ -0,0 +1,26 @@ +package org.smartfrog.examples.sudoku; + +import java.io.IOException; + +import org.restlet.Client; +import org.restlet.data.Protocol; +import org.restlet.data.Reference; +import org.restlet.data.Response; + +public class TestClient { + + public static void main(String[] args) throws IOException { + // Define our Restlet HTTP client. + Client client = new Client(Protocol.HTTP); + + // The URI of the resource "list of items". + Reference reference = new Reference("http://localhost:8182/foo"); + + Response response = client.get(reference); + if (response.getStatus().isSuccess()) { + if (response.isEntityAvailable()) { + response.getEntity().write(System.out); + } + } + } +} Property changes on: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/TestClient.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/hpback.GIF =================================================================== (Binary files differ) Property changes on: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/hpback.GIF ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + application/octet-stream Added: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/hpback.PNG =================================================================== (Binary files differ) Property changes on: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/hpback.PNG ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + application/octet-stream Added: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/sflabsng.PNG =================================================================== (Binary files differ) Property changes on: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/sflabsng.PNG ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + application/octet-stream Added: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/sudoko9.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/sudoko9.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/sudoko9.sf 2009-01-21 17:09:59 UTC (rev 7283) @@ -0,0 +1,66 @@ +#include "/org/smartfrog/functions.sf" + +Squares extends Constraint { + [sfSource] -- LAZY Board; + [sfPrefix] -- "square"; + [sfPath] -- LAZY val; + [sfUpdate] squares; + [sfConstraint] cons "true"; //some assignments may be added automatically through squares... +} + + +SuDoko9 extends { + + puzzle TBD; + + Board extends Array { + [sfPrefix] -- "square"; + [sfExtent] -- [9,9]; + [sfGenerator] -- extends ArrayGenerator, Constraint { + val VAR "[1..9]"; + } + } + + PreValues extends Squares { + squares puzzle; + } + + Constraints extends Array { + [sfPrefix] -- "cons"; + [sfExtent] -- 9; + [sfGenerator] -- extends ArrayGenerator, Constraint { + [sfContext] index sfIndex; //local sfIndex + [sfSource] -- LAZY Board; + [sfPrefix] -- "square"; + [sfPath] -- LAZY val; + [sfPred] -- (index == LAZY sfIndex0); + [sfUpdate] ver; + [sfPred] -- (index == LAZY sfIndex1); + [sfUpdate] hor; + [sfPred] -- (index == (((LAZY sfIndex1 / 3)*3) + (LAZY sfIndex0 / 3))); + [sfUpdate] sq; + [sfConstraint] -- "alldifferent(hor), alldifferent(ver), alldifferent(sq)"; + } + } + + + Label extends Squares { + cons "labeling(squares)"; + } + + PrintSolution extends PrettyPrint { + [sfSource] -- LAZY Board; + [sfPrefix] -- "square"; + [sfPath] -- LAZY val; + [sfUpdate] output; + } + + WriteBack extends PolicyEvaluation { + [sfEffects] -- extends { + puzzle PrintSolution:output; + } + } + +} + +sfConfig extends SuDoko9 {} \ No newline at end of file Property changes on: trunk/core/smartfrog/src/org/smartfrog/examples/sudoku/sudoko9.sf ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |