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.

Filter by
Sorted by
Tagged with
6
votes
1answer
781 views

Finite State Machine supporting shortest path transitions

In our automated test framework, written in Java 8, there are different entities representing test data, having different states and transitions between them. To model this behavior, I started to ...
1
vote
0answers
21 views

State machine to handle sequential and async events

I created this state machine to handle events. I'm unsure about my implementation firstly because I don't use a transition table or anything like that, instead, I ...
9
votes
2answers
859 views

Hierarchical State Machine in F#

I appreciate any feedback on where I might alter or improve my code for this project. This is an old attempt at implementing a Hierarchical State Machine in F#. I'm from a C#/OO background mostly. <...
6
votes
5answers
254 views

Simple tokenizer v2 - reading all matching chars at once

I have rewritten my tokenizer according to most of the suggestions from the previous question here. API It now reads all chars as long as they match the pattern. I use three types of attributes to ...
3
votes
2answers
243 views

Simple tokenizer v1 - reading char by char

I was feeling like writing a new Uri parser. The previous one was too limited and wasn't able to parse the authority part. This one is also based on the pretty ...
2
votes
1answer
49 views

A Simplistic Finite State Machine Generator

I have designed a compile time Finite State Machine generator. I have chosen to use some of the features of C++17 such as parameter pack expansion, fold expressions and lambdas to keep the complexity ...
2
votes
1answer
197 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 ...
16
votes
9answers
2k views

Increase difficulty based on score

What I'm trying to do is very straightforward and easy, but I am wondering whether there is a more elegant solution. Basically I have a game and I want the difficulty to increase the moment the ...
4
votes
2answers
47 views

Extract lines under the specified heading

I wrote the following working code, which I just can't stomach: ...
3
votes
1answer
71 views

Finite state machine for chasing and attacking a target

My questions are: How can I improve my implementation of the FSM model? Should Finite State Machines have functionality for Adding and Removing states from table? (Since I can only be in one state at ...
10
votes
5answers
3k views

Turing Machine in C#

I've tried designing a Turing Machine model, it works quite well, however I think it could be confusing to maintain on in the future, and I'm not sure what of best practices. Can I get some feedback ...
3
votes
1answer
56 views

State machine translates text into executable python code [v2]

A few days ago I started writing my own compiler-like program which has the goal to compile plain text into executable python code. After I let my first version review here, I made huge changes to the ...
6
votes
1answer
53 views

F# pattern matching to determine the state of a bank account based on past events

I am writing an event sourced system in which I need to have the state based on the events that already occurred for a given bank account. The events are defined such as: ...
4
votes
1answer
448 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
2answers
162 views

Turing machine schoolwork

Our teacher doesn't give much feedback on our code itself. Was just looking for some feedback on how I could improve on this. This is the method that tests the string against the Turing machine that ...
4
votes
1answer
66 views

Implementing Hangman using a State Pattern

I decided to implement a Hangman game using an object oriented State Pattern design. This is one of my first actual OOP as I normally write functional code. Code use: ...
6
votes
4answers
578 views

State machine for handling Telnet sequences for an FTP server

I've asked Code Climate to generate metrics for the ftpd Ruby gem. It correctly identified the God class; I know what to do about that. But one of the smaller classes has me stumped. This is telnet....
1
vote
0answers
23 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 ...
7
votes
1answer
225 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 ...
2
votes
1answer
98 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 ...
4
votes
3answers
600 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 ...
9
votes
1answer
865 views

Simple parsing for string formatting (version 2)

This is my second attempt (version 1) at writing a string formatting utility which uses parsing. This time I more explicitly designed it as a finite state machine. I have very little experience with ...
3
votes
1answer
241 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 ...
3
votes
0answers
61 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
145 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
234 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 ...
13
votes
2answers
235 views

Vending Machine in Idris

Type Driven Development with Idris demonstrates how Idris can be used to build a Finite State Machine for a vending machine. Please critique my implementation. I'm new to dependent types, so I'm not ...
4
votes
0answers
629 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
71 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: ...
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 ...
2
votes
1answer
141 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 ...
2
votes
1answer
234 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: ...
1
vote
1answer
347 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 ...
1
vote
0answers
37 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 ...
4
votes
1answer
6k views

C++ program that recognizes a context-free language

This program (C++) was for a class project. A program that recognizes a given context-free language by implementing a pushdown-automaton (PDA). The PDA recognizes the following language: S → $T$ ...
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 ...
2
votes
0answers
54 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: ...
3
votes
2answers
843 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 ...
2
votes
1answer
547 views

Stack-based state machine

Is everything alright with this code? What can I add to it? state.h: ...
5
votes
2answers
189 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 ...
13
votes
2answers
12k 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
577 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 ...
14
votes
1answer
30k views

State pattern + C++ template

This finds its origin in the following reflection. In their book from 1995, the so-called gang of four (GoF) described the state pattern. What they were actually telling us in their description, is ...
6
votes
1answer
73 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 ...
0
votes
2answers
123 views

Stateful implementation of TicTacToe

I made a TicTacToe implementation using State pattern in Java. I was wondering if this could ...
4
votes
1answer
349 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 ...
1
vote
2answers
125 views

Performing API calls from a mobile client, reauthorizing the session if necessary

I'm working on mobile app which doing requests to a server's API. I want to develop module that doing following: get authorization key already exists in previous session connect to server api and ...
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. ...
3
votes
0answers
79 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?...
2
votes
0answers
48 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?...