Skip to content

Commit

Permalink
formatting and reviewing what we have. Getting ready to make everythi…
Browse files Browse the repository at this point in the history
…ng be controlled through agents.
  • Loading branch information
keppy committed Jul 20, 2024
1 parent d65d2fa commit 016131b
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 50 deletions.
14 changes: 14 additions & 0 deletions worldender/worldender/agents/gm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import random
from pydantic import BaseModel, Field
from typing import List, Union

Expand Down Expand Up @@ -46,3 +47,16 @@ class GameMaster(BaseModel):
action: Union[Move, Build, Research, Warfare] = Field(
description="The action that the player can take"
)

def roll_d_20(self):
"""
roll_d_20 rolls a 20 sided die to determine the outcome of the action
"""
return random.randint(1, 20)


SCENARIO_PROMPT = "Make up a scenario that the player must face and react to in response to the action they took"
CHALLENGE_PROMPT = (
"Make up a challenge for the player that they must roll a d20 to overcome"
)
OUTCOME_PROMPT = "Make up an outcome for the player based on the scenario they faced, the action they took, and the challenge they faced"
1 change: 0 additions & 1 deletion worldender/worldender/models/choice.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pydantic import BaseModel, Field
from typing import List


class Choice(BaseModel):
Expand Down
72 changes: 36 additions & 36 deletions worldender/worldender/models/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
from tabulate import tabulate

DEFAULT_CONFIG: Dict[str, str | int | None] = {
'name': "",
'city': "",
'movement': 10,
'skill': "Survivalist",
'item': "Tools",
'ailment': "",
'hp': 100,
'sanity': 100
"name": "",
"city": "",
"movement": 10,
"skill": "Survivalist",
"item": "Tools",
"ailment": "",
"hp": 100,
"sanity": 100,
}


class Player(BaseModel):
_internal_values: Dict[str, str | int | None] = PrivateAttr(default=DEFAULT_CONFIG)

Expand All @@ -24,103 +25,102 @@ def __init__(self, **data: Any) -> None:
@property
def city(self) -> str:
"""The city property. A simple string, flexible on what's in it."""
return self._internal_values['city']
return self._internal_values["city"]

@city.setter
def city(self, value) -> None:
"""Set the underlying _internal_values dictionary value for 'city'"""
self._internal_values['city'] = value
self._internal_values["city"] = value

@computed_field
@property
def name(self) -> str:
"""The name property. A simple string."""
return self._internal_values['name']
return self._internal_values["name"]

@name.setter
def name(self, value) -> None:
"""Set the underlying _internal_values dictionary value for 'name'"""
self._internal_values['name'] = value
self._internal_values["name"] = value

@computed_field
@property
def hp(self) -> int:
"""The hp property. An integer."""
return self._internal_values['hp']
return self._internal_values["hp"]

@hp.setter
def hp(self, value) -> None:
"""Set the underlying _internal_values dictionary value for 'hp'"""
self._internal_values['hp'] = value
self._internal_values["hp"] = value

@computed_field
@property
def sanity(self) -> int:
"""The sanity property. An integer."""
return self._internal_values['sanity']
return self._internal_values["sanity"]

@sanity.setter
def sanity(self, value) -> None:
"""Set the underlying _internal_values dictionary value for 'sanity'"""
self._internal_values['sanity'] = value
self._internal_values["sanity"] = value

@computed_field
@property
def item(self) -> str:
"""The item property. A string."""
return self._internal_values['item']
return self._internal_values["item"]

@item.setter
def item(self, value) -> None:
"""Set the underlying _internal_values dictionary value for 'item'"""
self._internal_values['item'] = value
self._internal_values["item"] = value

@computed_field
@property
def skill(self) -> str:
"""The skill property. A string."""
return self._internal_values['skill']
return self._internal_values["skill"]

@skill.setter
def skill(self, value) -> None:
"""Set the underlying _internal_values dictionary value for 'skill'"""
self._internal_values['skill'] = value
self._internal_values["skill"] = value

@computed_field
@property
def ailment(self) -> str:
"""The ailment property. A string."""
return self._internal_values['ailment']
return self._internal_values["ailment"]

@ailment.setter
def ailment(self, value) -> None:
"""Set the underlying _internal_values dictionary value for 'ailment'"""
self._internal_values['ailment'] = value
self._internal_values["ailment"] = value

@computed_field
@property
def movement(self) -> str:
"""The movement property. A string."""
return self._internal_values['movement']
return self._internal_values["movement"]

@movement.setter
def movement(self, value) -> None:
"""Set the underlying _internal_values dictionary value for 'movement'"""
self._internal_values['movement'] = value
self._internal_values["movement"] = value

def status_table(self) -> str:
'''Return a table str that shows the player's status in a readable format.'''
headers = ['property', 'value']
"""Return a table str that shows the player's status in a readable format."""
headers = ["property", "value"]
table = [
['Name', self.name],
['City', self.city],
['Ailment', self.ailment],
['HP', self.hp],
['Sanity', self.sanity],
['Movement', self.movement],
['Item', self.item],
['Skill', self.skill],

["Name", self.name],
["City", self.city],
["Ailment", self.ailment],
["HP", self.hp],
["Sanity", self.sanity],
["Movement", self.movement],
["Item", self.item],
["Skill", self.skill],
]
table = tabulate(table, headers, tablefmt='rounded_outline')
table = tabulate(table, headers, tablefmt="rounded_outline")
return table
3 changes: 2 additions & 1 deletion worldender/worldender/models/question.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pydantic import BaseModel, Field


class Question(BaseModel):
text: str = Field(description="The text of the question to ask")
text: str = Field(description="The text of the question to ask")
12 changes: 8 additions & 4 deletions worldender/worldender/models/question_response.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from pydantic import BaseModel, Field


class QuestionResponse(BaseModel):
'''
"""
A response to a question about the world ending event. There is a correct question to ask that will reveal hidden information in the game.
'''
correct_question: bool = Field(description="Indicate if this was the correct question to ask")
response: str = Field(description="The response to the question")
"""

correct_question: bool = Field(
description="Indicate if this was the correct question to ask"
)
response: str = Field(description="The response to the question")
28 changes: 20 additions & 8 deletions worldender/worldender/models/world_ender.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
from pydantic import BaseModel, Field


class WorldEnder(BaseModel):
'''
An apocolyptic event that the human race, and likely the world, cannot come back from.
This will likely be a nuclear event. The consiquences will likely be long term fallout.
"""
An apocalyptic event that the human race, and likely the world, cannot come back from.
This will likely be a nuclear event. The consequences will likely be long term fallout.
The class should tell the story of how we got here and why these things happened.
'''
kind: str = Field(description="What kind of world ending event was this? (astrological, biological, war, etc.)")
description: str = Field(description="A detailed description of what happened, including the Events and Outcomes involved")
death_toll: str = Field(description="The total estimated cost of human life as a readable number example: 1bil")
survival_rate: float = Field(description="The percentage chance that any humans will survive the world ending event", ge=0.0, le=1.0)
"""

kind: str = Field(
description="What kind of world ending event was this? (astrological, biological, war, etc.)"
)
description: str = Field(
description="A detailed description of what happened, including the Events and Outcomes involved"
)
death_toll: str = Field(
description="The total estimated cost of human life as a readable number example: 1bil"
)
survival_rate: float = Field(
description="The percentage chance that any humans will survive the world ending event",
ge=0.0,
le=1.0,
)

def report(self):
dct = self.model_dump()
Expand Down

0 comments on commit 016131b

Please sign in to comment.