Last active
January 4, 2016 05:59
-
-
Save puterleat/8578848 to your computer and use it in GitHub Desktop.
stupidexample.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # An associative mapping of desired outcomes to actions | |
| # sometimes conditional (|) on a particular environment | |
| goal_to_action_mapping = { | |
| "Attract a mate": { | |
| "Disco": ["Demonstrate virility", "Be funny", "Be a nice person"], | |
| "Bedroom": ["Demonstrate virility", "Be a nice person"], | |
| } | |
| "Demonstrate virility": { | |
| "Disco": ["Dance like a boss", "Buy drinks", "Start a fight",], | |
| "Bedroom": [...] | |
| } | |
| "Dance like a boss": { | |
| "Ballroom": ["Do the Charleston", "Do a Waltz"] | |
| "Default": ["Shake your booty", "Gesticulate wildly"] | |
| } | |
| "Despair": { | |
| "Default": ["Climb into bed", "Drink beer", "Drive to Beachyhead"], | |
| "Beachyhead": ["Jump"] | |
| }, | |
| } | |
| def pursue_goal(desired_outcome, environment): | |
| print "Current active goal: " + desired_outcome | |
| possibilities = filter(outcome_to_action_mapping, desired_outcome, environment) | |
| if length(possibilities) == 0: | |
| return pursue_goal("Despair", environment) | |
| sort(possibilities, key=magic_inverse_inference_function_against_current_goal) | |
| best_bet = possibilities.pop() | |
| if is_an_an_actionable_thing(best_bet): | |
| your_body_does(best_bet) | |
| else: | |
| return pursue_goal(best_bet, environment) | |
| if outcome != complete: | |
| return pursue_goal(desired_outcome, environment) | |
| # happy scenario | |
| pursue_goal("Dance like a boss", "In your bedroom") | |
| > Current active goal: "Dance like a boss" | |
| > You shake your booty | |
| > You gesticulate wildly | |
| # unhappy scenario | |
| pursue_goal("Attract a mate", "At the disco") | |
| > Current active goal: "Demonstrate your virility" | |
| > Current active goal: "Dance like a boss" | |
| > You shake your booty | |
| > Current active goal: "Dance like a boss" | |
| > You gesticulate wildly | |
| > Current active goal: "Buy drinks" | |
| ... | |
| > Current active goal: "Start a fight" | |
| ... | |
| > Current active goal: "Despair" | |
| ... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment