From 9efb06a5f3505523cde5cf27f5320211c8e29e85 Mon Sep 17 00:00:00 2001 From: John Charron Date: Wed, 2 Feb 2011 09:49:44 +0100 Subject: [PATCH 01/13] Seance de travail, ajout de TotalScore et WordScore (jc) --- .gitignore | 3 +- code/PtiClic/src/org/pticlic/Score.java | 7 +-- .../src/org/pticlic/games/BaseGame.java | 6 +- .../org/pticlic/model/DownloadedScore.java | 11 ---- .../model/{GamePlayed.java => Match.java} | 4 +- .../src/org/pticlic/model/Network.java | 6 +- .../src/org/pticlic/model/TotalScore.java | 45 ++++++++++++++ .../src/org/pticlic/model/WordScore.java | 62 +++++++++++++++++++ 8 files changed, 120 insertions(+), 24 deletions(-) delete mode 100644 code/PtiClic/src/org/pticlic/model/DownloadedScore.java rename code/PtiClic/src/org/pticlic/model/{GamePlayed.java => Match.java} (94%) create mode 100644 code/PtiClic/src/org/pticlic/model/TotalScore.java create mode 100644 code/PtiClic/src/org/pticlic/model/WordScore.java diff --git a/.gitignore b/.gitignore index 496ee2c..748e5b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.DS_Store \ No newline at end of file +.DS_Store +code.zip diff --git a/code/PtiClic/src/org/pticlic/Score.java b/code/PtiClic/src/org/pticlic/Score.java index b3cbb37..b9c1f8e 100644 --- a/code/PtiClic/src/org/pticlic/Score.java +++ b/code/PtiClic/src/org/pticlic/Score.java @@ -1,8 +1,7 @@ package org.pticlic; import org.pticlic.model.Constant; -import org.pticlic.model.DownloadedScore; -import org.pticlic.model.GamePlayed; +import org.pticlic.model.Match; import org.pticlic.model.Network; import org.pticlic.model.Network.Mode; @@ -21,7 +20,7 @@ import android.widget.Button; */ public class Score extends Activity implements OnClickListener{ - private GamePlayed gamePlayed; + private Match gamePlayed; @Override protected void onCreate(Bundle savedInstanceState) { @@ -36,7 +35,7 @@ public class Score extends Activity implements OnClickListener{ if (getIntent().getExtras() != null) { // Pour JC : GamePlayed contient toutes les infos sur la partie jouee - this.gamePlayed = (GamePlayed) getIntent().getExtras().get(Constant.SCORE_GAMEPLAYED); + this.gamePlayed = (Match) getIntent().getExtras().get(Constant.SCORE_GAMEPLAYED); mode = (Mode) getIntent().getExtras().get(Constant.SCORE_MODE); } diff --git a/code/PtiClic/src/org/pticlic/games/BaseGame.java b/code/PtiClic/src/org/pticlic/games/BaseGame.java index f3b68ac..c0d5e37 100644 --- a/code/PtiClic/src/org/pticlic/games/BaseGame.java +++ b/code/PtiClic/src/org/pticlic/games/BaseGame.java @@ -4,7 +4,7 @@ import org.pticlic.R; import org.pticlic.Score; import org.pticlic.model.Constant; import org.pticlic.model.DownloadedGame; -import org.pticlic.model.GamePlayed; +import org.pticlic.model.Match; import org.pticlic.model.Network; import org.pticlic.model.Relation; import org.pticlic.model.Network.Mode; @@ -41,7 +41,7 @@ public class BaseGame extends Activity implements OnClickListener { private int currentWord = 0; private int nbWord = 0; private DownloadedGame game; - private GamePlayed gamePlayed; + private Match gamePlayed; /** Called when the activity is first created. */ @Override @@ -62,7 +62,7 @@ public class BaseGame extends Activity implements OnClickListener { nbWord = game.getNbWord(); // On initialise la partie. - gamePlayed = new GamePlayed(); + gamePlayed = new Match(); gamePlayed.setGame(game); Relation r = Relation.getInstance(); diff --git a/code/PtiClic/src/org/pticlic/model/DownloadedScore.java b/code/PtiClic/src/org/pticlic/model/DownloadedScore.java deleted file mode 100644 index 1447288..0000000 --- a/code/PtiClic/src/org/pticlic/model/DownloadedScore.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.pticlic.model; - -/** - * @author Bertrand BRUN - * - * Classe metier reprensentant le score sous forme json envoyer par le serveur. - * - */ -public class DownloadedScore { - -} diff --git a/code/PtiClic/src/org/pticlic/model/GamePlayed.java b/code/PtiClic/src/org/pticlic/model/Match.java similarity index 94% rename from code/PtiClic/src/org/pticlic/model/GamePlayed.java rename to code/PtiClic/src/org/pticlic/model/Match.java index e43507d..18c9129 100644 --- a/code/PtiClic/src/org/pticlic/model/GamePlayed.java +++ b/code/PtiClic/src/org/pticlic/model/Match.java @@ -11,7 +11,7 @@ import java.util.ArrayList; * puisse calculer le score obtenue. * */ -public class GamePlayed implements Serializable { +public class Match implements Serializable { private static final long serialVersionUID = 1L; private ArrayList relation1; @@ -21,7 +21,7 @@ public class GamePlayed implements Serializable { private ArrayList poubelle; private DownloadedGame game; - public GamePlayed() { + public Match() { relation1 = new ArrayList(); relation2 = new ArrayList(); relation3 = new ArrayList(); diff --git a/code/PtiClic/src/org/pticlic/model/Network.java b/code/PtiClic/src/org/pticlic/model/Network.java index d82f68d..3ba4991 100644 --- a/code/PtiClic/src/org/pticlic/model/Network.java +++ b/code/PtiClic/src/org/pticlic/model/Network.java @@ -138,8 +138,8 @@ public class Network { * @param game La partie jouee par l'utilisateur * @return Le score sous forme JSON. */ - public DownloadedScore sendGame(GamePlayed game) { - DownloadedScore score = null; + public TotalScore sendGame(Match game) { + TotalScore score = null; try { URL url = new URL(this.serverURL); URLConnection connection = url.openConnection(); @@ -155,7 +155,7 @@ public class Network { JsonReader reader = new JsonReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); // TODO : A changer lorsque je serais exactement ce que renvoie le serveur. - score = gson.fromJson(reader, DownloadedScore.class); + score = gson.fromJson(reader, TotalScore.class); } catch (IOException e) { return score; diff --git a/code/PtiClic/src/org/pticlic/model/TotalScore.java b/code/PtiClic/src/org/pticlic/model/TotalScore.java new file mode 100644 index 0000000..ddbf7ca --- /dev/null +++ b/code/PtiClic/src/org/pticlic/model/TotalScore.java @@ -0,0 +1,45 @@ +package org.pticlic.model; + +/** + * + * @author John CHARRON + * + */ + +public class TotalScore { + + private TotalScore scoreTotal; + private WordScore scores; + + public TotalScore() { + } + + public TotalScore(TotalScore scoreTotal, WordScore wordscores) { + this.scoreTotal = scoreTotal; + this.scores = wordscores; + } + + public TotalScore getScoreTotal() { + return scoreTotal; + } + + public void setScoreTotal(TotalScore scoreTotal) { + this.scoreTotal = scoreTotal; + } + + public WordScore getWordscores() { + return scores; + } + + public void setWordscores(WordScore wordscores) { + this.scores = wordscores; + } + + @Override + public String toString() { + return "TotalScore [scoreTotal=" + scoreTotal + ", wordscores=" + + scores + "]"; + } + + +} \ No newline at end of file diff --git a/code/PtiClic/src/org/pticlic/model/WordScore.java b/code/PtiClic/src/org/pticlic/model/WordScore.java new file mode 100644 index 0000000..50d3b95 --- /dev/null +++ b/code/PtiClic/src/org/pticlic/model/WordScore.java @@ -0,0 +1,62 @@ +package org.pticlic.model; + +/** + * + * @author John CHARRON + * + */ + +public class WordScore { + + private int idmot; + private double score; + private double probaR1; + private double probaR2; + + public WordScore() {} + + public WordScore(int idmot, double score, double probaR1, double probaR2) { + this.idmot = idmot; + this.score = score; + this.probaR1 = probaR1; + this.probaR2 = probaR2; + } + + public int getIdmot() { + return idmot; + } + + public void setIdmot(int idmot) { + this.idmot = idmot; + } + + public double getScore() { + return score; + } + + public void setScore(double score) { + this.score = score; + } + + public double getProbaR1() { + return probaR1; + } + + public void setProbaR1(double probaR1) { + this.probaR1 = probaR1; + } + + public double getProbaR2() { + return probaR2; + } + + public void setProbaR2(double probaR2) { + this.probaR2 = probaR2; + } + + @Override + public String toString() { + return "WordScore [idmot=" + idmot + ", score=" + score + ", probaR1=" + + probaR1 + ", probaR2=" + probaR2 + "]"; + } +} From 9a5d3d9cb9f18846618c20e8f54ad3ea58e86cb5 Mon Sep 17 00:00:00 2001 From: Bertrand BRUN Date: Wed, 2 Feb 2011 10:08:26 +0100 Subject: [PATCH 02/13] merge ? --- .../src/org/pticlic/model/GamePlayed.java | 100 +++++++++++++++--- .../src/org/pticlic/model/Network.java | 16 ++- 2 files changed, 101 insertions(+), 15 deletions(-) diff --git a/code/PtiClic/src/org/pticlic/model/GamePlayed.java b/code/PtiClic/src/org/pticlic/model/GamePlayed.java index e43507d..7b14bad 100644 --- a/code/PtiClic/src/org/pticlic/model/GamePlayed.java +++ b/code/PtiClic/src/org/pticlic/model/GamePlayed.java @@ -13,20 +13,20 @@ import java.util.ArrayList; */ public class GamePlayed implements Serializable { - private static final long serialVersionUID = 1L; - private ArrayList relation1; - private ArrayList relation2; - private ArrayList relation3; - private ArrayList relation4; - private ArrayList poubelle; - private DownloadedGame game; + private static final long serialVersionUID = 1L; + private ArrayList relation1; + private ArrayList relation2; + private ArrayList relation3; + private ArrayList relation4; + private ArrayList trash; + private DownloadedGame game; public GamePlayed() { - relation1 = new ArrayList(); - relation2 = new ArrayList(); - relation3 = new ArrayList(); - relation4 = new ArrayList(); - poubelle = new ArrayList(); + relation1 = new ArrayList(); + relation2 = new ArrayList(); + relation3 = new ArrayList(); + relation4 = new ArrayList(); + trash = new ArrayList(); } public void setGame(DownloadedGame game) { @@ -37,13 +37,85 @@ public class GamePlayed implements Serializable { return game; } - public void add(int relation, CharSequence word) { + public void add(int relation, String word) { switch (relation) { case 1: relation1.add(word); break; case 2: relation2.add(word); break; case 3: relation3.add(word); break; case 4: relation4.add(word); break; - default: poubelle.add(word); break; + default: trash.add(word); break; } } + + /** + * @return the relation1 + */ + public ArrayList getRelation1() { + return relation1; + } + + /** + * @return the relation2 + */ + public ArrayList getRelation2() { + return relation2; + } + + /** + * @return the relation3 + */ + public ArrayList getRelation3() { + return relation3; + } + + /** + * @return the relation4 + */ + public ArrayList getRelation4() { + return relation4; + } + + /** + * @return the trash + */ + public ArrayList getTrash() { + return trash; + } + + /** + * @param relation1 the relation1 to set + */ + public void setRelation1(ArrayList relation1) { + this.relation1 = relation1; + } + + /** + * @param relation2 the relation2 to set + */ + public void setRelation2(ArrayList relation2) { + this.relation2 = relation2; + } + + /** + * @param relation3 the relation3 to set + */ + public void setRelation3(ArrayList relation3) { + this.relation3 = relation3; + } + + /** + * @param relation4 the relation4 to set + */ + public void setRelation4(ArrayList relation4) { + this.relation4 = relation4; + } + + /** + * @param trash the trash to set + */ + public void setTrash(ArrayList trash) { + this.trash = trash; + } + + } diff --git a/code/PtiClic/src/org/pticlic/model/Network.java b/code/PtiClic/src/org/pticlic/model/Network.java index d82f68d..1148140 100644 --- a/code/PtiClic/src/org/pticlic/model/Network.java +++ b/code/PtiClic/src/org/pticlic/model/Network.java @@ -82,7 +82,7 @@ public class Network { reader.close(); } catch (IOException e) { e.printStackTrace(); - + return null; } @@ -148,6 +148,20 @@ public class Network { connection.addRequestProperty("passwd", this.passwd); connection.addRequestProperty("mode", mode.value()); + if (game.getGame().getCat1() != -1) { +// for (game.getRelation1()) +// connection.addRequestProperty("cat1[]", newValue); + } + if (game.getGame().getCat2() != -1) { + + } + if (game.getGame().getCat3() != -1) { + + } + if (game.getGame().getCat4() != -1) { + + } + Gson gson = new Gson(); String json = gson.toJson(game); From 4dddb4f4fc99db28bfe4d668d5396b49497965ab Mon Sep 17 00:00:00 2001 From: Bertrand BRUN Date: Wed, 2 Feb 2011 10:42:52 +0100 Subject: [PATCH 03/13] Changement du type de parametre pour la methode add de GamePlayed --- .../src/org/pticlic/games/BaseGame.java | 14 ++-- .../src/org/pticlic/model/GamePlayed.java | 68 +++++-------------- .../src/org/pticlic/model/Network.java | 55 ++++++++------- 3 files changed, 55 insertions(+), 82 deletions(-) diff --git a/code/PtiClic/src/org/pticlic/games/BaseGame.java b/code/PtiClic/src/org/pticlic/games/BaseGame.java index f3b68ac..aa2b951 100644 --- a/code/PtiClic/src/org/pticlic/games/BaseGame.java +++ b/code/PtiClic/src/org/pticlic/games/BaseGame.java @@ -9,6 +9,8 @@ import org.pticlic.model.Network; import org.pticlic.model.Relation; import org.pticlic.model.Network.Mode; +import com.google.gson.Gson; + import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; @@ -54,7 +56,7 @@ public class BaseGame extends Activity implements OnClickListener { String serverURL = sp.getString(Constant.SERVER_URL, "http://dumbs.fr/~bbrun/pticlic.json"); // TODO : Mettre comme valeur par defaut l'adresse reel du serveur String id = sp.getString(Constant.USER_ID, "joueur"); String passwd = sp.getString(Constant.USER_PASSWD, ""); - + // On initialise la classe permettant la communication avec le serveur. Network network = new Network(serverURL, Mode.SIMPLE_GAME, id, passwd); game = network.getGames(1); @@ -64,7 +66,7 @@ public class BaseGame extends Activity implements OnClickListener { // On initialise la partie. gamePlayed = new GamePlayed(); gamePlayed.setGame(game); - + Relation r = Relation.getInstance(); // Boutons des relations @@ -72,7 +74,7 @@ public class BaseGame extends Activity implements OnClickListener { Button r2 = ((Button)findViewById(R.id.relation2)); Button r3 = ((Button)findViewById(R.id.relation3)); Button r4 = ((Button)findViewById(R.id.relation4)); - + // TODO : Pour l'instant la poubelle ne fait rien. Il faudra certainement la ranger dans un categorie dans GamePlayed pour calculer le score. Button trash = ((Button)findViewById(R.id.trash)); trash.setOnClickListener(this); @@ -84,7 +86,7 @@ public class BaseGame extends Activity implements OnClickListener { if (nbrel > 2) { r3.setOnClickListener(this); r3.setText(r.getRelationName(game.getCat3()));} else { r3.setVisibility(View.GONE); } if (nbrel > 3) { r4.setOnClickListener(this); r4.setText(r.getRelationName(game.getCat4()));} else { r4.setVisibility(View.GONE); } - + ((TextView)findViewById(R.id.mainWord)).setText(DownloadedGame.getName(game.getCentre())); } @@ -153,7 +155,7 @@ public class BaseGame extends Activity implements OnClickListener { Intent intent = new Intent(this, Score.class); intent.putExtra(Constant.SCORE_GAMEPLAYED, gamePlayed); intent.putExtra(Constant.SCORE_MODE, Mode.SIMPLE_GAME); - + startActivityForResult(intent, 0x100); } } @@ -163,7 +165,7 @@ public class BaseGame extends Activity implements OnClickListener { */ @Override public void onClick(View v) { - CharSequence currentWord = ((TextView)findViewById(R.id.currentWord)).getText(); + int currentWord = game.getWordInCloud(this.currentWord).getId(); switch (v.getId()) { case (R.id.relation1) : gamePlayed.add(1, currentWord); next(); break; case (R.id.relation2) : gamePlayed.add(2, currentWord); next(); break; diff --git a/code/PtiClic/src/org/pticlic/model/GamePlayed.java b/code/PtiClic/src/org/pticlic/model/GamePlayed.java index 7b14bad..db655e9 100644 --- a/code/PtiClic/src/org/pticlic/model/GamePlayed.java +++ b/code/PtiClic/src/org/pticlic/model/GamePlayed.java @@ -14,19 +14,19 @@ import java.util.ArrayList; public class GamePlayed implements Serializable { private static final long serialVersionUID = 1L; - private ArrayList relation1; - private ArrayList relation2; - private ArrayList relation3; - private ArrayList relation4; - private ArrayList trash; + private ArrayList relation1; + private ArrayList relation2; + private ArrayList relation3; + private ArrayList relation4; + private ArrayList trash; private DownloadedGame game; public GamePlayed() { - relation1 = new ArrayList(); - relation2 = new ArrayList(); - relation3 = new ArrayList(); - relation4 = new ArrayList(); - trash = new ArrayList(); + relation1 = new ArrayList(); + relation2 = new ArrayList(); + relation3 = new ArrayList(); + relation4 = new ArrayList(); + trash = new ArrayList(); } public void setGame(DownloadedGame game) { @@ -37,7 +37,7 @@ public class GamePlayed implements Serializable { return game; } - public void add(int relation, String word) { + public void add(int relation, int word) { switch (relation) { case 1: relation1.add(word); break; case 2: relation2.add(word); break; @@ -50,72 +50,36 @@ public class GamePlayed implements Serializable { /** * @return the relation1 */ - public ArrayList getRelation1() { + public ArrayList getRelation1() { return relation1; } /** * @return the relation2 */ - public ArrayList getRelation2() { + public ArrayList getRelation2() { return relation2; } /** * @return the relation3 */ - public ArrayList getRelation3() { + public ArrayList getRelation3() { return relation3; } /** * @return the relation4 */ - public ArrayList getRelation4() { + public ArrayList getRelation4() { return relation4; } /** * @return the trash */ - public ArrayList getTrash() { + public ArrayList getTrash() { return trash; } - - /** - * @param relation1 the relation1 to set - */ - public void setRelation1(ArrayList relation1) { - this.relation1 = relation1; - } - - /** - * @param relation2 the relation2 to set - */ - public void setRelation2(ArrayList relation2) { - this.relation2 = relation2; - } - - /** - * @param relation3 the relation3 to set - */ - public void setRelation3(ArrayList relation3) { - this.relation3 = relation3; - } - - /** - * @param relation4 the relation4 to set - */ - public void setRelation4(ArrayList relation4) { - this.relation4 = relation4; - } - - /** - * @param trash the trash to set - */ - public void setTrash(ArrayList trash) { - this.trash = trash; - } - } diff --git a/code/PtiClic/src/org/pticlic/model/Network.java b/code/PtiClic/src/org/pticlic/model/Network.java index 1148140..161c8c0 100644 --- a/code/PtiClic/src/org/pticlic/model/Network.java +++ b/code/PtiClic/src/org/pticlic/model/Network.java @@ -21,24 +21,24 @@ public class Network { public enum Action { GET_GAMES } - + public enum Mode { SIMPLE_GAME("normal"); - + private final String value; - + Mode(String value) { this.value = value; } - + private String value() { return value; } } - + private Mode mode; private String serverURL; private String id; private String passwd; - + /** * Constructeur * @@ -53,7 +53,7 @@ public class Network { this.id = id; this.passwd = passwd; } - + /** * Cette méthode permet de récupérer du serveur un certain nombre de parties. * @param nbGames Le nombre de parties que l'on veut récupérer. @@ -69,10 +69,10 @@ public class Network { connection.addRequestProperty("passwd", this.passwd); connection.addRequestProperty("nb", String.valueOf(nbGames)); connection.addRequestProperty("mode", mode.value()); - + Gson gson = new Gson(); JsonReader reader = new JsonReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); - + // FIXME : Attention lorsque l'on pourra vraiment recupere plusieur partie, il faudra changer ce qui suit. reader.beginArray(); while (reader.hasNext()) { @@ -85,10 +85,10 @@ public class Network { return null; } - + return game; } - + /** * Permet la transformation du Json en une instance de Game. * @@ -105,7 +105,7 @@ public class Network { int cat4 = -1; DownloadedGame.Word center = null; DownloadedGame.Word[] cloud = null; - + reader.beginObject(); while (reader != null && reader.hasNext()) { String name = reader.nextName(); @@ -130,8 +130,8 @@ public class Network { reader.endObject(); return new DownloadedGame(id, cat1, cat2, cat3, cat4, center, cloud); } - - + + /** * Cette méthode permet d'envoyer les parties au serveur pour qu'il puisse les * rajouter à la base de données, et calculer le score. @@ -147,30 +147,37 @@ public class Network { connection.addRequestProperty("user", this.id); connection.addRequestProperty("passwd", this.passwd); connection.addRequestProperty("mode", mode.value()); - + if (game.getGame().getCat1() != -1) { -// for (game.getRelation1()) -// connection.addRequestProperty("cat1[]", newValue); + for (Integer i : game.getRelation1()) { + connection.addRequestProperty("cat1[]", i.toString()); + } } if (game.getGame().getCat2() != -1) { - + for (Integer i : game.getRelation2()) { + connection.addRequestProperty("cat2[]", i.toString()); + } } if (game.getGame().getCat3() != -1) { - + for (Integer i : game.getRelation3()) { + connection.addRequestProperty("cat3[]", i.toString()); + } } if (game.getGame().getCat4() != -1) { - + for (Integer i : game.getRelation4()) { + connection.addRequestProperty("cat4[]", i.toString()); + } + } + for (Integer i : game.getTrash()) { + connection.addRequestProperty("trash[]", i.toString()); } Gson gson = new Gson(); - String json = gson.toJson(game); - - connection.addRequestProperty("json", json); JsonReader reader = new JsonReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); - // TODO : A changer lorsque je serais exactement ce que renvoie le serveur. score = gson.fromJson(reader, DownloadedScore.class); + } catch (IOException e) { return score; } From d5e18a87094260df04f94f0ad7aafdd6c7141834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Wed, 2 Feb 2011 11:22:59 +0100 Subject: [PATCH 04/13] =?UTF-8?q?Cr=C3=A9ation=20de=20parties=20:=20100%?= =?UTF-8?q?=20(manque=20le=20debug).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/serveur/.gitignore | 2 +- code/serveur/dump2sqlite.sh | 2 ++ code/serveur/php/config.php | 10 ------ code/serveur/php/function.php | 36 --------------------- code/serveur/php/pticlic.php | 61 ++++++++++++++++++++--------------- 5 files changed, 38 insertions(+), 73 deletions(-) delete mode 100755 code/serveur/php/config.php delete mode 100755 code/serveur/php/function.php diff --git a/code/serveur/.gitignore b/code/serveur/.gitignore index d89ba74..f7b273d 100644 --- a/code/serveur/.gitignore +++ b/code/serveur/.gitignore @@ -1,3 +1,3 @@ -01042011-LEXICALNET-JEUXDEMOTS-FR-NOHTML.txt +*-LEXICALNET-JEUXDEMOTS-FR-NOHTML.txt db sql diff --git a/code/serveur/dump2sqlite.sh b/code/serveur/dump2sqlite.sh index 6ad4d0e..928b11c 100755 --- a/code/serveur/dump2sqlite.sh +++ b/code/serveur/dump2sqlite.sh @@ -1,5 +1,7 @@ #!/bin/sh +# TODO : sed -E sur certaines machines, sed -r sur d'autres. + echo " dump2sql.sh : conversion des dumps de JeuxDeMots vers du sql (sqlite3)." >&2 echo " La progression est affichée avec pv. Si vous n'avez pas pv, supprimez la ligne correspondante dans ce script." >&2 echo " Et c'est parti !" >&2 diff --git a/code/serveur/php/config.php b/code/serveur/php/config.php deleted file mode 100755 index b1f5583..0000000 --- a/code/serveur/php/config.php +++ /dev/null @@ -1,10 +0,0 @@ - diff --git a/code/serveur/php/function.php b/code/serveur/php/function.php deleted file mode 100755 index 1a35272..0000000 --- a/code/serveur/php/function.php +++ /dev/null @@ -1,36 +0,0 @@ -\nVoici l'erreur renvoyée par le serveur MySQL :\n
\n".mysql_error()); - - return $linkid; -} - -function secure($string) -{ - if(ctype_digit($string)) - { - $string = intval($string); - } - else - { - $string = sqlite_escape_string($string); - $string = addcslashes($string, '%_'); - } - - return $string; -} - -function writeRequest($request) -{ - -} -?> \ No newline at end of file diff --git a/code/serveur/php/pticlic.php b/code/serveur/php/pticlic.php index 237f3a5..e823374 100644 --- a/code/serveur/php/pticlic.php +++ b/code/serveur/php/pticlic.php @@ -69,23 +69,27 @@ function cg_build_result_sets($cloudSize, $centerEid, $r1, $r2) { // Ce n'est toujours pas ça… : "select eid from (select B.start as eid from relation as A, relation as B where A.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and A.start = $centerEid and B.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and B.end = A.end limit 1) order by random();" // Tordu, mais ça marche \o/ . En fait il faut empêcher l'optimiseur de ramener le random avant le limit (et l'optimiseur est malin… :) array('w'=>10, 'd'=>8, 's'=>"select x as eid, -0.1 as r1, -0.1 as r2 from (select x from (select X.eid + Y.dumb as x from (select B.start as eid from relation as A, relation as B where A.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and A.start = 74860 and B.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and B.end = A.end limit $cloudSize) as X, (select 0 as dumb) as Y)) order by random();"), - array('w'=>10, 's'=>false) // random. Le r1 et r2 de random sont juste en-dessous + 'rand' => array('w'=>10, 's'=>false) // random. Le r1 et r2 de random sont juste en-dessous ); $sumWeights = 0; foreach ($sources as $k => $x) { - $sumWeights += $x['w']; + $sumWeights += $x['w']; + $sources[$k]['rsPos'] = 0; + $sources[$k]['rsSize'] = 0; if ($x['s'] !== false) { $sources[$k]['resultSet'] = array(); $res = $db->query($x['s']); $i = 0; while ($i < 10 && $sources[$k]['resultSet'][] = $res->fetchArray()) { - $i++; + $i++; + $sources[$k]['rsSize']++; } } else { $sources[$k]['resultSet'] = array(); for ($i = 0; $i < 10; $i++) { $sources[$k]['resultSet'][] = array('eid'=>random_node(), 'r1'=>-1, 'r2'=>-1); + $sources[$k]['rsSize']++; } } } @@ -106,32 +110,46 @@ function cg_build_cloud($cloudSize, $sources, $sumWeights) { // On boucle tant qu'il n'y a pas eu au moins 2 sources épuisées $cloud = array(); $nbFailed = 0; - $i = 0; - while ($i < $cloudSize && $nbFailed < 50) { + $i = 0; + while ($i < $cloudSize && $nbFailed < 5*$cloudSize) { // On choisit une source aléatoire en tennant compte des poids. $rands = rand(1,$sumWeights); $sumw = 0; - $res = false; // TODO + $src = $sources['rand']; foreach ($sources as $x) { $sumw += $x['w']; if ($rands < $sumw) { - $res = $x['resultSet']; + $src = $x; break; } } - if (/* dépassé la fin de ce set */) { + if ($src['rsPos'] >= $src['rsSize']) { $nbFailed++; continue; } - $res = $res['eid']; - if (in_array($res, $cloud)) { + $res = $src['resultSet'][$src['rsPos']++]; + if (in_array($res['eid'], $cloud)) { $nbFailed++; continue; - } - $cloud[] = $res; - $i++; + } + // position dans le nuage, difficulté, eid, probaR1, probaR2 + $cloud[$i] = array('pos'=>$i++, 'd'=>$src['d'], 'eid'=>$res['eid'], 'probaR1'=>$res['r1'], 'probaR2'=>$res['r2']); + } + while ($i < $cloudSize) { + $cloud[$i] = array('pos'=>$i++, 'd'=>$sources['rand']['d'], 'eid'=>random_node(), 'probaR1'=>$sources['rand']['resultSet'][0]['r1'], 'probaR2'=>$sources['rand']['resultSet'][0]['r2']); } return $cloud; +} + +function cg_insert($centerEid, $cloud, $r1, $r2) { + $db->exec("begin transaction;"); + $db->exec("insert into game(gid, eid_central_word, relation_1, relation_2) values (null, $centerEid, $r1, $r2);"); + $gid = $db->lastInsertRowID(); + foreach ($cloud as $c) { + $db->exec("insert into game_cloud(gid, num, difficulty, probaR1, probaR2, eid_word) values($gid, ".$c['pos'].", ".$c['d'].", ".$c['probaR1'].', '.$c['probaR2'].', '.$c['eid'].");"); + } + // TODO : insert into game_played une partie de référence. + $db->exec("commit;"); } function create_game($cloudSize) { @@ -140,20 +158,11 @@ function create_game($cloudSize) { $centerEid = random_node(); $r1 = cg_choose_relations(); $r2 = $r1[1]; $r1 = $r1[0]; $sources = cg_build_result_sets($cloudSize, $centerEid, $r1, $r2); $sumWeights = $sources[1]; $sources = $sources[0]; - $cloud = cg_build_cloud($cloudSize, $sources, $sumWeights); + $cloud = cg_build_cloud($cloudSize, $sources, $sumWeights); + cg_insert($centerEid, $cloud); var_dump($cloud); - exit; - - $db->exec("begin transaction;"); - $db->exec("insert into game(gid, eid_central_word, relation_1, relation_2, relation_3, relation_4, reference_played_game) values (null, ".$centerEid.", 1,2,3,4,null);"); - $gid = $db->lastInsertRowID(); - foreach ($cloud as $eid) { - $db->exec("insert into game_cloud(gid, num, difficulty, eid_word) values(".$gid.", ".$i.", ".$difficulty.", ".$eid.");"); - } - // TODO : insert into game_played une partie de référence. - $db->exec("commit;"); -} + exit; } create_game(10); echo 'ok'; @@ -210,4 +219,4 @@ echo 'ok'; // else // die("Commande inconnue"); -?> \ No newline at end of file +?> From 8733a90bc13a5129d65fa42b38e1ddf326ed78cc Mon Sep 17 00:00:00 2001 From: John Charron Date: Wed, 2 Feb 2011 10:51:02 +0100 Subject: [PATCH 05/13] =?UTF-8?q?Fichier=20info..html=20modifi=C3=A9=20(r?= =?UTF-8?q?=C3=A9daction)=20(jc)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/PtiClic/res/raw/info.html | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/code/PtiClic/res/raw/info.html b/code/PtiClic/res/raw/info.html index 85dea82..06b5299 100644 --- a/code/PtiClic/res/raw/info.html +++ b/code/PtiClic/res/raw/info.html @@ -10,17 +10,21 @@
-

-PtiClic a ete concu et developpe par Mathieu Lafourcade (LIRMM - Universite Montpellier 3) et Virginie Zampa (LIDILEM - Universite Stendhal Grenoble 3)
-

-Merci en particulier a (en vrac) farfadet, mehdi (mym), alain joubert, gilles serasset (krado)...
-

-Pticlic n'est pas exempt de bugs - si vous en rencontrez un, pourriez-vous le signaler a l'administrateur ?
-

-Mathieu Lafourcade - Administrateur - contact
-

-Derniere mise a jour : fevrier 2008 -

+ +

PtiClic a été conçu et développé par Mathieu Lafourcade (LIRMM - Université Montpellier 3) +et Virginie Zampa (LIDILEM - Université Stendhal Grenoble 3)

+ +

La présente version pour SmartPhone sous Android en cours de développement a été +conçue et réalisée par des étudiants en Master 1 à l'Université Montpellier II : +Yoann BONAVERO, Bertrand BRUN, John CHARRON et Georges DUPERON.

+ +

Cette version du PtiClic est une version Alpha. Elle n'est pas exempte de bogues.

+

Si vous souhaitez participer au projet en tant que Bêta-testeur, +rendez-vous sur le site http://www... pour vous y inscrire.

+

Si vous souhaitez signaler des bogues ou de nous fournir des commentaires, vous pouvez +nous contacter sur pticlic.android.beta@gmail.com

+ +
\ No newline at end of file From bd3030223e59bfe5953436239b58eec217b673dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Wed, 2 Feb 2011 18:14:31 +0100 Subject: [PATCH 06/13] =?UTF-8?q?Note=20:=20page=20avec=20les=20tailles=20?= =?UTF-8?q?des=20ic=C3=B4nes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- organisation/notes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/organisation/notes b/organisation/notes index 85837d2..ed2661f 100644 --- a/organisation/notes +++ b/organisation/notes @@ -1,3 +1,3 @@ - Une classe Constante pour toutes les constantes ("symboles" pour les paramètres, ...). - Boutons pour les différents modes de jeu directement sur la "page de garde". -- Créer un splash au démarrage. +- Icônes : http://developer.android.com/guide/practices/ui_guidelines/icon_design.html From 2276897d8c506ab21e57115857645bf24f4e7215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Wed, 2 Feb 2011 18:48:22 +0100 Subject: [PATCH 07/13] =?UTF-8?q?Correction=20des=20CRLF=20=C3=A0=20la=20n?= =?UTF-8?q?oix=20qui=20sont=20apparus=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/serveur/php/pticlic.php | 418 +++++++++++++++++------------------ 1 file changed, 209 insertions(+), 209 deletions(-) diff --git a/code/serveur/php/pticlic.php b/code/serveur/php/pticlic.php index e823374..bd14e02 100644 --- a/code/serveur/php/pticlic.php +++ b/code/serveur/php/pticlic.php @@ -1,222 +1,222 @@ -exec("insert into user(login, mail, hash_passwd) values('foo', 'foo@isp.com', '".md5('bar')."');"); -} - -// initdb(); - -if(!isset($_GET['action']) || !isset($_GET['user']) || !isset($_GET['passwd'])) - mDie(2,"La requête est incomplète"); - -// Login -$action = $_GET['action']; -$user = $_GET['user']; -$hash_passwd = md5($_GET['passwd']); -if ($hash_passwd !== $db->querySingle("SELECT hash_passwd FROM user WHERE login='".SQLite3::escapeString($user)."';")) - mDie(3,"Utilisateur non enregistré ou mauvais mot de passe"); - -function random_node() { - global $db; - return $db->querySingle("select eid from node where eid = (abs(random()) % (select max(eid) from node))+1 or eid = (select max(eid) from node where eid > 0) order by eid limit 1;"); -} - -// TODO : Yoann : peut-être faire une classe create_game avec les fonctions ci-dessous comme méthodes ? - -function cg_build_result_sets($cloudSize, $centerEid, $r1, $r2) { - global $db; - // 'w' => weight (poids), 'd' => difficulté, 's' => select - // Le select doit ranvoyer trois colonnes : - // eid => l'eid du mot à mettre dans le nuage, - // r1 => la probabilité pour que le mot soit dans r1, entre -1 et 1 (négatif = ne devrait pas y être, positif = devrait y être à coup sûr, 0 = on sait pas). - // TODO : comment mettre un poids sur random, sachant qu'il ne peut / devrait pas être dans ces select, mais plutôt un appel à random_node() ? - $typer1r2 = "type in ($r1, $r2)"; - $sources = array( - // Voisins 1 saut du bon type (= relations déjà existantes) - array('w'=>10, 'd'=>1, 's'=>"select end as eid, type = $r1 as r1, type = $r2 as r2 from relation where start = $centerEid and $typer1r2 order by random();"), - // Voisins 1 saut via r_associated (0), donc qu'on voudrait spécifier si possible. - array('w'=>10, 'd'=>2, 's'=>"select end as eid, 0 as r1, 0 as r2 from relation where start = $centerEid and type = 0 order by random();"), - // Voisins 1 saut via les autres relations - array('w'=>10, 'd'=>3, 's'=>"select end as eid, 0 as r1, 0 as r2 from relation where start = $centerEid and type not in (0, $r1, $r2) order by random();"), - // Voisins 2 sauts, avec un mix de R1 et R2 pour les liens. Par ex [ A -R1-> B -R2-> C ] ou bien [ A -R2-> B -R2-> C ] - // Version optimisée de : "select end as eid from relation where $typer1r2 and start in oneHopWithType order by random();" - array('w'=>10, 'd'=>4, 's'=>"select B.end as eid, ((A.type = $r1) + (B.type = $r1)) / 3 as r1, ((A.type = $r2) + (B.type = $r2)) / 3 as r2 from relation as A, relation as B where A.start = $centerEid and A.$typer1r2 and B.start = A.end and B.$typer1r2 order by random();"), - // Voisins 1 saut r1/r2 + 1 saut synonyme - // Version optimisée de : "select end as eid from relation where start in oneHopWithType and type = 5 order by random();" - array('w'=>10, 'd'=>5, 's'=>"select B.end as eid, (A.type = $r1) * 0.75 as r1, (A.type = $r2) * 0.75 as r2 from relation as A, relation as B where A.start = $centerEid and A.$typer1r2 and B.start = A.end and B.type = 5 order by random();"), - // Version optimisée de : "select end as eid from relation where start in (select end from relation where start = $centerEid and type = 5) and $typer1r2 order by random();" - array('w'=>10, 'd'=>6, 's'=>"select B.end as eid, (B.type = $r1) * 0.75 as r1, (B.type = $r2) * 0.75 as r2 from relation as A, relation as B where A.start = $centerEid and A.type = 5 and B.start = A.end and B.$typer1r2 order by random();"), - // Voisins 2 sauts (tous) - array('w'=>10, 'd'=>7, 's'=>"select end as eid, 0.1 as r1, 0.1 as r2 from relation where start in (select end from relation where start = $centerEid) order by random();"), - // Centre pointe vers X, M pointe vers X aussi, on prend M. - // Version optimisée de : "select start as eid from relation where end in (select end from relation where start = $centerEid) and type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) order by random();" - // Ce n'est toujours pas ça… : "select eid from (select B.start as eid from relation as A, relation as B where A.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and A.start = $centerEid and B.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and B.end = A.end limit 1) order by random();" - // Tordu, mais ça marche \o/ . En fait il faut empêcher l'optimiseur de ramener le random avant le limit (et l'optimiseur est malin… :) - array('w'=>10, 'd'=>8, 's'=>"select x as eid, -0.1 as r1, -0.1 as r2 from (select x from (select X.eid + Y.dumb as x from (select B.start as eid from relation as A, relation as B where A.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and A.start = 74860 and B.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and B.end = A.end limit $cloudSize) as X, (select 0 as dumb) as Y)) order by random();"), - 'rand' => array('w'=>10, 's'=>false) // random. Le r1 et r2 de random sont juste en-dessous - ); - - $sumWeights = 0; - foreach ($sources as $k => $x) { +exec("insert into user(login, mail, hash_passwd) values('foo', 'foo@isp.com', '".md5('bar')."');"); +} + +// initdb(); + +if(!isset($_GET['action']) || !isset($_GET['user']) || !isset($_GET['passwd'])) + mDie(2,"La requête est incomplète"); + +// Login +$action = $_GET['action']; +$user = $_GET['user']; +$hash_passwd = md5($_GET['passwd']); +if ($hash_passwd !== $db->querySingle("SELECT hash_passwd FROM user WHERE login='".SQLite3::escapeString($user)."';")) + mDie(3,"Utilisateur non enregistré ou mauvais mot de passe"); + +function random_node() { + global $db; + return $db->querySingle("select eid from node where eid = (abs(random()) % (select max(eid) from node))+1 or eid = (select max(eid) from node where eid > 0) order by eid limit 1;"); +} + +// TODO : Yoann : peut-être faire une classe create_game avec les fonctions ci-dessous comme méthodes ? + +function cg_build_result_sets($cloudSize, $centerEid, $r1, $r2) { + global $db; + // 'w' => weight (poids), 'd' => difficulté, 's' => select + // Le select doit ranvoyer trois colonnes : + // eid => l'eid du mot à mettre dans le nuage, + // r1 => la probabilité pour que le mot soit dans r1, entre -1 et 1 (négatif = ne devrait pas y être, positif = devrait y être à coup sûr, 0 = on sait pas). + // TODO : comment mettre un poids sur random, sachant qu'il ne peut / devrait pas être dans ces select, mais plutôt un appel à random_node() ? + $typer1r2 = "type in ($r1, $r2)"; + $sources = array( + // Voisins 1 saut du bon type (= relations déjà existantes) + array('w'=>10, 'd'=>1, 's'=>"select end as eid, type = $r1 as r1, type = $r2 as r2 from relation where start = $centerEid and $typer1r2 order by random();"), + // Voisins 1 saut via r_associated (0), donc qu'on voudrait spécifier si possible. + array('w'=>10, 'd'=>2, 's'=>"select end as eid, 0 as r1, 0 as r2 from relation where start = $centerEid and type = 0 order by random();"), + // Voisins 1 saut via les autres relations + array('w'=>10, 'd'=>3, 's'=>"select end as eid, 0 as r1, 0 as r2 from relation where start = $centerEid and type not in (0, $r1, $r2) order by random();"), + // Voisins 2 sauts, avec un mix de R1 et R2 pour les liens. Par ex [ A -R1-> B -R2-> C ] ou bien [ A -R2-> B -R2-> C ] + // Version optimisée de : "select end as eid from relation where $typer1r2 and start in oneHopWithType order by random();" + array('w'=>10, 'd'=>4, 's'=>"select B.end as eid, ((A.type = $r1) + (B.type = $r1)) / 3 as r1, ((A.type = $r2) + (B.type = $r2)) / 3 as r2 from relation as A, relation as B where A.start = $centerEid and A.$typer1r2 and B.start = A.end and B.$typer1r2 order by random();"), + // Voisins 1 saut r1/r2 + 1 saut synonyme + // Version optimisée de : "select end as eid from relation where start in oneHopWithType and type = 5 order by random();" + array('w'=>10, 'd'=>5, 's'=>"select B.end as eid, (A.type = $r1) * 0.75 as r1, (A.type = $r2) * 0.75 as r2 from relation as A, relation as B where A.start = $centerEid and A.$typer1r2 and B.start = A.end and B.type = 5 order by random();"), + // Version optimisée de : "select end as eid from relation where start in (select end from relation where start = $centerEid and type = 5) and $typer1r2 order by random();" + array('w'=>10, 'd'=>6, 's'=>"select B.end as eid, (B.type = $r1) * 0.75 as r1, (B.type = $r2) * 0.75 as r2 from relation as A, relation as B where A.start = $centerEid and A.type = 5 and B.start = A.end and B.$typer1r2 order by random();"), + // Voisins 2 sauts (tous) + array('w'=>10, 'd'=>7, 's'=>"select end as eid, 0.1 as r1, 0.1 as r2 from relation where start in (select end from relation where start = $centerEid) order by random();"), + // Centre pointe vers X, M pointe vers X aussi, on prend M. + // Version optimisée de : "select start as eid from relation where end in (select end from relation where start = $centerEid) and type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) order by random();" + // Ce n'est toujours pas ça… : "select eid from (select B.start as eid from relation as A, relation as B where A.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and A.start = $centerEid and B.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and B.end = A.end limit 1) order by random();" + // Tordu, mais ça marche \o/ . En fait il faut empêcher l'optimiseur de ramener le random avant le limit (et l'optimiseur est malin… :) + array('w'=>10, 'd'=>8, 's'=>"select x as eid, -0.1 as r1, -0.1 as r2 from (select x from (select X.eid + Y.dumb as x from (select B.start as eid from relation as A, relation as B where A.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and A.start = 74860 and B.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and B.end = A.end limit $cloudSize) as X, (select 0 as dumb) as Y)) order by random();"), + 'rand' => array('w'=>10, 's'=>false) // random. Le r1 et r2 de random sont juste en-dessous + ); + + $sumWeights = 0; + foreach ($sources as $k => $x) { $sumWeights += $x['w']; $sources[$k]['rsPos'] = 0; - $sources[$k]['rsSize'] = 0; - if ($x['s'] !== false) { - $sources[$k]['resultSet'] = array(); - $res = $db->query($x['s']); - $i = 0; - while ($i < 10 && $sources[$k]['resultSet'][] = $res->fetchArray()) { + $sources[$k]['rsSize'] = 0; + if ($x['s'] !== false) { + $sources[$k]['resultSet'] = array(); + $res = $db->query($x['s']); + $i = 0; + while ($i < 10 && $sources[$k]['resultSet'][] = $res->fetchArray()) { $i++; - $sources[$k]['rsSize']++; - } - } else { - $sources[$k]['resultSet'] = array(); - for ($i = 0; $i < 10; $i++) { - $sources[$k]['resultSet'][] = array('eid'=>random_node(), 'r1'=>-1, 'r2'=>-1); - $sources[$k]['rsSize']++; - } - } - } - return array($sources, $sumWeights); -} - -function cg_choose_relations() { - $relations = array(5, 7, 9, 10); - $r1 = rand(0,count($relations)-1); - $r2 = rand(0,count($relations)-2); - if ($r2 >= $r1) $r2++; - $r1 = $relations[$r1]; - $r2 = $relations[$r2]; - return array($r1, $r2); -} - -function cg_build_cloud($cloudSize, $sources, $sumWeights) { - // On boucle tant qu'il n'y a pas eu au moins 2 sources épuisées - $cloud = array(); - $nbFailed = 0; - $i = 0; - while ($i < $cloudSize && $nbFailed < 5*$cloudSize) { - // On choisit une source aléatoire en tennant compte des poids. - $rands = rand(1,$sumWeights); - $sumw = 0; - $src = $sources['rand']; - foreach ($sources as $x) { - $sumw += $x['w']; - if ($rands < $sumw) { - $src = $x; - break; - } - } - if ($src['rsPos'] >= $src['rsSize']) { - $nbFailed++; - continue; - } - $res = $src['resultSet'][$src['rsPos']++]; - if (in_array($res['eid'], $cloud)) { - $nbFailed++; - continue; + $sources[$k]['rsSize']++; + } + } else { + $sources[$k]['resultSet'] = array(); + for ($i = 0; $i < 10; $i++) { + $sources[$k]['resultSet'][] = array('eid'=>random_node(), 'r1'=>-1, 'r2'=>-1); + $sources[$k]['rsSize']++; + } } - // position dans le nuage, difficulté, eid, probaR1, probaR2 - $cloud[$i] = array('pos'=>$i++, 'd'=>$src['d'], 'eid'=>$res['eid'], 'probaR1'=>$res['r1'], 'probaR2'=>$res['r2']); + } + return array($sources, $sumWeights); +} + +function cg_choose_relations() { + $relations = array(5, 7, 9, 10); + $r1 = rand(0,count($relations)-1); + $r2 = rand(0,count($relations)-2); + if ($r2 >= $r1) $r2++; + $r1 = $relations[$r1]; + $r2 = $relations[$r2]; + return array($r1, $r2); +} + +function cg_build_cloud($cloudSize, $sources, $sumWeights) { + // On boucle tant qu'il n'y a pas eu au moins 2 sources épuisées + $cloud = array(); + $nbFailed = 0; + $i = 0; + while ($i < $cloudSize && $nbFailed < 5*$cloudSize) { + // On choisit une source aléatoire en tennant compte des poids. + $rands = rand(1,$sumWeights); + $sumw = 0; + $src = $sources['rand']; + foreach ($sources as $x) { + $sumw += $x['w']; + if ($rands < $sumw) { + $src = $x; + break; + } + } + if ($src['rsPos'] >= $src['rsSize']) { + $nbFailed++; + continue; + } + $res = $src['resultSet'][$src['rsPos']++]; + if (in_array($res['eid'], $cloud)) { + $nbFailed++; + continue; + } + // position dans le nuage, difficulté, eid, probaR1, probaR2 + $cloud[$i] = array('pos'=>$i++, 'd'=>$src['d'], 'eid'=>$res['eid'], 'probaR1'=>$res['r1'], 'probaR2'=>$res['r2']); } while ($i < $cloudSize) { $cloud[$i] = array('pos'=>$i++, 'd'=>$sources['rand']['d'], 'eid'=>random_node(), 'probaR1'=>$sources['rand']['resultSet'][0]['r1'], 'probaR2'=>$sources['rand']['resultSet'][0]['r2']); - } - return $cloud; + } + return $cloud; } function cg_insert($centerEid, $cloud, $r1, $r2) { - $db->exec("begin transaction;"); - $db->exec("insert into game(gid, eid_central_word, relation_1, relation_2) values (null, $centerEid, $r1, $r2);"); - $gid = $db->lastInsertRowID(); - foreach ($cloud as $c) { - $db->exec("insert into game_cloud(gid, num, difficulty, probaR1, probaR2, eid_word) values($gid, ".$c['pos'].", ".$c['d'].", ".$c['probaR1'].', '.$c['probaR2'].', '.$c['eid'].");"); - } - // TODO : insert into game_played une partie de référence. + $db->exec("begin transaction;"); + $db->exec("insert into game(gid, eid_central_word, relation_1, relation_2) values (null, $centerEid, $r1, $r2);"); + $gid = $db->lastInsertRowID(); + foreach ($cloud as $c) { + $db->exec("insert into game_cloud(gid, num, difficulty, probaR1, probaR2, eid_word) values($gid, ".$c['pos'].", ".$c['d'].", ".$c['probaR1'].', '.$c['probaR2'].', '.$c['eid'].");"); + } + // TODO : insert into game_played une partie de référence. $db->exec("commit;"); -} - -function create_game($cloudSize) { - global $db; - // select random node - $centerEid = random_node(); - $r1 = cg_choose_relations(); $r2 = $r1[1]; $r1 = $r1[0]; - $sources = cg_build_result_sets($cloudSize, $centerEid, $r1, $r2); $sumWeights = $sources[1]; $sources = $sources[0]; +} + +function create_game($cloudSize) { + global $db; + // select random node + $centerEid = random_node(); + $r1 = cg_choose_relations(); $r2 = $r1[1]; $r1 = $r1[0]; + $sources = cg_build_result_sets($cloudSize, $centerEid, $r1, $r2); $sumWeights = $sources[1]; $sources = $sources[0]; $cloud = cg_build_cloud($cloudSize, $sources, $sumWeights); - cg_insert($centerEid, $cloud); - - var_dump($cloud); - exit; } - -create_game(10); -echo 'ok'; - -// // Sinon tout est bon on effectu l'opération correspondant à la commande passée. -// if($action == 0) // "Get partie" -// { -// // Requête sql de création de partie. -// $req = "..."; - -// $sql = sqlConnect(); -// $resp = mysql_query($req); - -// if(mysql_num_rows($resp) == 0) -// echo mysql_error(); -// else -// { -// $sequence = "..."; -// echo $sequence; -// } - -// mysql_close($sql); -// } -// else if($action == 1) // "Set partie" -// { -// // Requête sql d'ajout d'informations (et calcul de résultat). -// $req = "..."; - -// $sql = sqlConnect(); -// $resp = mysql_query($req); - -// if(mysql_num_rows($resp) == 0) -// echo mysql_error(); -// else -// { -// $sequence = "..."; -// echo $sequence; -// } - -// mysql_close($sql); -// } -// else if($action == 2) -// { - -// } -// else if($action == 3) -// { - -// } -// else if($action == 4) -// { - -// } -// else -// die("Commande inconnue"); - + cg_insert($centerEid, $cloud); + + var_dump($cloud); + exit;} + +create_game(10); +echo 'ok'; + +// // Sinon tout est bon on effectu l'opération correspondant à la commande passée. +// if($action == 0) // "Get partie" +// { +// // Requête sql de création de partie. +// $req = "..."; + +// $sql = sqlConnect(); +// $resp = mysql_query($req); + +// if(mysql_num_rows($resp) == 0) +// echo mysql_error(); +// else +// { +// $sequence = "..."; +// echo $sequence; +// } + +// mysql_close($sql); +// } +// else if($action == 1) // "Set partie" +// { +// // Requête sql d'ajout d'informations (et calcul de résultat). +// $req = "..."; + +// $sql = sqlConnect(); +// $resp = mysql_query($req); + +// if(mysql_num_rows($resp) == 0) +// echo mysql_error(); +// else +// { +// $sequence = "..."; +// echo $sequence; +// } + +// mysql_close($sql); +// } +// else if($action == 2) +// { + +// } +// else if($action == 3) +// { + +// } +// else if($action == 4) +// { + +// } +// else +// die("Commande inconnue"); + ?> From f18de3c2932b3b38bb48e1845e23d20c0119f416 Mon Sep 17 00:00:00 2001 From: Bertrand BRUN Date: Wed, 2 Feb 2011 20:09:26 +0100 Subject: [PATCH 08/13] Correction de la taille des mots dans le premier jeu --- code/PtiClic/res/layout/game.xml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/code/PtiClic/res/layout/game.xml b/code/PtiClic/res/layout/game.xml index fc2de73..4934c79 100644 --- a/code/PtiClic/res/layout/game.xml +++ b/code/PtiClic/res/layout/game.xml @@ -3,17 +3,17 @@ android:layout_height="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> - + + android:textStyle="bold" android:gravity="center" android:textSize="30dip"> + android:textStyle="bold" android:gravity="center" android:textSize="20dip"> @@ -32,8 +32,8 @@ android:layout_weight="1" android:layout_gravity="bottom">