SlideShare a Scribd company logo
1 of 30
Perl + Pathfinder = <3
            apeiron
       apeiron@cpan.org
        YAPC::NA::2012
What's This About?

Having fun
RPGs are fun
Perl is fun
How can we use one to make the other
more fun?
RPGs
I like tabletop RPGs and will play most
systems
However, running combats takes too
much time and effort
I want to pay attention to my players,
not logistics
Perl
Perl is really, really good at automating
things
RPG combats are simple and defined by
deterministic states
Don't we have something to handle
deterministic states?
FSA

Finite State Automaton
Huh?
An FSA is a set of rules defining each
state and how to move to other states
FSAs, Cont'd
An FSA models a system that moves
from one state to the next by a specific,
limited set of rules
Given an initial state and some data,
you can tell which state you'll end up in
... and where to go from there
Yet More FSAs

FSAs have multiple possible destination
states when transitioning
Each transition is tested; the first one
that's true is the destination state
Order transitions by priority
Perl + RPGs == <3
So, what do we have here?
A way of keeping track of whose turn it
is in an RPG combat, and some other
small things like condition expirations
Note that only the Pathfinder/d20
system uses FSA::Engine; it's not a
requirement
What Isn't It?
It doesn't track creature health
It doesn't record what actions one takes
It's not a virtual tabletop
It does not replace the GM
Complete or pretty (right now)
What Is It?
It tracks who goes when
It tracks simple statuses
... and if a status precludes someone
from acting, it skips them
That's it
Anything more is a bug
Why Is It?

Every other tool does too much
(Almost) Every other tool needs
Windows
Every other tool requires a GUI
Why an FSA?

Why not just use a REPL and some
variables?
Let's think about how RPG combats
work
The model fits really well
Why an FSA?
What happens in an RPG combat?
Different creatures take their turns
The order matters but what that order
is doesn't
There's some state that affects who
does what when
Why an FSA?
Turns are grouped into rounds, rounds
are grouped into a combat
Loop over the combatants' turns every
round until there's no combatants from
one side left
Every step of the way is determined by
the state of the system at the time
Why an FSA?

Therefore, we need something that
moves from one of a finite list of states
to another based upon the existing
state
It turns out FSAs are really good at that
Automata in Perl

We've got a few automata in Perl:
 POE::NFA
 FSA::Rules
 FSA::Engine
FSA::Engine
Moose role
Adds some attributes and methods
These attributes and methods control
the automaton
The docs are good, I won't repeat them
here
Using FSA::Engine
It's a Moose role, so you compose it into
your class as you would any other role
Then there are some attributes and
methods you need to write which tell
the FSA how to transition states
Really easy, seriously
The App Itself

It's simple, really
Start it, it asks for a list of combatants
(PCs and NPCs)
Then it runs a combat until one side
wins
Poking Under The Cover
 Each different game system is supported
 by a ruleset class
 This ruleset class is actually the brain
 of the app
 It determines who goes when and most
 everything else
But...


What if a player changes their mind?
Undo Support
When thinking about this feature, I
investigated various undo frameworks
on CPAN
They do what they say on the tin...
... but they require me to write lots of
boring code
Isn't there an easier way?
Undo Support
It turns out there is
The FSA runs various coderefs to
determine which state to advance to
These coderefs use attributes and
variables in scope for the transition
subs
Therefore...

All we need for undo support is to find a
way to snapshot the object attributes
and lexicals and a way to roll back that
to that snapshot and then tell the state
machine to go to the next state
The Magic
The trick here is realizing that it's not
really undo that we need
It's just moving the FSA to another
state
If we can fake that, then it doesn't
really matter that it's fake undo
How?
If this was just package variables it'd be
easy
But it's modern Perl and that means
lexicals
Thankfully, Perl is awesome
We have tools for that, like PadWalker
PadWalker?
Every so often, take a snapshot of the
lexical pad
Push it onto a stack
When requested, unwind the stack, tell
the FSA to go to the next state
Undo support!
But...

It *is* a bit of a hack
It's simple
But it's cheating
Patches welcome
Future Directions

Other RPG systems
Serialize state to disk for resuming
sessions later
Add support for holding/delaying
actions and other things of that sort
Questions?


Code is on github at http://bit.ly/LlqIcR
Slides at http://slidesha.re/LSTqT4

More Related Content

