Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .coverage
Binary file not shown.
5 changes: 5 additions & 0 deletions src/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ def __init__(self):
self.godMode = False # Disable god mode
self.maxTicks = 1000
self.tickLength = 0.1

# Early-game survival settings
self.earlyGameGracePeriod = 50 # Number of ticks of protection for player
self.playerDamageReduction = 0.4 # 40% damage reduction for player during grace period
# During grace period, other creatures have 85% chance to avoid attacking player
10 changes: 10 additions & 0 deletions src/entity/livingEntity.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def fight(self, kreature):
# This creature attacks first
if self.health > 0:
damage = random.randint(15, 25) # Random damage between 15-25
# Apply damage reduction if target has it
if hasattr(kreature, 'damageReduction') and kreature.damageReduction > 0:
damage = int(damage * (1 - kreature.damageReduction))
damage = max(damage, 1) # Ensure at least 1 damage

kreature.health -= damage
if kreature.health <= 0:
self.log.append(
Expand All @@ -80,6 +85,11 @@ def fight(self, kreature):
# Target creature counter-attacks if still alive
if kreature.health > 0:
damage = random.randint(15, 25) # Random damage between 15-25
# Apply damage reduction if target has it
if hasattr(self, 'damageReduction') and self.damageReduction > 0:
damage = int(damage * (1 - self.damageReduction))
damage = max(damage, 1) # Ensure at least 1 damage

self.health -= damage
if self.health <= 0:
kreature.log.append(
Expand Down
39 changes: 35 additions & 4 deletions src/kreatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def __init__(self):
self.running = True
self.config = Config()
self.tick = 0

# Initialize player early-game protection
self.playerCreature.damageReduction = self.config.playerDamageReduction
self.playerCreature.log.append("%s has early-game protection!" % self.playerCreature.name)

def initiateEntityActions(self):
entities_to_remove = [] # Track entities that die this turn
Expand All @@ -59,8 +63,18 @@ def initiateEntityActions(self):
entity.decreaseChanceToFight()
self.createChildEntity(parents[0], parents[1])
elif decision == "fight":
if target == self.playerCreature and self.config.godMode:
continue
# Enhanced protection: during grace period, reduce attacks on player
if target == self.playerCreature:
if self.config.godMode:
continue
# During grace period, 85% chance to skip attacking the player
if (self.tick < self.config.earlyGameGracePeriod and
random.randint(1, 100) <= 85):
entity.log.append(
"%s decided not to attack %s." % (entity.name, target.name)
)
continue

entity.increaseChanceToFight()
entity.decreaseChanceToBefriend()
entity.fight(target)
Expand All @@ -78,6 +92,14 @@ def initiateEntityActions(self):
for entity in entities_to_remove:
self.environment.removeEntity(entity)

def updatePlayerProtection(self):
"""Update player protection based on current tick"""
if self.tick >= self.config.earlyGameGracePeriod:
# Grace period has ended
if hasattr(self.playerCreature, 'damageReduction') and self.playerCreature.damageReduction > 0:
self.playerCreature.damageReduction = 0
self.playerCreature.log.append("%s's protection has worn off!" % self.playerCreature.name)

def regenerateAllEntities(self):
"""Regenerate health for all living entities"""
for entity in self.environment.getEntities():
Expand Down Expand Up @@ -186,6 +208,12 @@ def printSummary(self):
"%s's chance to be nice was %d percent."
% (self.playerCreature.name, self.playerCreature.chanceToBefriend)
)

# Show protection status
if hasattr(self.playerCreature, 'damageReduction') and self.playerCreature.damageReduction > 0:
protection_percent = int(self.playerCreature.damageReduction * 100)
print("%s still has %d%% damage reduction." % (self.playerCreature.name, protection_percent))

if self.playerCreature.isAlive():
print(
"%s ended with %d health (out of %d max)."
Expand All @@ -198,6 +226,7 @@ def printSummary(self):
else:
print("%s died during the simulation." % self.playerCreature.name)
print("Kreatures still alive: %d" % self.environment.getNumEntities())
print("Simulation ran for %d ticks." % self.tick)

def printStats(self):
print("=== Stats ===")
Expand All @@ -224,6 +253,7 @@ def run(self):
pass

self.initiateEntityActions()
self.updatePlayerProtection() # Update player protection status
self.regenerateAllEntities() # Regenerate health for all entities
time.sleep(self.config.tickLength)
self.tick += 1
Expand All @@ -238,5 +268,6 @@ def run(self):
self.printStats()


kreatures = Kreatures()
kreatures.run()
if __name__ == "__main__":
kreatures = Kreatures()
kreatures.run()
Loading