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
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
2k 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
384 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
38 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
275 views

Parse regular expression

Task: This function searches given null terminated string pStr by given subset of regular expression pMatch. Return value is ...
6
votes
1answer
2k 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
176 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
249 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
7k 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 \...
3
votes
1answer
267 views

Finite state machine written in OCaml to test for the sequence 0,1

I got inspired by Stack Overflow to build a simple state machine which can test if a sequence contains 0,1. I have two questions: How can I get rid of line ...
2
votes
1answer
650 views

Building thermostat state machine in Python

I used a Raspberry Pi and Adafruit LCD with buttons to build a small thermostat for my house. This is the hardware I used to you can imagine how the button and the code work: https://www.adafruit.com/...
5
votes
2answers
115 views

Finding if there exists an input for a given automata for which no matter what the starting state is, final state would be same everytime

I am solving a puzzle (Finding if there exists an input for a given automata for which no matter what the starting state is, final state would be same everytime) and have written following Python code....
6
votes
1answer
251 views

Chat room using GenServer

It seems odd that state must be passed around all the time. Can't State module hold itself, so I could do something like ...
11
votes
2answers
164 views

Using state transitions to filter C comments

This is my second attempt at K&R 1-23, Write a program to remove all comments from a C program. Don't forget to handle quoted strings and character constants properly. C comments don't nest....
4
votes
1answer
545 views

Asynchronous start/stop state transitions

I have a third-party object with asynchronous start and stop methods. Each start and stop may fail with exception. The object is not re-entrant, i.e. I can only call its start or stop method after the ...
5
votes
1answer
931 views

Model of an mp3 player with state and prototype design patterns

After reading about design patterns in general, I decided to try and incorporate them in an actual program. I chose a State machine for my first exercise, or, more concretely, an MP3 player. The ...
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 ...
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 ...
1
vote
1answer
124 views

Node.js drawing game based off of my state diagram

I really want to have a nice design pattern for my Node.js project. This is my state diagram. As I'm coding this, I'm wondering if it's better to separate state logic from the class? So instead I ...
3
votes
1answer
290 views

POP3 message downloader using state machine processor

This simple program uses a socket class I wrote, class socket, to retrieve a users pop3 emails and print to stdout. I would like feedback on the socket class and the code to download the pop3 emails. ...
3
votes
2answers
504 views

Solving game state with polymorphism

I've been working on a small game as a hobby, and I've been having trouble finding a good way to control the state of the game that could scale easily. I couldn't find a solution that I felt was ...
5
votes
3answers
4k views

State machine implementation

I have written a simple state machine. Comments and feedback are welcome. ...
4
votes
0answers
831 views

C++ Finite State Machine - follow-up

This question is a follow-up from Object Oriented Finite State Machine. I vastly improved commenting and followed the suggestions from the answer. Additionally, I improved my tests and did some more ...
2
votes
1answer
1k views

Object Oriented Finite State Machine

I wrote a little library for myself: implementing a generic finite state machine. I will be using this library in class assignments. I clearly have little understanding of C++ templates because most ...
6
votes
1answer
105 views

Input processing/state machine function

I'm making a Mario clone in pygame and I have just wrote a function proccesses inputs and acts as a state machine for Mario. Everything is working just as I want it, but I was wondering if you can ...
12
votes
1answer
4k views

Robot toy simulator

I have already flunked the test with this code so don't feel bad for cheating any employer. I didn't get any feedback though just wondering what could have gone wrong. You don't need to get into the ...
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 ...
3
votes
1answer
383 views

Finite state machine for CSV data

I want to read a file containing comma-separated values, so have written a finite state machine: ...
12
votes
1answer
209 views

NotBF - A Brainfuck-ish like “language”

I've made an interpreted language that's like Brainfuck except it has keywords instead of characters. Here's an explanation of the commands, and how to run it. ...
5
votes
0answers
2k views

Reducing complexity in NSView event handling code in Swift

My Cocoa event code always tends to descend into madness, I need to advice on how to reduce complexity. I've spend a few hours putting this example together. CanvasView is a layer hosting subclass of ...
2
votes
1answer
41 views

Is it bad practice to have executable code in my channel state object?

I have a CommunicationStateMachine object that's attached to my channels. It keeps track of who's turn it is to speak, how far along the conversation the server and ...
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
116 views

Extracting dynamic behaviors of state machines to modules

This is my initial class. (I am not trying to reinvent state-flows again, just practicing) As you can see straight forward, it dynamically generates methods like .recommend,.recommend!, ....
4
votes
1answer
99 views

Using atom to reference state in Clojure

I am trying to implement a 2D fighting game in Clojure both for fun and learning. Since the characters in a fighter game are essentially state machines, I constructed the following code: ...
2
votes
1answer
764 views

Very basic shell on microcontroller in C - follow-up

This is a follow-up of: Very basic shell on microcontroller in C A few days back I've asked for a review on a simple shell parser in c. Based on the answers, I've restructured my code to use a table-...
5
votes
2answers
4k views

State Transition Table

I wrote a transition table which allows the client to: Create States Create a TransitionTable or some kind of ...
4
votes
1answer
829 views

Tic-Tac-Toe game using erlang gen_fsm

I would like to use erlang to create an online, web-based game. I thought it would make sense to start with something easy, so I chose tic-tac-toe (which seems like a popular choice here). I am ...
2
votes
2answers
76 views

One dimension cellular automation in Python

Here is my implementation for one dimensional cellular automation in Python. Any suggestions for more efficiency - other strategies? ...
12
votes
1answer
2k views

DFA and NFA in Haskell

I've written a determinstic & non-deterministic finite state machine. I've scrubbed the code quite a bit but I wonder if it could perhaps be scrubbed even more. Suggestions for code clarity, ...
3
votes
1answer
703 views

Game State Engine

Can you improve my state engine which consists of the state engine based on an interface and an example menustate? It all works fine but seems a bit cumbersome in terms of the way I have to change ...
8
votes
2answers
401 views

Playing a game throughout the house

Target I wrote this program in a few free hours when I was on an excursion as "youth leader". I had created a game to explore the house, with a 40-field mechanic, using dice for advancing and ...
8
votes
2answers
420 views

Does this simulation follow abstraction and encapsulation?

This below code implements a simulation of an ocean(as 2d-array of cells) which currently have Shark, fish or be Empty. User can run this simulation, as shown below: ...
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 ...
3
votes
2answers
1k views

Parsing a text file of nested structures using a state machine

My goal is to have something really simple with as small an amount of code as possible. The real code is used to parse a text file of nested structures. This code is highly simplified but is the ...
8
votes
1answer
460 views

Member function state machine

For various reasons, I wrote this. For one, I don't like to wrap every single function in a separate class, which is too verbose. It's a state machine based on GoTW 57 function pointer wrapping and ...
3
votes
1answer
1k views

Simple Javascript state management class

So I needed very basic state management and notification for a small game-like thing I'm building. I decided to implement something like a finite state machine (but not quite, it doesn't transition ...
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 ...
7
votes
1answer
270 views

Implementation of interface within state machine

This particular example is verilog, but my question is more about the state machine structuring, which would be relevant to both VHDL and verilog. So if I have a state machine, this one is fairly ...
5
votes
2answers
17k views

Designing simple state machine in C++

I have designed a simple state machine for the following diagram: I am seeking improvements from the community. I especially don't like two things: When calling ...