Merge branch 'master' of https://github.com/jsmaniac/2011-m1s2-ter
Conflicts: code/serveur/php/function.php code/serveur/php/pticlic.php
3
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
.DS_Store
|
||||
.DS_Store
|
||||
code.zip
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
<activity android:name=".games.BaseGame" android:screenOrientation="portrait"></activity>
|
||||
<activity android:label="Information" android:name=".Information" android:screenOrientation="portrait"></activity>
|
||||
<activity android:name=".Score" android:label="Score" android:screenOrientation="portrait"></activity>
|
||||
<activity android:name=".FrontPage" android:screenOrientation="portrait"></activity>
|
||||
</application>
|
||||
|
||||
|
||||
|
|
Before Width: | Height: | Size: 9.1 KiB After Width: | Height: | Size: 9.1 KiB |
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 7.6 KiB |
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 9.0 KiB |
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 96 KiB |
Before Width: | Height: | Size: 7.4 KiB After Width: | Height: | Size: 7.4 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.3 KiB |
BIN
code/PtiClic/res/drawable-ldpi/splash.png
Normal file
After Width: | Height: | Size: 96 KiB |
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.9 KiB |
BIN
code/PtiClic/res/drawable-mdpi/splash.png
Normal file
After Width: | Height: | Size: 96 KiB |
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
43
code/PtiClic/res/layout/frontpage.xml
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent" android:layout_height="fill_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView android:text="@string/app_name" android:id="@+id/logo"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content"
|
||||
android:textSize="50px" android:layout_weight="1" />
|
||||
|
||||
<RelativeLayout android:layout_height="wrap_content"
|
||||
android:id="@+id/RelativeLayout01" android:layout_width="wrap_content"
|
||||
android:layout_gravity="bottom|center_horizontal">
|
||||
|
||||
<ImageView android:layout_height="wrap_content"
|
||||
android:text="@string/play_label" android:layout_width="wrap_content"
|
||||
android:id="@+id/play" android:clickable="true" android:padding="30dip" android:src="@drawable/mode_normal"/>
|
||||
|
||||
<ImageView android:src="@drawable/config" android:layout_height="wrap_content" android:id="@+id/prefs"
|
||||
android:layout_width="wrap_content" android:layout_below="@+id/play"
|
||||
android:layout_alignLeft="@+id/play" android:layout_alignRight="@+id/play" android:padding="30dip"></ImageView>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout android:id="@+id/LinearLayout01"
|
||||
android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical" android:layout_weight="1">
|
||||
|
||||
<TextView android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent" android:textStyle="bold"
|
||||
android:gravity="center_horizontal" android:text="@+id/login"
|
||||
android:id="@+id/login"></TextView>
|
||||
<ImageView android:layout_height="wrap_content" android:id="@+id/infoButton"
|
||||
android:layout_width="wrap_content" android:layout_gravity="right" android:layout_weight="5"
|
||||
android:clickable="true" android:src="@drawable/aide"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -3,17 +3,17 @@
|
|||
android:layout_height="fill_parent" android:orientation="vertical"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<LinearLayout android:id="@+id/widget40"
|
||||
android:layout_width="fill_parent" android:layout_height="fill_parent"
|
||||
android:orientation="vertical" android:layout_weight="1">
|
||||
<LinearLayout android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" android:orientation="vertical"
|
||||
android:layout_weight="1">
|
||||
|
||||
<TextView android:id="@+id/mainWord" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:text="mainWord"
|
||||
android:textSize="30sp" android:textStyle="bold" android:gravity="center">
|
||||
android:textStyle="bold" android:gravity="center" android:textSize="30dip">
|
||||
</TextView>
|
||||
<TextView android:id="@+id/currentWord" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:text="currentWord"
|
||||
android:textStyle="bold" android:gravity="center">
|
||||
android:textStyle="bold" android:gravity="center" android:textSize="20dip">
|
||||
</TextView>
|
||||
|
||||
|
||||
|
@ -32,8 +32,8 @@
|
|||
android:layout_weight="1" android:layout_gravity="bottom">
|
||||
</Button>
|
||||
<Button android:id="@+id/trash" android:text="trash"
|
||||
android:layout_height="wrap_content" android:layout_width="fill_parent"
|
||||
android:layout_weight="1" android:layout_gravity="bottom">
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_weight="1" android:layout_gravity="bottom" android:layout_height="fill_parent">
|
||||
</Button>
|
||||
<Button android:id="@+id/relation3" android:text="relation3"
|
||||
android:layout_height="wrap_content" android:layout_width="fill_parent"
|
||||
|
|
|
@ -1,46 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent" android:layout_height="fill_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView android:text="@string/app_name" android:id="@+id/logo"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content"
|
||||
android:textSize="50px" android:layout_weight="1" />
|
||||
|
||||
<RelativeLayout android:layout_height="wrap_content"
|
||||
android:id="@+id/RelativeLayout01" android:layout_width="wrap_content"
|
||||
android:layout_gravity="bottom|center_horizontal">
|
||||
|
||||
<ImageView android:layout_height="wrap_content"
|
||||
android:text="@string/play_label" android:layout_width="wrap_content"
|
||||
android:id="@+id/play" android:src="@drawable/mode_chrono"
|
||||
android:clickable="true" android:padding="40dip" />
|
||||
|
||||
<ImageView android:src="@drawable/config" android:padding="40dip"
|
||||
android:layout_height="wrap_content" android:id="@+id/prefs"
|
||||
android:layout_width="wrap_content" android:layout_below="@+id/play"
|
||||
android:layout_alignLeft="@+id/play" android:layout_alignRight="@+id/play"></ImageView>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout android:id="@+id/LinearLayout01"
|
||||
android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical" android:layout_weight="1">
|
||||
|
||||
<TextView android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent" android:textStyle="bold"
|
||||
android:gravity="center_horizontal" android:text="@+id/login"
|
||||
android:id="@+id/login"></TextView>
|
||||
<ImageView android:layout_height="wrap_content" android:id="@+id/infoButton"
|
||||
android:layout_width="wrap_content" android:src="@android:drawable/ic_dialog_info"
|
||||
android:layout_gravity="right" android:layout_weight="5"
|
||||
android:clickable="true" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<ImageView android:id="@+id/ImageView01" android:src="@drawable/splash" android:layout_gravity="center_vertical|center_horizontal|center" android:layout_width="fill_parent" android:layout_height="fill_parent"></ImageView>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -10,17 +10,21 @@
|
|||
</style>
|
||||
<body style="margin: 0; padding: 0" bgcolor="Black">
|
||||
<center>
|
||||
<p>
|
||||
PtiClic a ete concu et developpe par Mathieu Lafourcade (LIRMM - Universite Montpellier 3) et Virginie Zampa (LIDILEM - Universite Stendhal Grenoble 3)<br />
|
||||
</p><p>
|
||||
Merci en particulier a (en vrac) farfadet, mehdi (mym), alain joubert, gilles serasset (krado)...<br />
|
||||
</p><p>
|
||||
Pticlic n'est pas exempt de bugs - si vous en rencontrez un, pourriez-vous le signaler a l'administrateur ?<br />
|
||||
</p><p>
|
||||
Mathieu Lafourcade - Administrateur - <a mailto:"pticlic.android.beta@gmail.com">contact</a><br />
|
||||
</p><p>
|
||||
Derniere mise a jour : fevrier 2008
|
||||
</p>
|
||||
|
||||
<p>PtiClic a été conçu et développé par Mathieu Lafourcade (LIRMM - Université Montpellier 3)
|
||||
et Virginie Zampa (LIDILEM - Université Stendhal Grenoble 3)</p>
|
||||
|
||||
<p>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.</p>
|
||||
|
||||
<p>Cette version du PtiClic est une version Alpha. Elle n'est pas exempte de bogues.</p>
|
||||
<p>Si vous souhaitez participer au projet en tant que Bêta-testeur,
|
||||
rendez-vous sur le site http://www... pour vous y inscrire.</p>
|
||||
<p>Si vous souhaitez signaler des bogues ou de nous fournir des commentaires, vous pouvez
|
||||
nous contacter sur pticlic.android.beta@gmail.com</p>
|
||||
|
||||
|
||||
</center>
|
||||
</body>
|
||||
</html>
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
<PreferenceCategory android:title="Connexion">
|
||||
|
||||
<EditTextPreference android:title="Login" android:key="login" android:summary=""/>
|
||||
<EditTextPreference android:title="Mot de Passe" android:key="passwd"/>
|
||||
<EditTextPreference android:title="Login" android:key="login" android:summary="" android:dialogTitle="Entrer nom utilisateur"/>
|
||||
<EditTextPreference android:title="Mot de Passe" android:key="passwd" android:dialogTitle="Entrer mot de passe" android:password="true"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="Debug">
|
||||
|
|
57
code/PtiClic/src/org/pticlic/FrontPage.java
Normal file
|
@ -0,0 +1,57 @@
|
|||
package org.pticlic;
|
||||
|
||||
import org.pticlic.games.BaseGame;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class FrontPage extends Activity implements OnClickListener{
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.frontpage);
|
||||
|
||||
// Écoute des clics sur les différents boutons
|
||||
((ImageView)findViewById(R.id.prefs)).setOnClickListener(this);
|
||||
((ImageView)findViewById(R.id.play)).setOnClickListener(this);
|
||||
((ImageView)findViewById(R.id.infoButton)).setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
// On récupère le nom du joueur des préférences.
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String loginPref = sp.getString("login", "joueur");
|
||||
// On l'ajoute dans le TextView prévu à cet effet
|
||||
((TextView)findViewById(R.id.login)).setText("Login : " + loginPref);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.view.View.OnClickListener#onClick(android.view.View)
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case (R.id.prefs) : startActivity(new Intent(this, Preference.class)); break;
|
||||
case (R.id.play) : startActivity(new Intent(this, BaseGame.class)); break;
|
||||
case (R.id.infoButton) : startActivity(new Intent(this, Information.class)); break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,51 +1,40 @@
|
|||
package org.pticlic;
|
||||
|
||||
import org.pticlic.games.BaseGame;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public class Main extends Activity implements OnClickListener {
|
||||
public class Main extends Activity {
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
// Écoute des clics sur les différents boutons
|
||||
((ImageView)findViewById(R.id.prefs)).setOnClickListener(this);
|
||||
((ImageView)findViewById(R.id.play)).setOnClickListener(this);
|
||||
((ImageView)findViewById(R.id.infoButton)).setOnClickListener(this);
|
||||
|
||||
// On récupère le nom du joueur des préférences.
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String loginPref = sp.getString("login", "joueur");
|
||||
// On l'ajoute dans le TextView prévu à cet effet
|
||||
((TextView)findViewById(R.id.login)).setText("Login : " + loginPref);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.view.View.OnClickListener#onClick(android.view.View)
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case (R.id.prefs) : startActivity(new Intent(this, Preference.class)); break;
|
||||
case (R.id.play) : startActivity(new Intent(this, BaseGame.class)); break;
|
||||
case (R.id.infoButton) : startActivity(new Intent(this, Information.class)); break;
|
||||
}
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
startActivityForResult(new Intent(this, FrontPage.class), 0x0);
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
System.exit(0);
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -66,6 +65,5 @@ public class Score extends Activity implements OnClickListener{
|
|||
if (v.getId()==R.id.saw) {
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@ 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;
|
||||
import org.pticlic.model.Relation;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
|
@ -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
|
||||
|
@ -54,7 +54,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);
|
||||
|
@ -62,9 +62,9 @@ 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();
|
||||
|
||||
// Boutons des relations
|
||||
|
@ -72,7 +72,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 +84,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 +153,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 +163,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;
|
||||
|
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package org.pticlic.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Bertrand BRUN
|
||||
*
|
||||
* Cette classe represente une partie joue.
|
||||
* Elle sera envoyer au serveur pour que celui-ci
|
||||
* puisse calculer le score obtenue.
|
||||
*
|
||||
*/
|
||||
public class GamePlayed implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private ArrayList<CharSequence> relation1;
|
||||
private ArrayList<CharSequence> relation2;
|
||||
private ArrayList<CharSequence> relation3;
|
||||
private ArrayList<CharSequence> relation4;
|
||||
private ArrayList<CharSequence> poubelle;
|
||||
private DownloadedGame game;
|
||||
|
||||
public GamePlayed() {
|
||||
relation1 = new ArrayList<CharSequence>();
|
||||
relation2 = new ArrayList<CharSequence>();
|
||||
relation3 = new ArrayList<CharSequence>();
|
||||
relation4 = new ArrayList<CharSequence>();
|
||||
poubelle = new ArrayList<CharSequence>();
|
||||
}
|
||||
|
||||
public void setGame(DownloadedGame game) {
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
public DownloadedGame getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
public void add(int relation, CharSequence 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;
|
||||
}
|
||||
}
|
||||
}
|
85
code/PtiClic/src/org/pticlic/model/Match.java
Normal file
|
@ -0,0 +1,85 @@
|
|||
package org.pticlic.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Bertrand BRUN
|
||||
*
|
||||
* Cette classe represente une partie joue.
|
||||
* Elle sera envoyer au serveur pour que celui-ci
|
||||
* puisse calculer le score obtenue.
|
||||
*
|
||||
*/
|
||||
public class Match implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private ArrayList<Integer> relation1;
|
||||
private ArrayList<Integer> relation2;
|
||||
private ArrayList<Integer> relation3;
|
||||
private ArrayList<Integer> relation4;
|
||||
private ArrayList<Integer> trash;
|
||||
private DownloadedGame game;
|
||||
|
||||
public Match() {
|
||||
relation1 = new ArrayList<Integer>();
|
||||
relation2 = new ArrayList<Integer>();
|
||||
relation3 = new ArrayList<Integer>();
|
||||
relation4 = new ArrayList<Integer>();
|
||||
trash = new ArrayList<Integer>();
|
||||
}
|
||||
|
||||
public void setGame(DownloadedGame game) {
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
public DownloadedGame getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
public void add(int relation, int 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: trash.add(word); break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the relation1
|
||||
*/
|
||||
public ArrayList<Integer> getRelation1() {
|
||||
return relation1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the relation2
|
||||
*/
|
||||
public ArrayList<Integer> getRelation2() {
|
||||
return relation2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the relation3
|
||||
*/
|
||||
public ArrayList<Integer> getRelation3() {
|
||||
return relation3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the relation4
|
||||
*/
|
||||
public ArrayList<Integer> getRelation4() {
|
||||
return relation4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the trash
|
||||
*/
|
||||
public ArrayList<Integer> getTrash() {
|
||||
return trash;
|
||||
}
|
||||
|
||||
}
|
|
@ -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()) {
|
||||
|
@ -82,13 +82,13 @@ public class Network {
|
|||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
|
||||
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,16 +130,16 @@ 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.
|
||||
* @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();
|
||||
|
@ -147,16 +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 (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"));
|
||||
|
||||
score = gson.fromJson(reader, TotalScore.class);
|
||||
|
||||
// TODO : A changer lorsque je serais exactement ce que renvoie le serveur.
|
||||
score = gson.fromJson(reader, DownloadedScore.class);
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
return score;
|
||||
}
|
||||
|
|
45
code/PtiClic/src/org/pticlic/model/TotalScore.java
Normal file
|
@ -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 + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
62
code/PtiClic/src/org/pticlic/model/WordScore.java
Normal file
|
@ -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 + "]";
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 7.7 KiB |
Before Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 5.4 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 7.7 KiB |
2
code/serveur/.gitignore
vendored
|
@ -1,3 +1,3 @@
|
|||
01042011-LEXICALNET-JEUXDEMOTS-FR-NOHTML.txt
|
||||
*-LEXICALNET-JEUXDEMOTS-FR-NOHTML.txt
|
||||
db
|
||||
sql
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
#!/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
|
||||
echo >&2
|
||||
|
||||
# Played_game(type) : 0 => partie de référence, 1 => joueur
|
||||
|
||||
cat <<EOF
|
||||
begin transaction;
|
||||
create table node(eid integer primary key autoincrement, name, type, weight);
|
||||
|
@ -12,9 +16,10 @@ create table relation(rid integer primary key autoincrement, start, end, type, w
|
|||
create table type_node(name, num);
|
||||
create table type_relation(name, num, extended_name, info);
|
||||
create table user(login primary key, mail, hash_passwd);
|
||||
create table game(gid integer primary key autoincrement, eid_central_word, relation_1, relation_2, relation_3, relation_4, reference_played_game);
|
||||
create table game_cloud(gid, num, difficulty, eid_word);
|
||||
create table played_game(gid, type, num, relation, weight);
|
||||
create table game(gid integer primary key autoincrement, eid_central_word, relation_1, relation_2, difficulty);
|
||||
create table game_cloud(gid, num, difficulty, eid_word, totalWeight, probaR1, probaR2, probaR0, probaTrash);
|
||||
create table played_game(pgid integer primary key autoincrement, gid, login);
|
||||
create table played_game_cloud(pgid, gid, type, num, relation, weight, score);
|
||||
EOF
|
||||
|
||||
# tr : pour virer le CRLF qui traîne
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
/** fichier de configuration */
|
||||
|
||||
// Général
|
||||
|
||||
// Quelques fonctions utiles.
|
||||
// include("function.php");
|
||||
|
||||
?>
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**Ce fichier définit un certain nombre de fonctions utiles */
|
||||
|
||||
// Connexion à la base de données.
|
||||
function sqlConnect()
|
||||
{
|
||||
global $sql_server, $sql_login, $sql_pass, $sql_bdd;
|
||||
//connexion au serveur
|
||||
$linkid = @mysql_connect($sql_server,$sql_login,$sql_pass) or die ("Erreur lors de la connection au serveur MySQL !");
|
||||
//selection de la base
|
||||
@mysql_select_db($sql_bdd,$linkid) or die("Impossible de selectionner la base de données\n<br>\nVoici l'erreur renvoyée par le serveur MySQL :\n<br>\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)
|
||||
{
|
||||
|
||||
}
|
||||
?>
|
|
@ -1,3 +1,4 @@
|
|||
<<<<<<< HEAD
|
||||
<?php
|
||||
// Requête : http://serveur/pticlic.php?action=getparties&nb=2&mode=normal&user=foo&passwd=bar
|
||||
|
||||
|
@ -218,3 +219,250 @@ function selectGame($gId)
|
|||
// die("Commande inconnue");
|
||||
|
||||
?>
|
||||
=======
|
||||
<?php
|
||||
// Requête : http://serveur/pticlic.php?action=getparties&nb=2&mode=normal&user=foo&passwd=bar
|
||||
|
||||
$do_initdb = false;
|
||||
$email_admin = ''; // Adresse e-mail Administrateur.
|
||||
|
||||
$SQL_DBNAME = (dirname(__FILE__) . "/db");
|
||||
|
||||
function mDie($err,$msg)
|
||||
{
|
||||
echo "{ error:".json_encode("".$err).", msg:".json_encode("".$msg)."}";
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$db = new SQLite3('db')) {
|
||||
mDie(1,"Erreur lors de l'ouverture de la base de données SQLite3");
|
||||
}
|
||||
|
||||
function initdb() {
|
||||
global $db;
|
||||
$db->exec("insert into user(login, mail, hash_passwd) values('foo', 'foo@isp.com', '".md5('bar')."');");
|
||||
}
|
||||
|
||||
if ($do_initdb) 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'=>40, 'd'=>1, 's'=>"select end as eid, type = $r1 as r1, type = $r2 as r2, 0 as r0, 0 as trash 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'=>40, 'd'=>2, 's'=>"select end as eid, 0.25 as r1, 0.25 as r2, 0.5 as r0, 0 as trash from relation where start = $centerEid and type = 0 order by random();"),
|
||||
// Voisins 1 saut via les autres relations
|
||||
// TODO ! certains de ces select pourraient renvoyer des mots de types systèmes (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001), il faut les éliminer.
|
||||
array('w'=>20, 'd'=>3, 's'=>"select end as eid, 0.1 as r1, 0.1 as r2, 0.8 as r0, 0 as trash 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'=>30, 'd'=>3, 's'=>"select B.end as eid, ((A.type = $r1) + (B.type = $r1)) / 3 as r1, ((A.type = $r2) + (B.type = $r2)) / 3 as r2, 1/6 as r0, 1/6 as trash 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'=>20, 'd'=>5, 's'=>"select B.end as eid, (A.type = $r1) * 0.75 as r1, (A.type = $r2) * 0.75 as r2, 0.25 as r0, 0 as trash 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'=>20, 'd'=>6, 's'=>"select B.end as eid, (B.type = $r1) * 0.75 as r1, (B.type = $r2) * 0.75 as r2, 0.25 as r0, 0 as trash 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, 0.3 as r0, 0.5 as trash 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, 0.2 as r0, 0.6 as trash 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'=>5, 'd'=>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()) {
|
||||
$i++;
|
||||
$sources[$k]['rsSize']++;
|
||||
}
|
||||
} else {
|
||||
$sources[$k]['resultSet'] = array();
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$sources[$k]['resultSet'][] = array('eid'=>random_node(), 'r1'=>0, 'r2'=>0, 'r0'=>0, 'trash'=>1);
|
||||
$sources[$k]['rsSize']++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return array($sources, $sumWeights);
|
||||
}
|
||||
|
||||
function cg_choose_relations() {
|
||||
$relations = array(5, 7, 9, 10, /* Pas d'icônes pour celles-ci. */ 13, 14, 22);
|
||||
$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;
|
||||
$totalDifficulty = 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'];
|
||||
$srck = null;
|
||||
foreach ($sources as $k => $x) {
|
||||
$sumw += $x['w'];
|
||||
if ($rands < $sumw) {
|
||||
$src = $x;
|
||||
$srck = $k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($src['rsPos'] >= $src['rsSize']) {
|
||||
$nbFailed++;
|
||||
if ($srck !== null) {
|
||||
$sumWeights -= $src['w'];
|
||||
unset($sources[$srck]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$res = $src['resultSet'][$src['rsPos']++];
|
||||
if (in_array($res['eid'], $cloud)) {
|
||||
$nbFailed++;
|
||||
continue;
|
||||
}
|
||||
// position dans le nuage, difficulté, eid, probaR1, probaR2
|
||||
$totalDifficulty += $src['d'];
|
||||
$cloud[$i] = array('pos'=>$i++, 'd'=>$src['d'], 'eid'=>$res['eid'], 'probaR1'=>$res['r1'], 'probaR2'=>$res['r2'], 'probaR0'=>$res['r0'], 'probaTrash'=>$res['trash']);
|
||||
}
|
||||
$res = $sources['rand']['resultSet'][0];
|
||||
while ($i < $cloudSize) {
|
||||
$totalDifficulty += $sources['rand']['d'];
|
||||
$cloud[$i] = array('pos'=>$i++, 'd'=>$sources['rand']['d'], 'eid'=>random_node(), 'probaR1'=>$res['r1'], 'probaR2'=>$res['r2'], 'probaR0'=>$res['r0'], 'probaTrash'=>$res['trash']);
|
||||
}
|
||||
return array($cloud, $totalDifficulty);
|
||||
}
|
||||
|
||||
function cg_insert($centerEid, $cloud, $r1, $r2, $totalDifficulty) {
|
||||
// Insère dans la base une partie avec le mot central $centerEid, le nuage $cloud et les relations $r1 et $r2
|
||||
global $db;
|
||||
$db->exec("begin transaction;");
|
||||
$db->exec("insert into game(gid, eid_central_word, relation_1, relation_2, difficulty) values (null, $centerEid, $r1, $r2, $totalDifficulty);");
|
||||
$gid = $db->lastInsertRowID();
|
||||
$db->exec("insert into played_game(pgid, gid, login) values (null, $gid, null);");
|
||||
$pgid = $db->lastInsertRowID();
|
||||
foreach ($cloud as $c) {
|
||||
$db->exec("insert into game_cloud(gid, num, difficulty, eid_word, totalWeight, probaR1, probaR2, probaR0, probaTrash) values($gid, ".$c['pos'].", ".$c['d'].", ".$c['eid'].", 2, ".$c['probaR1'].", ".$c['probaR2'].", ".$c['probaR0'].", ".$c['probaTrash'].");");
|
||||
$db->exec("insert into played_game_cloud(pgid, gid, type, num, relation, weight, score) values($pgid, $gid, 0, ".$c['pos'].", $r1, ".$c['probaR1'].", 0);");
|
||||
$db->exec("insert into played_game_cloud(pgid, gid, type, num, relation, weight, score) values($pgid, $gid, 0, ".$c['pos'].", $r1, ".$c['probaR1'].", 0);");
|
||||
}
|
||||
$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];
|
||||
$cloud = cg_build_cloud($cloudSize, $sources, $sumWeights); $totalDifficulty = $cloud[1]; $cloud = $cloud[0];
|
||||
cg_insert($centerEid, $cloud, $r1, $r2, $totalDifficulty);
|
||||
}
|
||||
|
||||
//create_game(10);
|
||||
|
||||
function random_game() {
|
||||
global $db;
|
||||
return $db->querySingle("select gid from game where gid = (abs(random()) % (select max(gid) from game))+1 or gid = (select max(gid) from game where gid > 0) order by gid limit 1;");
|
||||
}
|
||||
|
||||
function game2json($game_id) {
|
||||
global $db;
|
||||
// TODO Yoann : faire des tests d'erreur pour ces select ?
|
||||
$game = $db->query("select gid, (select name from node where eid = eid_central_word) as name_central_word, eid_central_word, relation_1, relation_2 from game where gid = ".$game_id.";");
|
||||
$game = $game->fetchArray();
|
||||
echo "{id:".$game['gid'].",cat1:".$game['relation_1'].",cat2:".$game['relation_2'].",cat3:0,cat4:-1,";
|
||||
echo "center:{id:".$game['eid_central_word'].",name:".json_encode("".$game['name_central_word'])."},";
|
||||
echo "cloudsize:10,cloud:["; // TODO ! compter dynamiquement.
|
||||
|
||||
$res = $db->query("select eid_word,(select name from node where eid=eid_word) as name_word from game_cloud where gid = ".$game['gid'].";");
|
||||
while ($x = $res->fetchArray()) {
|
||||
echo "{id:".$x['eid_word'].",name:".$x['name_word']."}\n";
|
||||
}
|
||||
echo "]}";
|
||||
}
|
||||
|
||||
function main() {
|
||||
// Sinon tout est bon on effectu l'opération correspondant à la commande passée.
|
||||
if($action == 0) { // "Get partie"
|
||||
if(!isset($_GET['nb']) || !isset($_GET['mode']))
|
||||
mDie(2,"La requête est incomplète");
|
||||
$nbGames = intval($_GET['nb']);
|
||||
|
||||
echo "[";
|
||||
for ($i=0; $i < $nbGames; $i) {
|
||||
game2json(random_game());
|
||||
if ((++$i) < $nbGames) {
|
||||
echo ",";
|
||||
}
|
||||
}
|
||||
echo "]";
|
||||
} else if($action == 1) { // "Set partie"
|
||||
// Requête sql d'ajout d'informations (et calcul de résultat).
|
||||
// TODO : nettoyer, finir
|
||||
$gid = $_GET['gid']; // TODO : vérifier qu'on a bien distribué cette partie à cet utilisateur, et qu'il n'y a pas déjà répondu (répercuter ça sur le random_game).
|
||||
$userReputation = 5; // TODO : un nombre entre 0 et 5 environ. Par ex. log(pointsUtilisateur) est un bon choix.
|
||||
$db->exec("begin transaction;");
|
||||
$db->exec("insert into played_game(pgid, gid, login) values (null, $gid, null);");
|
||||
$pgid = $db->lastInsertRowID();
|
||||
for ($i=0; $i < 10; $i++) {
|
||||
$x = $_GET['$i'];
|
||||
// TODO : calculer le score. Score = proba[réponse de l'utilisateur]*coeff - proba[autres reponses]*coeff
|
||||
// TODO : adapter le score en fonction de la réputation de l'utilisateur (plus quand il est jeune, pour le motiver, par ex. avec un terme constant qu'on ajoute).
|
||||
$score = 1;
|
||||
$db->exec("insert into played_game_cloud(pgid, gid, type, num, relation, weight, score) values($pgid, $gid, 1, ".$c['pos'].", $r1, ".($x*$userReputation).", ".$score.");");
|
||||
// TODO : game_cloud(probaR_x_) += $réputationJoueur * $coeff
|
||||
// TODO : game_cloud(totalWeight) += $réputationJoueur * $coeff (NOTE : même coeff que pour game_cloud(probaR_x_))
|
||||
}
|
||||
$db->exec("commit;");
|
||||
// On renvoie une nouvelle partie pour garder le client toujours bien alimenté.
|
||||
game2json(random_game());
|
||||
} else {
|
||||
die("Commande inconnue");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
>>>>>>> c9d82a5818ec8da08c3d9ce6038a2ad59d9bf9af
|
||||
|
|
|
@ -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
|
||||
|
|