Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Anyone here implemented a state machine in code?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Random spam
View previous topic :: View next topic  
Author Message
Aviar³
Grandmaster Cheater
Reputation: 50

Joined: 03 Jan 2008
Posts: 655
Location: Canada

PostPosted: Sun Mar 03, 2013 8:25 pm    Post subject: Anyone here implemented a state machine in code? Reply with quote

If so, how did you guys go about implementing transitions?
_________________
This is the inception of deception, checking the depth of your perception.
Back to top
View user's profile Send private message
InternetIsSeriousBusiness
Grandmaster Cheater Supreme
Reputation: 8

Joined: 12 Jul 2010
Posts: 1269

PostPosted: Sun Mar 03, 2013 8:25 pm    Post subject: Reply with quote

shadeslayer
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Sun Mar 03, 2013 10:02 pm    Post subject: Reply with quote

global variable
int a = 0;

on an event that moves the state to the next one::
- a++;
- if ( a == 3 ) a = 0;

states are 0 1 and 2

machine states are separated by looking at a
if (a == 0){
//do this
}
else if (a == 1){
//do this
}
else if (a == 2){
//do this
}

___
no?
Back to top
View user's profile Send private message MSN Messenger
Aviar³
Grandmaster Cheater
Reputation: 50

Joined: 03 Jan 2008
Posts: 655
Location: Canada

PostPosted: Sun Mar 03, 2013 10:31 pm    Post subject: Reply with quote

Yeah, hardcoded is the simplest way of doing it, though hardly the optimum way I think. After all, how do you reuse the code? How do you minimize the machine? Etc etc. I'm doing it by having a class for State, StateMachine and Transition. A states simple enough, just a name (and optionally onEntry actions and onExit actions represented by a set of Function objects to be executed) and a statemachine is a collection of states and transitions, the current state and the current input. Transitions are simple in the sense of one having an fromState and toState property, but my problem is modeling the input property which represents what input triggers the transition as well as the best way to capture/represent transitions in a statemachine (for when having to search for what transition to take).

Also I don't think your model/implementation captures the possibility of moving from state 0 to an arbitrary state, such as state 2 or n. Also doesn't capture the idea of moving from a state 2 to a state 1 or 0.

_________________
This is the inception of deception, checking the depth of your perception.


Last edited by Aviar³ on Sun Mar 03, 2013 10:42 pm; edited 1 time in total
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Sun Mar 03, 2013 10:37 pm    Post subject: Reply with quote

I can't really assist you, I would like to but your saying is too general x.x I can not fully understand the problem you are trying to solve.

what I mean is that a "state machine" is too vague of a concept to start trying to come up with a solution.


Last edited by gogodr on Sun Mar 03, 2013 10:39 pm; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
Aviar³
Grandmaster Cheater
Reputation: 50

Joined: 03 Jan 2008
Posts: 655
Location: Canada

PostPosted: Sun Mar 03, 2013 10:39 pm    Post subject: Reply with quote

The problem is representing the concept of statemachines (particularly finite statemachines without epsilon transitions) in a reusable manner. Reusable here means I can, during runtime, add transitions, states and carry out operations on the same (such as minimizing, finding dead states, paths, etc.).
_________________
This is the inception of deception, checking the depth of your perception.
Back to top
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Sun Mar 03, 2013 11:26 pm    Post subject: Reply with quote

just so I dont foget.
Code:
Class Transition{
State start,end;
String trigger;
void Transition(State state1, String input, State state2){
this.start = state1;
this.end = state2;
this.trigger = input;
}
}

class StateMachine{
List<State> states;
List<Transition> transitions;
void addTransition(State state1, String input, State state2){
bool check1,check2;
foreach (State ex in This.states){
if (ex == state1) check1 = true;
if (ex == state2) check2 = true;
}
if(state1 && state2){
transitions.add(new Transition(state1,input,state2));
}
else{
alert("Not valid States");
return
}
}
}
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Random spam All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites