Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [state-machine]

A state machine is a model for designing systems which change based upon their current state and what input they receive.

1
vote
0answers
22 views

Java UIState System

I am trying to come up with a UIState system that works well with Java UI. Before I show it I know I could add enums to help distinguish the states but I've left that out for simplicity. Here is what ...
6
votes
1answer
190 views

Designing yet another a state machine

I wanted to design a state machine with a few goals in mind: Encapsulate state logic within individual classes to keep them decoupled. (I'm very curious what the community thinks about this in ...
1
vote
1answer
70 views

Scheme: FSM substring search

I have been working on a function that return a FSM that searches a specific word based on the argument of the constructor. The idea was to use those routines as means to learn about regular ...
2
votes
1answer
127 views

C++ CLI Console Menu Statemachine

I am trying to find the best way(/most efficent way) to setup my console program's menu. The way I have it set up is that I have a Menu class and then I use a menu pointer called currentMenu and I ...
4
votes
3answers
246 views

Finite State Machine in C++

I made a state machine. You can press 0 and 1 to switch between the hypothetical menu and playing state. I hope you can help me improve it further. StateManager.h ...
3
votes
0answers
49 views

static macro-based State Machine implementation

While learning Rust for the past couple of weeks, I set out to use the type-system to build a static State Machine implementation in Rust. The goals: program in idiomatic Rust no runtime overhead ...
1
vote
0answers
110 views

21 Game (Nim) as Finite State Machine in Python

Feedback from previous posts of mine suggested that my approach to states was haphazard, which is not surprising since I hadn't really thought of games in terms of states before. I have since gone off ...
6
votes
2answers
185 views

Finite state automata

This is a non-deterministic finite state automata (NFA) meant to be used with a Regex engine. To show some example usage, suppose you wanted to construct an NFA for the regex ...
4
votes
0answers
613 views

Finite Automata stub in Rust

I wrote a finite automata implementation in C years ago. C's access to mutable, unsafe, raw pointers made it quite simple for me to link/relink the states of a finite automata. I read the official ...
3
votes
0answers
56 views

Finite State Machine to segment Thai syllables

I am developing a FSM to segment Thai syllables with the following rules: Here are my util functions: ...
1
vote
1answer
270 views

Implement a Finite State Machine in ES6 [closed]

I have built a simple finite state machine that models an even simpler fictitious bank account system. Any given account can be in one of three states at any time: Open, Closed, or Held. I have a ...
2
votes
1answer
127 views

Push Down Automaton to detect RNA hairpins

For one of my assignments I am supposed to write a Push Down Automaton. It's supposed to receive a string that has to be checked if it's an RNA Hairpin. For example: gacgcaaguc would be one, since ...
1
vote
0answers
35 views

3 state switch for a table sort

I have a data table with 7 columns. The first column is the index that increases from 1 to N and is considered to be in ascending order by default. The remaining columns are unsorted. I need to be ...
2
votes
1answer
44 views

Python coroutine structure

I've completed Advent of Code's Day 9 in Python3, trying to use it to teach myself coroutines. I'm very familiar with generators, but I've pretty much never used coroutines before. I've ended up with ...
1
vote
1answer
170 views

Simple state machine based command-line argument parser

I'm in the process of learning to write idiomatic JavaScript code so naturally I'm parsing command line arguments. My approach to this is to have a simple state machine. The parser should work as ...
3
votes
0answers
53 views

“Academic interest” implementation of a Finite State Machine

Context I'm playing around the concept of a Finite State Machine. While I understand the basic principles behind it, I want to implement a simple, yet generic class which could be reused in the ...
4
votes
2answers
685 views

DFA creation from string

I have fairly simple Python 3 code that creates a DFA from a string. It works great, but I believe it can be made more efficient. There are a total of 3 loops: First iterates over the string Second ...
1
vote
0answers
241 views

Mars Rover problem in J

I've written an implementation of the "famous" Mars Rover simulation, (another question on this) whose problem statement is this: The first line of input is the upper-right coordinates of the ...
1
vote
1answer
476 views

Stack-based state machine

Is everything alright with this code? What can I add to it? state.h: ...
5
votes
2answers
187 views

Alternative to nonlocal for local variables in a function with nested functions in Python

Introduction for future readers I posted the code below in the hope that it would be a good example to discuss the topic "Alternative to nonlocal for local variables in a function with nested ...
2
votes
0answers
50 views

Time-dependent state machine with two outputs

Given a class BasicDataFeed whose purpose is to feed questions and answers into an artificial neural network, which is tested in a non-negotiable manner as follows: ...
11
votes
2answers
9k views

Very simple finite state machine

I have beginner knowledge of C++ and using that and some self dummy design I came up with the above implementation. The FiniteStateMachine here first asks for the ...
2
votes
1answer
465 views

Tennis-Refactoring-Kata through OOP

I was trying to solve Tennis-Refactoring-Kata. This seems quite hard at startup but, through use os OOP it can be deeply refactoring using just a single if. My ...
0
votes
2answers
118 views

Stateful implementation of TicTacToe

I made a TicTacToe implementation using State pattern in Java. I was wondering if this could ...
2
votes
1answer
231 views

Regex to DFA parser in Dart

I've created a Regex to DFA parser, using Thompson's construction algorithm and epsilon-reduction. Here is the code: builtins.dart: ...
4
votes
1answer
315 views

Designing posts: state machine

In the Object-Oriented Design Pattern Implementation chapter of the second edition of The Rust Programming Language, the basic code structure is given and it suggests trying to add features: This ...
2
votes
0answers
65 views

STTCL FSM framework based on the GoF State Pattern, Part III: Policy based design of higher level State Machine constructs

Preface I have decided to let my pet project created some years ago to undergo a code review here. The review will be broken into parts according to meta question Multiple reviews or one big review?...
1
vote
0answers
40 views

STTCL FSM framework based on the GoF State Pattern, Part II: Abstraction of asynchronous/concurrency features

Preface I have decided to let my pet project created some years ago to undergo a code review here. The review will be broken into parts according to meta question Multiple reviews or one big review?...
6
votes
0answers
269 views

STTCL FSM framework based on the GoF State Pattern, Part I: The basic interfaces

Preface I have decided to let my pet project created some years ago to undergo a code review here. The review will be broken into parts according to meta question Multiple reviews or one big review?...
1
vote
1answer
39 views

How to refactor / re-architect the components/state here in ui-router app [closed]

https://plnkr.co/edit/bOZW1a9u62W1QA6cYjYj?p=preview My goal has been to separate the Dashboard states from the Feed state. ...
6
votes
1answer
70 views

Arduino controller to control the backlighting of a gear selector

Background The gear selector on a car allows the driver to select which state the transmission should be in. In the example picture, one of the five letters (P, R, N, D & S) lights up to ...
7
votes
3answers
788 views

Efficient data-driven finite state machine

In creating this answer to a recent question, I thought I might write a fully worked example that implements a finite state machine in C. The purpose is to implement the following function: ...
1
vote
1answer
123 views

SafeBox StateMachine implemented with Enums

does someone has any opinions about this SafeBox StateMachine? ...
2
votes
1answer
204 views

Defusing a bomb using a state machine

This code is a solution for /r/daily_programmer #293. The idea of this challenge is, you are given input in the form of colored wires: ...
5
votes
1answer
74 views

Logon state management

I'm in the process of writing a simple text based MUD. First up is making sure that it's possible to create new players / logon with existing players. Since everything is text based, there are ...
1
vote
1answer
45 views

Handling workflow rules for a job application process

For some reason I always have a negative feeling towards having many if statements in my JavaScript functions. But I've got some code that is processing an object ...
4
votes
1answer
190 views

Time-dependent state machine

I keep having to write state machines that depend on time for various experiments I run and I'd like to know how to write them better. This state machine is for training a neural network by feeding in ...
4
votes
1answer
4k views

Event-driven finite state machine DSL in Kotlin

I wrote a DSL for defining a finite state machine. My robotics team wants to use a state machine to manage the state of the subsystems on our robot, like the arms, drive train, lifter, etc. Each ...
7
votes
1answer
1k views

Implementation of tokenizer object and finite state machine in C

I was given an assignment to create an implementation of a tokenizer object (by object, I mean a struct with associated functions that operate on instances of the struct). This tokenizer retrieves ...
5
votes
1answer
83 views

UTF8 Codepoint decode and length v.2

This is the complete rewrite of a function to decode an UTF-8 codepoints and return the encoding length (or 0 if the codepoint is ...
0
votes
1answer
55 views

Controller method to modify Active Directory, other systems, and send notification with error handling

I have to handle an Action (Modify) about my web application. The app working with SMTP Email, ActiveDirectory, External System (...
6
votes
2answers
1k views

Simple ini file parser

The below is a C++ parser for a reasonably simple INI grammar (although my understanding is that there isn't an official spec as such). My grammar is roughly: ...
3
votes
0answers
375 views

Linear finite state machine in ES6

I would love some feedback on my linear finite state machine. I say linear, as it can only handle one state at a time. I am also giving my method of how I -work- with the state machine, as I would ...
3
votes
0answers
36 views

Backbone.model based state machine

I have created a class to keep track of some internal states. You can see it as a very simple implementation of a state machine ...
10
votes
1answer
260 views

Parse regular expression

Task: This function searches given null terminated string pStr by given subset of regular expression pMatch. Return value is ...
5
votes
1answer
1k views

Simulate Turing machine

I have written this code to simulate a Turing machine and wonder what could be improved. In particular, the --tape.end() seems a bit dodgy. ...
0
votes
1answer
2k views

Table-Driven Finite State Machine

I'm writing a finite state machine based on a transition table in C++ 14. My code so far looks like: ...
2
votes
1answer
172 views

NFA and DFA implementation

Can you review my F# code and point out some insights about it? What I want to know, in order of relevance: Avoid so much common code between DFA and NFA. I want to make something more generic, ...
1
vote
0answers
227 views

Deterministic finite automaton in Java - follow-up

(See the initial and first iteration for description and motivation.) Now I have incorporated all the remarks made by Tunaki, and it looks like this: TransitionFunction.java: ...
7
votes
1answer
6k views

Deterministic finite automaton in Java

Formally, a deterministic finite automaton is a 5-tuple \$M = (Q, \Sigma, \delta, q_0, F)\$, where \$Q\$ is the set of all possible states \$\Sigma\$ is the alphabet \$\delta \colon Q \times \Sigma \...