Recently uploaded

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Recently uploaded (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Perl + pathfinder == &lt;3

  • 1. Perl + Pathfinder = <3 apeiron apeiron@cpan.org YAPC::NA::2012
  • 2. What's This About? Having fun RPGs are fun Perl is fun How can we use one to make the other more fun?
  • 3. RPGs I like tabletop RPGs and will play most systems However, running combats takes too much time and effort I want to pay attention to my players, not logistics
  • 4. Perl Perl is really, really good at automating things RPG combats are simple and defined by deterministic states Don't we have something to handle deterministic states?
  • 5. FSA Finite State Automaton Huh? An FSA is a set of rules defining each state and how to move to other states
  • 6. FSAs, Cont'd An FSA models a system that moves from one state to the next by a specific, limited set of rules Given an initial state and some data, you can tell which state you'll end up in ... and where to go from there
  • 7. Yet More FSAs FSAs have multiple possible destination states when transitioning Each transition is tested; the first one that's true is the destination state Order transitions by priority
  • 8. Perl + RPGs == <3 So, what do we have here? A way of keeping track of whose turn it is in an RPG combat, and some other small things like condition expirations Note that only the Pathfinder/d20 system uses FSA::Engine; it's not a requirement
  • 9. What Isn't It? It doesn't track creature health It doesn't record what actions one takes It's not a virtual tabletop It does not replace the GM Complete or pretty (right now)
  • 10. What Is It? It tracks who goes when It tracks simple statuses ... and if a status precludes someone from acting, it skips them That's it Anything more is a bug
  • 11. Why Is It? Every other tool does too much (Almost) Every other tool needs Windows Every other tool requires a GUI
  • 12. Why an FSA? Why not just use a REPL and some variables? Let's think about how RPG combats work The model fits really well
  • 13. Why an FSA? What happens in an RPG combat? Different creatures take their turns The order matters but what that order is doesn't There's some state that affects who does what when
  • 14. Why an FSA? Turns are grouped into rounds, rounds are grouped into a combat Loop over the combatants' turns every round until there's no combatants from one side left Every step of the way is determined by the state of the system at the time
  • 15. Why an FSA? Therefore, we need something that moves from one of a finite list of states to another based upon the existing state It turns out FSAs are really good at that
  • 16. Automata in Perl We've got a few automata in Perl: POE::NFA FSA::Rules FSA::Engine
  • 17. FSA::Engine Moose role Adds some attributes and methods These attributes and methods control the automaton The docs are good, I won't repeat them here
  • 18. Using FSA::Engine It's a Moose role, so you compose it into your class as you would any other role Then there are some attributes and methods you need to write which tell the FSA how to transition states Really easy, seriously
  • 19. The App Itself It's simple, really Start it, it asks for a list of combatants (PCs and NPCs) Then it runs a combat until one side wins
  • 20. Poking Under The Cover Each different game system is supported by a ruleset class This ruleset class is actually the brain of the app It determines who goes when and most everything else
  • 21. But... What if a player changes their mind?
  • 22. Undo Support When thinking about this feature, I investigated various undo frameworks on CPAN They do what they say on the tin... ... but they require me to write lots of boring code Isn't there an easier way?
  • 23. Undo Support It turns out there is The FSA runs various coderefs to determine which state to advance to These coderefs use attributes and variables in scope for the transition subs
  • 24. Therefore... All we need for undo support is to find a way to snapshot the object attributes and lexicals and a way to roll back that to that snapshot and then tell the state machine to go to the next state
  • 25. The Magic The trick here is realizing that it's not really undo that we need It's just moving the FSA to another state If we can fake that, then it doesn't really matter that it's fake undo
  • 26. How? If this was just package variables it'd be easy But it's modern Perl and that means lexicals Thankfully, Perl is awesome We have tools for that, like PadWalker
  • 27. PadWalker? Every so often, take a snapshot of the lexical pad Push it onto a stack When requested, unwind the stack, tell the FSA to go to the next state Undo support!
  • 28. But... It *is* a bit of a hack It's simple But it's cheating Patches welcome
  • 29. Future Directions Other RPG systems Serialize state to disk for resuming sessions later Add support for holding/delaying actions and other things of that sort
  • 30. Questions? Code is on github at http://bit.ly/LlqIcR Slides at http://slidesha.re/LSTqT4

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. I love the flexibility offered by tabletop RPGs. When we involve a computer in gaming, the limitations of the technology impose limitations on what we can do in the game world. This code was designed specifically to be as minimal and lightweight as possible so as to not restrict what people can do in the game world.\n
  10. This application is more defined by what it does not do than by what it does do. Small is beautiful. Less is more. Just as describing something limits it, providing scaffolding and mechanism in a computer program limits what one can do to what the program can do. This is very much a philosophical decision for this application.\n
  11. I want the freedom to let my players do whatever they want. This means leaving things simple and light. I don&apos;t run Windows. It&apos;s not an option. I&apos;m a minimalist and I love Unix. Seriously. I live in a terminal all day every day. I have about 50 panes in tmux across all the machines I have logins on. Each one has a purpose. Text is beautiful. Go read ESR&apos;s Art of Unix Programming and replace all the jibes at Perl with &apos;fnord&apos;.\n
  12. \n
  13. This is a simplified model, of course, which doesn&apos;t account for environmental hazards or other more creative things. It also glosses over the ways different RPG systems \n
  14. \n
  15. \n
  16. POE::NFA is not really what I want; my use case is very deterministic.\nFSA::Rules, well, frankly I&apos;m not sure how I missed it. metacpan bug maybe? I very probably would have used this if I knew about it.\nFSA::Engine is a Moose role that adds FSA capabilities to a class. It&apos;s also what we&apos;ll be talking about today.\n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. There&apos;s a lot left to do here, but the basic groundwork is laid and can be built upon.\n
  30. \n