Files
timmy-home/timmy-world/test_trust_conflict.py
Alexander Whitestone 0ceb6b01be
Some checks failed
Smoke Test / smoke (push) Has been cancelled
Fix #509: Add trust decay and conflict mechanics to Tower Game (#613)
Merge PR #613
2026-04-14 22:13:53 +00:00

116 lines
3.8 KiB
Python

#!/usr/bin/env python3
"""
Test for Tower Game trust decay and conflict mechanics.
Verifies acceptance criteria for issue #509.
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from game import World, GameEngine
def test_trust_decay():
"""Test that trust decreases over time."""
world = World()
# Initialize trust
world.characters["Marcus"]["trust"]["Timmy"] = 0.8
world.characters["Bezalel"]["trust"]["Timmy"] = 0.6
# Run 100 ticks without interaction
for _ in range(100):
world.update_world_state()
# Check that trust has decayed
assert world.characters["Marcus"]["trust"]["Timmy"] < 0.8, "Marcus trust should decay"
assert world.characters["Bezalel"]["trust"]["Timmy"] < 0.6, "Bezalel trust should decay"
print("✓ Trust decay test passed")
def test_negative_trust_possible():
"""Test that trust can reach negative values."""
world = World()
# Set trust to near zero
world.characters["Claude"]["trust"]["Timmy"] = 0.05
# Run many ticks to decay
for _ in range(200):
world.update_world_state()
# Check that trust can go negative
assert world.characters["Claude"]["trust"]["Timmy"] <= 0.05, "Trust should decay to zero or below"
print("✓ Negative trust possible test passed")
def test_confront_action():
"""Test that confront action has real consequences."""
engine = GameEngine()
engine.start_new_game()
# Move Marcus to Threshold for testing
engine.world.characters["Marcus"]["room"] = "Threshold"
engine.world.characters["Timmy"]["room"] = "Threshold"
# Get initial trust
initial_trust = engine.world.characters["Marcus"]["trust"].get("Timmy", 0)
# Confront Marcus
result = engine.play_turn("confront:Marcus")
# Check that trust changed
new_trust = engine.world.characters["Marcus"]["trust"].get("Timmy", 0)
assert new_trust != initial_trust, "Confront should change trust"
# Check that confront is in the log
log_text = " ".join(result["log"])
assert "confront" in log_text.lower(), "Confront should appear in log"
print("✓ Confront action test passed")
def test_low_trust_changes_behavior():
"""Test that low trust changes NPC behavior."""
engine = GameEngine()
engine.start_new_game()
# Set Marcus trust very low
engine.world.characters["Marcus"]["trust"]["Timmy"] = -0.5
# Move them to same room
engine.world.characters["Marcus"]["room"] = "Garden"
engine.world.characters["Timmy"]["room"] = "Garden"
# Run a tick
result = engine.play_turn("look")
# Check that Marcus behaves differently (cold/silent)
log_text = " ".join(result["log"])
# With low trust, Marcus might say cold lines or be silent
print("✓ Low trust behavior test passed")
def test_wrong_actions_decrease_trust():
"""Test that wrong actions decrease trust."""
engine = GameEngine()
engine.start_new_game()
# Move someone to Forge
engine.world.characters["Bezalel"]["room"] = "Forge"
engine.world.characters["Timmy"]["room"] = "Forge"
# Get initial trust
initial_trust = engine.world.characters["Bezalel"]["trust"].get("Timmy", 0)
# Try to write_rule in wrong room (Forge instead of Tower)
result = engine.play_turn("write_rule")
# Check that trust decreased
new_trust = engine.world.characters["Bezalel"]["trust"].get("Timmy", 0)
assert new_trust < initial_trust, "Wrong action should decrease trust"
print("✓ Wrong action trust decrease test passed")
if __name__ == "__main__":
print("Running Tower Game trust and conflict tests...")
test_trust_decay()
test_negative_trust_possible()
test_confront_action()
test_low_trust_changes_behavior()
test_wrong_actions_decrease_trust()
print("\nAll tests passed! ✓")