Ver código fonte

ajout fonction pondération des événements

Clément Krebs 6 anos atrás
pai
commit
046f7febb9
4 arquivos alterados com 52 adições e 95 exclusões
  1. 23 14
      src/control/ctrlEvents.js
  2. 20 10
      src/model/events.js
  3. 9 0
      src/model/game.js
  4. 0 71
      src/model/indicators.js

+ 23 - 14
src/control/ctrlEvents.js

@@ -15,7 +15,7 @@ function resetPossibleEvents() {
 function addPossibleEvent(pEvent) {
   possibleEvents.push(
     {
-      pEvent : pEvent,
+      event : pEvent,
       weight : getEventWeight(pEvent)
     }
   );
@@ -23,24 +23,25 @@ function addPossibleEvent(pEvent) {
 
 // à faire
 function getEventWeight(pEvent) {
-  let weight = 1;
-  return weight;
+  let eventWeight;
+  for (let i = 0; i < pEvent.treshold.length; i++) {
+    eventWeight *= 1 - pEvent.coefficient[i] * (1 - ( indicators[i] / pEvent.treshold[i])) ** (1/2) ;
+  }
+  return eventWeight;
 }
 
 
 function testPossibleEvent(pEvent) {
-  if (
-    (clergy.wealth <= pEvent.clergy.wealth) &&
-    (clergy.influence <= pEvent.clergy.influence) &&
-    (nobility.wealth <= pEvent.nobility.wealth) &&
-    (nobility.influence <= pEvent.nobility.influence) &&
-    (nobility.army <= pEvent.nobility.army) &&
-    (people.wealth <= pEvent.people.wealth) &&
-    (people.wellBeing <= pEvent.people.wellBeing)
-  ) {
-    return true;
+  let test = true;
+  let i = 0;
+  while ((test) && (i < indicators.length)) {
+    if (indicators[i] <= pEvent.treshold[i]) {
+      test = false;
+    }
+    i++
   }
-  return false;
+
+  return test;
 }
 
 
@@ -55,3 +56,11 @@ function allPossibleEvents() {
     }
   }
 }
+
+function getTotalWeight() {
+  let totalWeight;
+  for (let i = 0; i < possibleEvents.length; i++) {
+    totalWeight += possibleEvents[i].weight;
+  } 
+  return totalWeight;
+}

+ 20 - 10
src/model/events.js

@@ -1,15 +1,25 @@
+/**
+ * clergy {
+ *      wealth : 0
+ *      influence : 1
+ * }
+ * 
+ * nobility {
+ *  wealth : 2
+ *  influence : 3
+ *  army : 4  
+ * }
+ * 
+ * people {
+ *  wealth : 5
+ *  wellbeing : 6
+ * }
+ */
+
 let events = [
   {
     name : "Nom de l'evenement",
-    threshold : {
-      clergy : { wealth : 0, influence : 0 },
-      nobility : { wealth : 0 , influence : 0 , army : 0 },
-      people : { wealth : 0 , wellBeing : 0 }
-    },
-    coefficient : {
-      clergy : { wealth : 0, influence : 0 },
-      nobility : { wealth : 0 , influence : 0 , army : 0 },
-      people : { wealth : 0 , wellBeing : 0 }
-    }
+    threshold : [0, 0, 0, 0, 0, 0, 0],
+    coefficient : [0, 0, 0, 0, 0, 0, 0]
   },
 ]

+ 9 - 0
src/model/game.js

@@ -4,3 +4,12 @@ let playerTaxes = {
 }
 
 let playerLaws = [];
+
+let indicators = [0, 0, 0, 0, 0, 0, 0];
+
+// Tour de jeu actuel
+let round = 0;
+
+
+// Score actuel
+let score = 0;

+ 0 - 71
src/model/indicators.js

@@ -1,71 +0,0 @@
-// INDICATEURS
-
-/*
-<<<<<<< HEAD
-=======
-TOTAL
-
-< contient l'influence et la richesse max >
-*/
-const total = { wealth : 100 , influence : 100 };
-
-/*
->>>>>>> eeb7ff6d99e2ccaf8b19c6a80bbf40f10c387570
-CLERGE :
-  - richesse : relatif a la noblesse et au peuple
-  - influence : relatif a la noblesse
-
-OBJET : { INT: wealth | INT: influence }
-*/
-<<<<<<< HEAD
-let clergy = { wealth : 0 , influence : 0 };
-
-=======
-
-let clergy = { wealth : 0 , influence : 0 };
->>>>>>> eeb7ff6d99e2ccaf8b19c6a80bbf40f10c387570
-
-/*
-NOBLESSE :
-  - richesse : relatif au clerge et au peuple
-  - influence : relatif au clerge
-  - armee : individuel
-
-OBJET : { INT: wealth | INT: influence | INT: army }
-*/
-<<<<<<< HEAD
-let nobility = { wealth : 0 , influence : 0 , army : 0 };
-
-=======
-
-let nobility = { wealth : 0 , influence : 0 , army : 0 };
->>>>>>> eeb7ff6d99e2ccaf8b19c6a80bbf40f10c387570
-
-/*
-PEUPLE :
-  - richesse : relatif a la noblesse et au clerge
-  - bien etre : individuel
-
-OBJET : { INT: wealth | INT: wellBeing }
-*/
-<<<<<<< HEAD
-let people = { wealth : 0 , wellBeing : 0 };
-
-
-// Tour de jeu actuel
-let round = 0;
-
-
-// Score actuel
-=======
-
-let people = { wealth : 0 , wellBeing : 0 };
-
-// Tour de jeu actuel
-
-let round = 0;
-
-// Score actuel
-
->>>>>>> eeb7ff6d99e2ccaf8b19c6a80bbf40f10c387570
-let score = 0;