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
2
votes
1answer
818 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-...
6
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
947 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
91 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
776 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
403 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
442 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
3k 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
536 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
967 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
288 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
18k 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 ...
4
votes
1answer
4k views

State Design Pattern in Python

I'm trying to find the best - read: readable, maintainable, robust, threadsafe, usable - solution for a State Machine in python. For this I've been looking at the State Design Pattern. However I want ...
10
votes
2answers
324 views

Excel-formula-analysis state machine

This is one of my first useful scripts. I run it on a highlighted text selection within Notepad++, but I've provided a sample formula and commented out the Scintilla-specific references. I'm a rank ...
9
votes
2answers
1k 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
1answer
1k views

A variant of state pattern + C++ template FSM without state creation/destruction penalty

This is a variant of the solution posted here, without state creation/destruction penalty. Note that my comment in the original question about the simplification provided by C++11's inherited ...
15
votes
1answer
33k 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
2answers
330 views

Design feedback for automaton to draw a checkerboard pattern

I've just completed the 3rd task of the 1st assignment offered by Stanford's programming methodologies (see the full resources for it here too). I just need some helpful feedback on how my code can ...
3
votes
1answer
119 views

How do I avoid explicit type switching when operation based on state?

I've encountered a problem that I have to solve using dynamic_cast to invoke different functions, depending on the type of class State family. I was re-factoring a ...
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 ...
6
votes
1answer
299 views

Automata theory, state reachability in Haskell

I wrote a small library to learn Haskell while studying Automata theory. I have some concerns on my algorithm to evaluate state reachability. That is, I think it might be improved if I can avoid ...
6
votes
4answers
686 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....
4
votes
1answer
312 views

State Machine for Character

I come today with a state machine I'm currently working on. Problem: Given any State that the Character is in, a button press or combination of button presses can modify that state in a different ...
2
votes
0answers
77 views

String matching

I recently came across a lecture on DFA. I tried to use it to determine whether a given 'search string' is found in the 'input string'. Please tell me if there is a better way. ...
8
votes
2answers
15k views

Designing a state machine in C++ using the STL

I have this working code for C++ state machine using STL (not using boost state chart). The purpose of posting is two-fold: To share a simple and working code C++ state machine using the STL for the ...
24
votes
4answers
11k views

Simple Turing machine simulator

Yesterday I got a sudden urge to go from writing Python to something, well, more UNIX core-ish. I read some examples on here and decided I might as well put some of that stuff to use to test something ...
3
votes
1answer
583 views

State machine for upvoting/downvoting

I have a list of resources which can be voted on. There are 3 voting states: upvoted, downvoted and no vote. In a fashion identical to Stack Exchange voting, it follows these rules: If you upvote a ...
3
votes
1answer
2k views

Sample table-driven finite-state machine

We have interviewees write sample code, but now we want them to modify some simple working code. I came up with the following proposal, which is a syntax-directed interpreter implemented with a table-...

1 2
3