1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
   |  
 
	import java.io.IOException;
	import java.lang.reflect.Method;
	import java.util.TreeMap;
	import java.util.Vector;
	import java.io.FileWriter;
	import java.io.IOException;
	import java.io.PrintWriter;
 
 
	public class Strategies {
 
		public TreeMap<String, Integer> ponderation;
 
		/* on initialise les valeurs */
		public void initialise_ponderation()
		{TreeMap<String,Integer> ponderation= new TreeMap<String,Integer>();
		ponderation.put("cooperation", 50);
		ponderation.put("competition", 10);
		ponderation.put("trahison", 60);
		ponderation.put("trahi", 0);	
		}
 
		/* pour le moment, seulement deux strategies. historique et pos seront utilisés plus tard*/
		public int gentil(Vector historique , int pos)
		{	
			return 1;
		}		
		public int mechant(Vector historique , int pos)
		{	
			return 0;
		}
 
 
 
 
		public void match(String strat1, String strat2,Vector historique) throws Exception
		{
			TreeMap resultat= new TreeMap<String,Integer>();
 
 
 
			/* on initialise le vecteur qui donnera les résultats */
			resultat.put(strat1, 0);
			resultat.put(strat2, 0);
 
 
 
			/* Voila la partie interessante*/
 
 
			Strategies entity = new Strategies();
 
			Class classTypes [] = {(new String()).getClass()};
			Method getMethod = entity.getClass().getMethod(strat1, classTypes); 
 
			String arg1[] = {"historique","0"};
			int choix1 = (Integer) (getMethod.invoke(entity, arg1));
 
			String arg2[] = {"historique","1"};
			int choix2 = (Integer) (getMethod.invoke(entity, arg2));
 
 
 
 
 
 
 
 
			/* on attribue les points selon les strategies*/
 
			if ((choix1==0)&(choix2==0)) 
			{resultat.put(strat1,ponderation.get("cooperation"));
			 resultat.put(strat2,ponderation.get("cooperation"));		
			}
			if ((choix1==0)&(choix2==1)) 
			{resultat.put(strat1,ponderation.get("trahi"));
			 resultat.put(strat2,ponderation.get("trahison"));		
			}
			if ((choix1==1)&(choix2==0)) 
			{resultat.put(strat1,ponderation.get("trahison"));
			 resultat.put(strat2,ponderation.get("trahi"));		
			}
			if ((choix1==1)&(choix2==1)) 
			{resultat.put(strat1,ponderation.get("competition"));
			 resultat.put(strat2,ponderation.get("competition"));		
			}
 
 
			/* on ecrit le résultat*/
			PrintWriter ecrire = new PrintWriter(new FileWriter("resultat.txt"));
			ecrire.print(resultat.entrySet());
			ecrire.close();
 
 
		}
 
		public static void main (String[] args) throws Exception{
			Strategies entity= new Strategies() ;
			Vector historique= new Vector();
			entity.initialise_ponderation();
			entity.match("mechant", "gentil", historique);
 
		}
 
 
} |