Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorechinelli <emilianochinelli@gmail.com>2010-11-29 23:33:49 (GMT)
committer echinelli <emilianochinelli@gmail.com>2010-11-29 23:33:49 (GMT)
commite4b439367352ad76a5a13e4e95dcfde6899e4377 (patch)
tree0aef23eba5819e897c74caf583921511ee93bc32
parent85a4026c7441fbe72b388d095d906ad025fdaf2a (diff)
Linking events and bars...
changes in modules: app_init, events, game_manager, status_bars
-rwxr-xr-xSaludame.activity/app_init.py9
-rwxr-xr-xSaludame.activity/events.py39
-rwxr-xr-xSaludame.activity/game_manager.py34
-rwxr-xr-xSaludame.activity/status_bars.py15
4 files changed, 82 insertions, 15 deletions
diff --git a/Saludame.activity/app_init.py b/Saludame.activity/app_init.py
index adc9307..5b0b5ef 100755
--- a/Saludame.activity/app_init.py
+++ b/Saludame.activity/app_init.py
@@ -78,22 +78,22 @@ class AppLoader:
_events = []
# probabiliy configuration: (bar, type, threshold, probability_percentaje)
- probability = [("v_frutas", "indirect", 10, 30)]
+ probability = [("v_frutas", "indirect", 10.0, 30.0)]
effect = effects.Effect(bars_controller, [("energy", -1.0), ("fun", -0.5)])
event = events.Event("ill.jpg", None, "constipation", _("Constipation"), 5, 15, "personal", probability, effect, u"Me duele la panza y no \n puedo ir al baño", 2, 50)
_events.append(event)
- probability = [("w_hands", "indirect", 25, 30)]
+ probability = [("w_hands", "indirect", 25.0, 30.0)]
effect = effects.Effect(bars_controller, [("energy", -1.0), ("fun", -0.5), ("agua", -1.0), ("defenses", -0.5)])
event = events.Event("ill.jpg", None, "diarrhea", _("Diarrhea"), 5, 15, "personal", probability, effect, "Tengo diarrea", 2, 50)
_events.append(event)
- probability = [("nutrition", "indirect", 100, 40), ("relaxing", "indirect", 100, 40)]
+ probability = [("nutrition", "indirect", 100.0, 20.0), ("relaxing", "indirect", 100.0, 20.0)]
effect = effects.Effect(bars_controller, [("energy", -1.0), ("fun", -0.5), ("relaxing", -0.5)])
event = events.Event("ill.jpg", None, "headache", _("Headache"), 5, 15, "personal", probability, effect, "Me duele la cabeza", 2, 50)
_events.append(event)
- probability = [("b_teeth", "indirect", 25, 50), ("dulces", "direct", 75, 20)]
+ probability = [("b_teeth", "indirect", 25.0, 50.0), ("dulces", "direct", 75.0, 20.0)]
effect = effects.Effect(bars_controller, [("energy", -1.0), ("defenses", -1.0), ("fun", -1.0), ("relaxing", -1.0)])
event = events.Event("caries.jpg", None, "caries", _("Caries"), 5, 15, "personal", probability, effect, "Me duele una muela...", 5, 50)
_events.append(event)
@@ -136,3 +136,4 @@ class AppLoader:
return moods_list
+
diff --git a/Saludame.activity/events.py b/Saludame.activity/events.py
index 4ec6d36..0b230d7 100755
--- a/Saludame.activity/events.py
+++ b/Saludame.activity/events.py
@@ -2,6 +2,9 @@
import actions
+MAX_BAR_VALUE = 100.0 #maximo valor que puede alcanzar una barra
+ #necesario para el calculo de probabilidades
+
class Event:
def __init__(self, picture, kid_animation_path, name, description, appereance_probability, time_span, kind, event_status, effect, kid_message, preferred_mood=9, message_time_span=5):
@@ -27,6 +30,10 @@ class Event:
self.effect = effect
+ self.conditioned_bars = event_status
+
+ self.conditioned_probability = 0 #se toma como cero la probabilidad inicial de cada evento
+
def perform(self):
if(self.time_left):
self.effect.activate()
@@ -35,8 +42,40 @@ class Event:
def reset(self):
self.time_left = self.time_span
+ def get_probability(self):
+ #eventually we just take the conditioned
+ #probability
+ return int(self.conditioned_probability)
+
+ def update_probability(self, bars_value_dic):
+ """
+ Updates event probability
+ """
+
+ prob = 0.0
+ for bar_con in self.conditioned_bars:
+ bar_id = bar_con[0]
+ threshold = bar_con[2]
+ max_prob = bar_con[3]
+
+ bar_value = bars_value_dic[bar_id]
+
+ if bar_con[1] == "direct":
+
+ if bar_value > threshold:
+ prob += max_prob * ((bar_value - threshold) / (MAX_BAR_VALUE - threshold))
+ elif bar_con[1] == "indirect":
+ if bar_value < threshold:
+ prob += max_prob * ((threshold - bar_value) / threshold)
+ elif bar_con[1] == "constant":
+ if bar_value < threshold :
+ prob += max_prob
+ self.conditioned_probability = prob
+ return int(prob)
+
class EventStatusProbability:
def __init__(self, conditioned_probability, direct_indirect):
self.conditioned_probability = conditioned_probability
self.direct_indirect = direct_indirect
+
diff --git a/Saludame.activity/game_manager.py b/Saludame.activity/game_manager.py
index 0521ef4..8f33d1e 100755
--- a/Saludame.activity/game_manager.py
+++ b/Saludame.activity/game_manager.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
CONTROL_INTERVAL = 15 #cantidad de señales hasta que realiza un checkeo de las acciones.
-EVENTS_OCCURRENCE_INTERVAL = 5 #per control interval after an event
+EVENTS_OCCURRENCE_INTERVAL = 2 #per control interval after an event
HOUR_COUNT_CYCLE = 10 #control intevals that have to pass to management the time of day
@@ -68,6 +68,7 @@ class GameManager:
#for testing
self.p_i = 0
+
# management
@@ -91,9 +92,8 @@ class GameManager:
self.__check_active_mood() # check if the active character mood
self.__handle_time()
- self.count = 0
+ self.count = 0
-
## Environment handling
def update_environment(self):
@@ -296,7 +296,7 @@ class GameManager:
self.active_event = None
else:
if(not self.events_interval):
- self.active_event = self.__get_new_event() #get a new random event
+ self.active_event = self.__get_random_event() #get a new random event
self.windows_controller.add_personal_event(self.active_event) #notify windows controller
@@ -309,14 +309,27 @@ class GameManager:
else:
self.events_interval -= 1
- def __get_new_event(self):
+ def __get_random_event(self):
"""
Get a random event
"""
+ self.__update_events_probability()
+
rand = random.randint(0, self.max_rand)
for i in range(0, len(self.probability_ranges)):
if(rand >= self.probability_ranges[i][0] and rand <= self.probability_ranges[i][1]):
return self.events_list[i]
+
+ def __update_events_probability(self):
+ """
+ Updates events probability
+ """
+ #updates events probability
+ for evt in self.events_list:
+ print evt.name, " prob: ", evt.update_probability(self.bars_controller.get_bars_status())
+
+ self.max_rand = self.__calculate_max_rand(self.events_list)
+ self.probability_ranges = self.__calculate_ranges(self.events_list)
def __calculate_max_rand(self, events_list):
"""
@@ -324,7 +337,7 @@ class GameManager:
"""
max_rand = 0
for event in events_list:
- max_rand += event.appereance_probability
+ max_rand += event.get_probability()
return max_rand
def __calculate_ranges(self, events_list):
@@ -335,13 +348,13 @@ class GameManager:
previous = 0
ranges = []
for event in events_list:
- ranges += [(previous, previous + event.appereance_probability)]
- previous += event.appereance_probability + 1
+ ranges += [(previous, previous + event.get_probability())]
+ previous += event.get_probability() + 1
return ranges
# Score handling
def add_points(self, points):
- score_bar = [bar for bar in self.bars_controller.bars if bar.id == "score_bar"][0]
+ score_bar = self.bars_controller.score_bar
score_bar.value += points
def __control_level(self):
@@ -365,4 +378,5 @@ class GameManager:
# reach the master challenge again.
self.challenges_creator.get_challenge()
self.windows_controller.set_active_window("challenges_window")
- \ No newline at end of file
+
+
diff --git a/Saludame.activity/status_bars.py b/Saludame.activity/status_bars.py
index 8b5453a..a0ed8e5 100755
--- a/Saludame.activity/status_bars.py
+++ b/Saludame.activity/status_bars.py
@@ -333,7 +333,7 @@ class ScoreSection(Widget):
self.text_color = pygame.Color(TEXT_COLOR)
def draw(self, screen):
- self.surface.blit(self.get_background().subsurface(self.rect_in_container), (0,0))
+ self.surface.blit(self.get_background().subsurface(self.rect_in_container), (0, 0))
# draw bar:
self.score_bar_display.draw(self.surface)
@@ -392,6 +392,18 @@ class BarsController:
for bar in self.bars:
if bar.id == bar_id:
return bar.label
+
+ def get_bars_status(self):
+ """
+ Generates a dictionary {bar_id : actual_bar_value} and
+ returns it.
+ """
+ bars_state = {}
+
+ for bar in self.bars:
+ bars_state.update({ bar.id : bar.value })
+
+ return bars_state
class StatusBar:
"""
@@ -456,3 +468,4 @@ class StatusBar:
self.value = self.max
elif self.value < 0:
self.value = 0
+