Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8181675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:36:04+00:00 2026-06-07T00:36:04+00:00

I am having difficulties with my state machine. I use a function that returns

  • 0

I am having difficulties with my state machine. I use a function that returns the new state based on input parameters oldState and two input parameters.

In this function I have a lot of nested switch cases. I’d rather use a 2×2 transition matrix but have no idea how to use it. I did make a transition table from the state diagram with sates and inputs.

But how exaclty do I use the 2 dim. array transition_table[3][4]?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:36:07+00:00Added an answer on June 7, 2026 at 12:36 am

    You stated you currently have something like this:

    StateType transition (StateType old, InputType one, InputType two) {
        //... nested switch statements
        return new_state;
    }
    

    So, it seems what you need is a 3-dimensional array:

    #define MAX_STATES 12
    #define MAX_INPUT_VAL 2
    StateType transitionTable[MAX_STATES][MAX_INPUT_VAL][MAX_INPUT_VAL] = {
        { { StateA, StateB },
          { StateC, StateD } },
        { { StateE, StateF },
          { StateG, StateH } },
        { { StateI, StateJ },
          { StateK, StateL } },
        //...
    };
    

    Then you would transition like this:

    new_state = transitionTable[StateIndex(old)][one][two];
    

    So, assuming that StateIndex(StateC) returns 2, then:

    old = StateC;
    new_state = transitionTable[StateIndex(old)][1][0];
    assert(new_state == StateK);
    

    would result in new_state holding StateK.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having difficulties in returning an input field value through a JS function.
I am having difficulties in disabling href links through jquery. I am using this
I'm having difficulties grasping how to do this. I am making a product options
I'm having difficulties adding momentum to my spinning wheel. I have this wheel (something
We're starting new web site development with Umbraco, and having some difficulties with optimal
I am having difficulties testing Controllers in Codeigniter: I use Toast but when I
OK, I am having difficulties with this query, What I want to do is
im having difficulties figuring this out, ive looked at examples here and on the
I'm having difficulties parsing a string. This is the structure I have: Title:Avatar,Year:2009,Rated:PG-13,Released:18 Dec
I'm having difficulties believing this question hasn't been asked before, but I couldn't find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.