Converting a DFA to efficient code?

  • Thread starter Thread starter kolleamm
  • Start date Start date
  • Tags Tags
    Code Dfa
Click For Summary

Discussion Overview

The discussion revolves around the implementation of a Deterministic Finite Automaton (DFA) for a game character's dialogue system. Participants explore various coding strategies to efficiently manage multiple states and transitions without resorting to complex nested conditional statements.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant suggests that using "if, if else, for, while" statements may be impractical due to the number of states and inputs, indicating a need for a more efficient approach.
  • Another participant proposes the use of a case statement as a potential solution.
  • A different participant emphasizes the importance of using appropriate data structures and pre-existing code from the programming language to implement the DFA effectively.
  • One suggestion involves organizing the dialogue data into records that include state transitions and associated questions and answers, allowing for dynamic user interaction based on the current state.
  • A participant mentions using C# and considers linked lists for state management but expresses concerns about efficiency.
  • There is a discussion about whether to use a data file or nested directories for storing state information, with references to XML as a more sophisticated option for data storage.

Areas of Agreement / Disagreement

Participants present multiple competing views on the best approach to implement the DFA, with no consensus reached on a single method or structure. The discussion remains unresolved regarding the optimal coding strategy.

Contextual Notes

Participants express uncertainty about the complexity of the DFA and the efficiency of various proposed data structures and storage methods. There are also unresolved considerations regarding the best practices for organizing state information.

Who May Find This Useful

Readers interested in game development, dialogue systems, or those looking for efficient coding strategies for state management in programming may find this discussion relevant.

kolleamm
Messages
476
Reaction score
44
I've created a DFA for a game character's dialogue. I could probably code this using "if, if else, for, while" statements, but I feel like this would be impractical since there are about 20 states with 4 different inputs each.
Any ideas on how I could make this work? I would really like to avoid a lot of nested statements if possible.
 
Technology news on Phys.org
Maybe a case statement would be useful.
 
kolleamm said:
Any ideas on how I could make this work? I would really like to avoid a lot of nested statements if possible.

In order to simplify things as much as possible you have to use the right data structures combined with relevant premade code that the programming language you use offers you.

I don't know how complex is the DFA you refer to but just to give you a general idea about a complete DFA, if I had to implement it in Java, I would import the relevant packages (like List, LinkedList, Iterator ... just to name a few) and see what to use to implement the transition function, the terminal states etc. Then I would develop the right methods to make it work.
 
I would put everything in data. Just a whole bunch of records.
startstate#, nextstate#, "Question text", "Answertext"
display all of the questions with startstate# = currentstate, let the user choose one, and then set currentstate to the nextstate# belonging to the question text that was chosen and give the answer belonging to that question.
{1, 1, "Good morning", "Good morning"},
{1, 2, "I'd like to buy a book", "We don't have any"},
(2, 3, "But I was told to come here", "I hear the gooseberry's are doing well this year"}
etc.
More sophisticated systems would store this in an XML file. something like this
https://stackoverflow.com/questions/372915/game-logic-in-xml-files
 
I currently use C#.
I was thinking of using linked lists to store the name of the states which would then be called using methods, although I'm still unsure since efficiency is a concern.
willem2 said:
I would put everything in data. Just a whole bunch of records.
startstate#, nextstate#, "Question text", "Answertext"
display all of the questions with startstate# = currentstate, let the user choose one, and then set currentstate to the nextstate# belonging to the question text that was chosen and give the answer belonging to that question.
{1, 1, "Good morning", "Good morning"},
{1, 2, "I'd like to buy a book", "We don't have any"},
(2, 3, "But I was told to come here", "I hear the gooseberry's are doing well this year"}
etc.
More sophisticated systems would store this in an XML file. something like this
https://stackoverflow.com/questions/372915/game-logic-in-xml-files
Would a data file be better as opposed to nested directories? Such as C:/State/State#/Transition_State#...n
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
4K
Replies
11
Views
4K
  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K