Skip to content
Snippets Groups Projects

Partenaires & Co

Merged SCHLUMBERGER CLAUDE requested to merge schlumberger/UniversityTycoon:master into master
Compare and
6 files
+ 69
53
Preferences
Compare changes
Files
6
@@ -9,13 +9,12 @@ import java.util.Random;
import fr.universitytycoon.Instance;
public class Partners {
private int nextId=1;
private int nextOfferId=1;
private ArrayList<Partner> listPartners=new ArrayList<Partner>();
private ArrayList<Partner> listOffers=new ArrayList<Partner>();
public int offerPartnership(String nom, long value, double insertion) {
public void offerPartnership(String nom, long value, double insertion) {
Partner p=new Partner(nextOfferId,nom,value,insertion);
boolean add=true;
for(Partner a : listOffers) {
@@ -35,7 +34,6 @@ public class Partners {
}
listOffers.add(p);
nextOfferId++;
return nextOfferId-1;
}
public Partner getOffer(int id) {
@@ -66,10 +64,10 @@ public class Partners {
public int signPartnership(Partner p) {
listOffers.remove(p);
p.setId(nextId);
nextId++;
p.setId(nextOfferId);
nextOfferId++;
listPartners.add(p);
return nextId-1;
return nextOfferId-1;
}
public Partner getPartner(int id) {
@@ -85,36 +83,35 @@ public class Partners {
return new ArrayList<Partner>(this.listPartners);
}
public int generateOffer() {
double chanceOffer=(double)(Instance.getInstance().getGame().get().getUniversity().getStudents().getInsertion()+Instance.getInstance().getGame().get().getUniversity().getResearches().getResearchScore())/2;
double randValue=Math.random();
int res=-1;
if(randValue<chanceOffer) {
public void generateOffer() {
// Vérifie si l'université est éligible pour un partenaire
int scoreRecherche = Math.round((float)Math.floor(Instance.getInstance().getGame().get().getUniversity().getResearches().getResearchScore()));
int niveauPartenaires = scoreRecherche/5;
while(nextOfferId <= niveauPartenaires)
{
// Lecture du fichier csv
InputStreamReader reader = new InputStreamReader(Instance.class.getResourceAsStream("/fr/universitytycoon/resources/randomPartner.csv"));
BufferedReader br = new BufferedReader(reader);
String[] lignePartenaire = null;
try {
String[] args;
ArrayList<String[]> rr= new ArrayList<String[]>();
int count=0;
for (String line = br.readLine(); line != null; line = br.readLine()) {
rr.add(line.split("/"));
count++;
for (String line = br.readLine(); line != null; line = br.readLine())
{
String[] curs = line.split("/");
if (Integer.parseInt(curs[0]) == nextOfferId)
lignePartenaire = curs;
}
Random rand=new Random();
int randLine=rand.nextInt(count);
args=rr.get(randLine);
try {
res = offerPartnership(args[0],Long.parseLong(args[1]),Double.parseDouble(args[2]));
}
catch(IllegalArgumentException e) {
}
} catch (IOException e) {
e.printStackTrace();
if (lignePartenaire == null)
throw new Exception("Aucune ligne n°"+ nextOfferId);
offerPartnership(lignePartenaire[1], Long.parseLong(lignePartenaire[2]), 0.05);
}
catch (Exception e)
{
System.out.println("Lecture CSV Partenaires : lecture ligne "+ nextOfferId +" échouée : " + e.getMessage());
}
}
System.out.println(listOffers);
return res;
}
}