Search Results

Search found 10851 results on 435 pages for 'state diagram'.

Page 1/435 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Maintaining State in Mud Engine

    - by Johnathon Sullinger
    I am currently working on a Mud Engine and have started implementing my state engine. One of the things that has me troubled is maintaining different states at once. For instance, lets say that the user has started a tutorial, which requires specific input. If the user types "help" I want to switch in to a help state, so they can get the help they need, then return them to the original state once exiting the help. my state system uses a State Manager to manage the state per user: public class StateManager { /// <summary> /// Gets the current state. /// </summary> public IState CurrentState { get; private set; } /// <summary> /// Gets the states available for use. /// </summary> /// <value> public List<IState> States { get; private set; } /// <summary> /// Gets the commands available. /// </summary> public List<ICommand> Commands { get; private set; } /// <summary> /// Gets the mob that this manager controls the state of. /// </summary> public IMob Mob { get; private set; } public void Initialize(IMob mob, IState initialState = null) { this.Mob = mob; if (initialState != null) { this.SwitchState(initialState); } } /// <summary> /// Performs the command. /// </summary> /// <param name="message">The message.</param> public void PerformCommand(IMessage message) { if (this.CurrentState != null) { ICommand command = this.CurrentState.GetCommand(message); if (command is NoOpCommand) { // NoOperation commands indicate that the current state is not finished yet. this.CurrentState.Render(this.Mob); } else if (command != null) { command.Execute(this.Mob); } else if (command == null) { new InvalidCommand().Execute(this.Mob); } } } /// <summary> /// Switches the state. /// </summary> /// <param name="state">The state.</param> public void SwitchState(IState state) { if (this.CurrentState != null) { this.CurrentState.Cleanup(); } this.CurrentState = state; if (state != null) { this.CurrentState.Render(this.Mob); } } } Each of the different states that the user can be in, is a Type implementing IState. public interface IState { /// <summary> /// Renders the current state to the players terminal. /// </summary> /// <param name="player">The player to render to</param> void Render(IMob mob); /// <summary> /// Gets the Command that the player entered and preps it for execution. /// </summary> /// <returns></returns> ICommand GetCommand(IMessage command); /// <summary> /// Cleanups this instance during a state change. /// </summary> void Cleanup(); } Example state: public class ConnectState : IState { /// <summary> /// The connected player /// </summary> private IMob connectedPlayer; public void Render(IMob mob) { if (!(mob is IPlayer)) { throw new NullReferenceException("ConnectState can only be used with a player object implementing IPlayer"); } //Store a reference for the GetCommand() method to use. this.connectedPlayer = mob as IPlayer; var server = mob.Game as IServer; var game = mob.Game as IGame; // It is not guaranteed that mob.Game will implement IServer. We are only guaranteed that it will implement IGame. if (server == null) { throw new NullReferenceException("LoginState can only be set to a player object that is part of a server."); } //Output the game information mob.Send(new InformationalMessage(game.Name)); mob.Send(new InformationalMessage(game.Description)); mob.Send(new InformationalMessage(string.Empty)); //blank line //Output the server MOTD information mob.Send(new InformationalMessage(string.Join("\n", server.MessageOfTheDay))); mob.Send(new InformationalMessage(string.Empty)); //blank line mob.StateManager.SwitchState(new LoginState()); } /// <summary> /// Gets the command. /// </summary> /// <param name="message">The message.</param> /// <returns>Returns no operation required.</returns> public Commands.ICommand GetCommand(IMessage message) { return new NoOpCommand(); } /// <summary> /// Cleanups this instance during a state change. /// </summary> public void Cleanup() { // We have nothing to clean up. return; } } With the way that I have my FSM set up at the moment, the user can only ever have one state at a time. I read a few different posts on here about state management but nothing regarding keeping a stack history. I thought about using a Stack collection, and just pushing new states on to the stack then popping them off as the user moves out from one. It seems like it would work, but I'm not sure if it is the best approach to take. I'm looking for recommendations on this. I'm currently swapping state from within the individual states themselves as well which I'm on the fence about if it makes sense to do there or not. The user enters a command, the StateManager passes the command to the current State and lets it determine if it needs it (like passing in a password after entering a user name), if the state doesn't need any further commands, it returns null. If it does need to continue doing work, it returns a No Operation to let the state manager know that the state still requires further input from the user. If null is returned, the state manager will then go find the appropriate state for the command entered by the user. Example state requiring additional input from the user public class LoginState : IState { /// <summary> /// The connected player /// </summary> private IPlayer connectedPlayer; private enum CurrentState { FetchUserName, FetchPassword, InvalidUser, } private CurrentState currentState; /// <summary> /// Renders the current state to the players terminal. /// </summary> /// <param name="mob"></param> /// <exception cref="System.NullReferenceException"> /// ConnectState can only be used with a player object implementing IPlayer /// or /// LoginState can only be set to a player object that is part of a server. /// </exception> public void Render(IMob mob) { if (!(mob is IPlayer)) { throw new NullReferenceException("ConnectState can only be used with a player object implementing IPlayer"); } //Store a reference for the GetCommand() method to use. this.connectedPlayer = mob as IPlayer; var server = mob.Game as IServer; // Register to receive new input from the user. mob.ReceivedMessage += connectedPlayer_ReceivedMessage; if (server == null) { throw new NullReferenceException("LoginState can only be set to a player object that is part of a server."); } this.currentState = CurrentState.FetchUserName; switch (this.currentState) { case CurrentState.FetchUserName: mob.Send(new InputMessage("Please enter your user name")); break; case CurrentState.FetchPassword: mob.Send(new InputMessage("Please enter your password")); break; case CurrentState.InvalidUser: mob.Send(new InformationalMessage("Invalid username/password specified.")); this.currentState = CurrentState.FetchUserName; mob.Send(new InputMessage("Please enter your user name")); break; } } /// <summary> /// Receives the players input. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> void connectedPlayer_ReceivedMessage(object sender, IMessage e) { // Be good memory citizens and clean ourself up after receiving a message. // Not doing this results in duplicate events being registered and memory leaks. this.connectedPlayer.ReceivedMessage -= connectedPlayer_ReceivedMessage; ICommand command = this.GetCommand(e); } /// <summary> /// Gets the Command that the player entered and preps it for execution. /// </summary> /// <param name="command"></param> /// <returns>Returns the ICommand specified.</returns> public Commands.ICommand GetCommand(IMessage command) { if (this.currentState == CurrentState.FetchUserName) { this.connectedPlayer.Name = command.Message; this.currentState = CurrentState.FetchPassword; } else if (this.currentState == CurrentState.FetchPassword) { // find user } return new NoOpCommand(); } /// <summary> /// Cleanups this instance during a state change. /// </summary> public void Cleanup() { // If we have a player instance, we clean up the registered event. if (this.connectedPlayer != null) { this.connectedPlayer.ReceivedMessage -= this.connectedPlayer_ReceivedMessage; } } Maybe my entire FSM isn't wired up in the best way, but I would appreciate input on what would be the best to maintain a stack of state in a MUD game engine, and if my states should be allowed to receive the input from the user or not to check what command was entered before allowing the state manager to switch states. Thanks in advance.

    Read the article

  • Using the Items collection for state management

    - by nikolaosk
    I have explained some of the state mechanisms that we have in our disposal for preserving state in ASP.Net applications in various posts in this blog. You can have a look at this post , this post , this post and this one .My last post was on Application state management and you can read it here . In this post I will show you how to preserve state using the Items collection. Many developers do not know that we have this option as well for state management. With Items state we can pass data between...(read more)

    Read the article

  • Memento with optional state?

    - by Korey Hinton
    EDIT: As pointed out by Steve Evers and pdr, I am not correctly implementing the Memento pattern, my design is actually State pattern. Menu Program I built a console-based menu program with multiple levels that selects a particular test to run. Each level more precisely describes the operation. At any level you can type back to go back one level (memento). Level 1: Server Type? [1] Server A [2] Server B Level 2: Server environment? [1] test [2] production Level 3: Test type? [1] load [2] unit Level 4: Data Collection? [1] Legal docs [2] Corporate docs Level 4.5 (optional): Load Test Type [2] Multi TIF [2] Single PDF Level 5: Command Type? [1] Move [2] Copy [3] Remove [4] Custom Level 6: Enter a keyword [setup, cleanup, run] Design States PROBLEM: Right now the STATES enum is the determining factor as to what state is BACK and what state is NEXT yet it knows nothing about what the current memento state is. Has anyone experienced a similar issue and found an effective way to handle mementos with optional state? static enum STATES { SERVER, ENVIRONMENT, TEST_TYPE, COLLECTION, COMMAND_TYPE, KEYWORD, FINISHED } Possible Solution (Not-flexible) In reference to my code below, every case statement in the Menu class could check the state of currentMemo and then set the STATE (enum) accordingly to pass to the Builder. However, this doesn't seem flexible very flexible to change and I'm struggling to see an effective way refactor the design. class Menu extends StateConscious { private State state; private Scanner reader; private ServerUtils utility; Menu() { state = new State(); reader = new Scanner(System.in); utility = new ServerUtils(); } // Recurring menu logic public void startPromptingLoop() { List<State> states = new ArrayList<>(); states.add(new State()); boolean redoInput = false; boolean userIsDone = false; while (true) { // get Memento from last loop Memento currentMemento = states.get(states.size() - 1) .saveMemento(); if (currentMemento == null) currentMemento = new Memento.Builder(0).build(); if (!redoInput) System.out.println(currentMemento.prompt); redoInput = false; // prepare Memento for next loop Memento nextMemento = null; STATES state = STATES.values()[states.size() - 1]; // get user input String selection = reader.nextLine(); switch (selection) { case "exit": reader.close(); return; // only escape case "quit": nextMemento = new Memento.Builder(first(), currentMemento, selection).build(); states.clear(); break; case "back": nextMemento = new Memento.Builder(previous(state), currentMemento, selection).build(); if (states.size() <= 1) { states.remove(0); } else { states.remove(states.size() - 1); states.remove(states.size() - 1); } break; case "1": nextMemento = new Memento.Builder(next(state), currentMemento, selection).build(); break; case "2": nextMemento = new Memento.Builder(next(state), currentMemento, selection).build(); break; case "3": nextMemento = new Memento.Builder(next(state), currentMemento, selection).build(); break; case "4": nextMemento = new Memento.Builder(next(state), currentMemento, selection).build(); break; default: if (state.equals(STATES.CATEGORY)) { String command = selection; System.out.println("Executing " + command + " command on: " + currentMemento.type + " " + currentMemento.environment); utility.executeCommand(currentMemento.nickname, command); userIsDone = true; states.clear(); nextMemento = new Memento.Builder(first(), currentMemento, selection).build(); } else if (state.equals(STATES.KEYWORD)) { nextMemento = new Memento.Builder(next(state), currentMemento, selection).build(); states.clear(); nextMemento = new Memento.Builder(first(), currentMemento, selection).build(); } else { redoInput = true; System.out.println("give it another try"); continue; } break; } if (userIsDone) { // start the recurring menu over from the beginning for (int i = 0; i < states.size(); i++) { if (i != 0) { states.remove(i); // remove all except first } } reader = new Scanner(System.in); this.state = new State(); userIsDone = false; } if (!redoInput) { this.state.restoreMemento(nextMemento); states.add(this.state); } } } }

    Read the article

  • Java code generation from class diagram

    - by Sanjay
    I'm on the way developing a Java application where user can provide a class diagram and get the corresponding Java code. I don't know how can I let the user interactively draw a class diagram in Java. I am currently getting the required parameters like attributes, functions directly from the user, and then I render a class diagram for him. I show the class diagram on a jdialog. Is there a better way to do this? This is an example of a class diagram, I need to generate this from a Java program, given the values and relationship.

    Read the article

  • UML class diagram vs ER database diagram

    - by salva84
    Hi, I'm a little confused, I'm developing a program, the program consist in two parts, the server and the clients, there are groups, places, messages... stored in the server, and the clients has to connect with it. I've design the use cases diagram, the activity diagrams, and I have design the class diagram too. The thing is that I want to implement the server in a mysql tables for storing the users, groups, places... users in groups... so I've designed a E-R diagram consisting in 6 tables, but the problem is that I think that my class diagram and my ER diagram looks too similar, I mean, I think I'm not doing things right because I have a class for each table practically, and when I have to extract all the users on my system, do I have to convert all the rows into objects at first and write in the database for each object modified? The easy choice for me would be to base my whole application only in the database, and making a class to extract and insert data in it, but I have to follow the UML specification and I'm a little confused what to do with the class diagram, because the books I have read say that I have to create a class for each "entity" of my program. Sorry for my bad English. Thank you.

    Read the article

  • Alternative to Game State System?

    - by Ricket
    As far as I can tell, most games have some sort of "game state system" which switches between the different game states; these might be things like "Intro", "MainMenu", "CharacterSelect", "Loading", and "Game". On the one hand, it totally makes sense to separate these into a state system. After all, they are disparate and would otherwise need to be in a large switch statement, which is obviously messy; and they certainly are well represented by a state system. But at the same time, I look at the "Game" state and wonder if there's something wrong about this state system approach. Because it's like the elephant in the room; it's HUGE and obvious but nobody questions the game state system approach. It seems silly to me that "Game" is put on the same level as "Main Menu". Yet there isn't a way to break up the "Game" state. Is a game state system the best way to go? Is there some different, better technique to managing, well, the "game state"? Is it okay to have an intro state which draws a movie and listens for enter, and then a loading state which loops on the resource manager, and then the game state which does practically everything? Doesn't this seem sort of unbalanced to you, too? Am I missing something?

    Read the article

  • C# - Coding a nested stateflow diagram

    - by weberc2
    I have the following state diagram. I know how to make a simple state machine that transitions between non-nested states; however, I don't know how to transition between nested states. Could someone explain how to do this at an appropriately high level (i.e., you don't need to write the code for me--unless you're feeling particularly generous :P). State Diagram [EDIT: The bottom "A", "C", and "E" should be "B", "D", and "F" respectively; sorry!] What I know how to do public class MyState : State // State enumeration { public static MyState A = new MyState("State A"); public static MyState B = new MyState("State B"); public static MyState C = new MyState("State C"); public static MyState D = new MyState("State D"); public static MyState E = new MyState("State E"); public static MyState F = new MyState("State F"); public static MyState NEUT = new MyState("Neutral"); public static MyState P = new MyState("P"); protected MyState(string name) : base(name) { } } public class MyEvent : Event // Event enumeration { public static MyEvent X_POS = new MyEvent("X+"); public static MyEvent X_NEG = new MyEvent("X-"); public static MyEvent Y_POS = new MyEvent("Y+"); public static MyEvent Y_NEG = new MyEvent("Y-"); protected MyEvent(string name) : base(name) { } } public class MyStateMachine : StateMachine<MyState, MyEvent> // State Machine implementation { public MyStateMachine() : base(MyState.P) // MyState.P = initial state { // Set up the transition table // P this.addTransition(MYState.P, MyState.NEUT, MyEvent.Y_NEG); // NEUTRAL this.addTransition(MyState.NEUT, MyState.P, MyEvent.Y_POS); this.addTransition(MyState.NEUT, MyState.A, MyEvent.Y_NEG); this.addTransition(MyState.NEUT, MyState.B, MyEvent.Y_POS); this.addTransition(MyState.NEUT, MyState.C, MyEvent.Y_NEG); this.addTransition(MyState.NEUT, MyState.D, MyEvent.Y_POS); this.addTransition(MyState.NEUT, MyState.E, MyEvent.Y_NEG); this.addTransition(MyState.NEUT, MyState.F, MyEvent.Y_POS); // A this.addTransition(MyState.A, MyState.NEUT, MyEvent.Y_POS); // B this.addTransition(MyState.B, MyState.NEUT, MyEvent.Y_NEG); // C this.addTransition(MyState.C, MyState.NEUT, MyEvent.Y_POS); // D this.addTransition(MyState.D, MyState.NEUT, MyEvent.Y_NEG); // E this.addTransition(MyState.E, MyState.NEUT, MyEvent.Y_POS); // F this.addTransition(MyState.F, MyState.NEUT, MyEvent.Y_NEG); } public void move(MyEvent eevent) { try { this.moveNext(eevent); } catch (Exception e) { } } }

    Read the article

  • How to visualize timer functionality in sequence diagram?

    - by truthseeker
    I am developing software for communication with external device through serial port. To better understand the new functionality I am trying to display it in sequence diagram. Flow of events is as follows. I send to the device command to reset it. This is asynchronous operation so there is some delay between request and response (typically 100 ms). There can be case when the answer never comes (for example device is not connected to the specified port or is currently turned off). For this purpose I create a timer with period twice the maximum answer time. In my case it is 2 * 125 ms = 250 ms. If the answer comes in predefined time interval, I destroy already running timer. If the answer doesnt come in predefined interval, timer initiates some action. After this action we can destroy it. How to effectively model this situation in sequence diagram? Addendum 1: Based on advices made by scarfridge i drew following UML diagram. Comment by Ozair is also helpful for simplifying the diagram even more.

    Read the article

  • What alternative is better to diagram this scenario?

    - by Mosty Mostacho
    I was creating and discussing a class diagram with a partner of mine. To simplify things, I've modify the real domain we're working on and made up the following diagram: Basically, a company works on constructions that are quite different one from each other but are still constructions. Note I've added one field for each class but there should be many more. Now, I thought this was the way to go but my partner told me that if in the future new construction classes appear we would have to modify the Company class, which is correct. So the new proposed class diagram would be this: Now I've been wondering: Should the fact that in no place of the application will there be mixed lists of planes and bridges affect the design in any way? When we have to list only planes for a company, how are we supposed to distinguish them from the other elements in the list without checking for their class names? Related to the previous question, is it correct to assume that this type of diagram should be high-level and this is something it shouldn't matter at this stage but rather be thought and decided at implementation time? Any comment will be appreciated.

    Read the article

  • How does a "Variables introduce state"?

    - by kunj2aan
    I was reading the "C++ Coding Standards" and this line was there: Variables introduce state, and you should have to deal with as little state as possible, with lifetimes as short as possible. Doesn't anything that mutates eventually manipulate state? What does "you should have to deal with little state as possible" mean? In an impure language such as C++, isn't state management really what you are doing? And what are other ways to "deal with as little state as possible" other than limiting variable lifetime?

    Read the article

  • Visualize flowchart diagram with multiple end symbols

    - by platzhirsch
    I am looking for a standardize way to visualize the following hierarchical logic: The state of the thread is represented by the answers to the hierarchical set of question You can read this listing like a flowchart, you iterate over the questions decide, go one step deeper and so on. Therefore I thought the best way to visualize it, using a flowchart. The problem is, in this hierarchical set it is possible to end in more than one state and its totally valid. I have never seen a flowchart where you can enter more than one state. Is it still possible and I am missing the right symbol to present this logic or are flowchart not fitting anyway? What other graphical representation could I use, is there something fitting in UML? A non-deterministic state machine seems not to be intuitive enough, transfering it into a deterministic state machine would result in to many states, and so on.

    Read the article

  • Visualize flowchart diagram with multiple end symbols

    - by platzhirsch
    I am looking for a standardize way to visualize the following hierarchical logic: The state of the thread is represented by the answers to the hierarchical set of question You can read this listing like a flowchart, you iterate over the questions decide, go one step deeper and so on. Therefore I thought the best way to visualize it, using a flowchart. The problem is, in this hierarchical set it is possible to end in more than one state and its totally valid. I have never seen a flowchart where you can enter more than one state. Is it still possible and I am missing the right symbol to present this logic or are flowchart not fitting anyway? What other graphical representation could I use, is there something fitting in UML? A non-deterministic state machine seems not to be intuitive enough, transfering it into a deterministic state machine would result in to many states, and so on.

    Read the article

  • which should be drawn first , class or sequence diagram?

    - by m0j1
    hi , I've had this discussion with my professor at college about UML diagrams . hi believes that sequence diagrams should be drawn before getting to class diagrams . but I think the opposite . I think after finishing the usecase diagram , the next diagram should be class diagram and after that we should get to sequence diagram . Rational rose requires us to use the classes in sequence diagram, which are already in class diagram . can anyone help me with this? thanks

    Read the article

  • IIS 7 and ASP.NET State Service Configuration

    - by Shawn
    We have 2 web servers load balanced and we wanted to get away from sticky sessions for obvious reasons. Our attempted approach is to use the ASP.NET State service on one of the boxes to store the session state for both. I realize that it's best to have a server dedicated to storing sessions but we don't have the resources for that. I've followed these instructions to no avail. The session still isn't being shared between the two servers. I'm not receiving any errors. I have the same machine key for both servers, and I've set the application ID to a unique value that matches between the two servers. Any suggestions on how I can troubleshoot this issue? Update: I turned on the session state service on my local machine and pointed both servers to the ip address on my local machine and it worked as expected. The session was shared between both servers. This leads me to believe that the problem might be that I'm not using a standalone server as my state service. Perhaps the problem is because I am using the ip address 127.0.0.1 on one server and then using a different ip address on the other server. Unfortunately when I try to use the network ip address as opposed to localhost the connection doesn't seem to work from the host server. Any insight on whether my suspicions are correct would be appreciated.

    Read the article

  • State management using the Application class in ASP.Net applications

    - by nikolaosk
    I have explained some of the state mechanisms that we have in our disposal for preserving state in ASP.Net applications in various posts in this blog. You can have a look at this post , this post , this post and this one . I have not presented yet an example in using the Application class/object for preserving state within our application. Application state is available globally in an application.The way we access Application State is through the HttpApplication object's Application property. Let...(read more)

    Read the article

  • Making Class Diagram for MVC Pattern Project

    - by iMohammad
    I have a question about making a class diagram for an MVC based college senior project. If we have 2 actors of users in my system, lets say Undergrad and Graduate students are the children of abstract class called User. (Generalisation) Each actor has his own features. My question, in such case, do we need to have these two actors in separate classes which inherits from the abstract class User? even though, I'm going to implement them as roles using one Model called User Model ? I think you can see my confusion here. I code using MVC pattern, but I've never made a class diagram for this pattern. Thank you in advance!

    Read the article

  • State pattern: Why doesn't the context class implement or inherit the State abstract interface/class

    - by Ricket
    I'm reading about the State pattern. I have only just begun, so of course I begin by reading the entire Wikipedia article on it. I noticed that both of the examples in the article have some base abstract class or Java interface for a generic State's methods/functions. Then there are some states which inherit from the base and implement those methods/functions in different ways. Then there's a Context class which has a private member of type State and which, at any time, can be equal to an instance of one of the implementations. That context class also implements the same methods, and passes them onto the current state instance, and then has an additional method to change the state (or depending on design I understand the change of state could be a reaction to one of the implemented methods). Why doesn't this context class specifically "extend" or "implement" the generic State base class/interface?

    Read the article

  • Using both IIS6 and IIS7 with the same SQL State Server

    - by Josef
    We are trying to use new IIS7 (32bit, Classic Mode) webs in addition to our IIS6 webs with one SQL State Server for ASP.NET Session Handling. Unfortunately the number of transactions per seconds in the State Servers spikes (10 times+) as soon as we add the new IIS7 web to the farm. Are there any known issues with the described setup?

    Read the article

  • Is my sequence diagram correct?

    - by Dummy Derp
    NOTE: I am self studying UML so I have nobody to verify my diagrams and hence I am posting here, so please bear with me. This is the problem I got from some PDF available on Google that simply had the following problem statement: Problem Statement: A library contains books and journals. The task is to develop a computer system for borrowing books. In order to borrow a book the borrower must be a member of the library. There is a limit on the number of books that can be borrowed by each member of the library. The library may have several copies of a given book. It is possible to reserve a book. Some books are for short term loans only. Other books may be borrowed for 3 weeks. Users can extend the loans. Draw a use case diagram for a library. I already drew the Use Case diagram and had it checked by a community member. This time I drew sequence diagrams for borrowing a book and extending the date of return. Please let me know if they are correct. I drew them using Visual Paradigm and I dont know how to keep a control of the sequence numbers. If you do, please let me know :) Diagrams

    Read the article

  • In a state machine, is it a good idea to separate states and transitions?

    - by codablank1
    I have implemented a small state machine in this way (in pseudo code): class Input {} class KeyInput inherits Input { public : enum { Key_A, Key_B, ..., } } class GUIInput inherits Input { public : enum { Button_A, Button_B, ..., } } enum Event { NewGame, Quit, OpenOptions, OpenMenu } class BaseState { String name; Event get_event (Input input); void handle (Event e); //event handling function } class Menu inherits BaseState{...} class InGame inherits BaseState{...} class Options inherits BaseState{...} class StateMachine { public : BaseState get_current_state () { return current_state; } void add_state (String name, BaseState state) { statesMap.insert(name, state);} //raise an exception if state not found BaseState get_state (String name) { return statesMap.find(name); } //raise an exception if state or next_state not found void add_transition (Event event, String state_name, String next_state_name) { BaseState state = get_state(state_name); BaseState next_state = get_state(next_state_name); transitionsMap.insert(pair<event, state>, next_state); } //raise exception if couple not found BaseState get_next_state(Event event, BaseState state) { return transitionsMap.find(pair<event, state>); } void handle(Input input) { Event event = current_state.get_event(input) current_state.handle(event); current_state = get_next_state(event, current_state); } private : BaseState current_state; map<String, BaseState> statesMap; //map of all states in the machine //for each couple event/state, this map stores the next state map<pair<Event, BaseState>, BaseState> transitionsMap; } So, before getting the transition, I need to convert the key input or GUI input to the proper event, given the current state; thus the same key 'W' can launch a new game in the 'Menu' state or moving forward a character in the 'InGame' state; Then I get the next state from the transitionsMap and I update the current state Does this configuration seem valid to you ? Is it a good idea to separate states and transitions ? And I have some kind of trouble to represent a 'null state' or a 'null event'; What initial value can I give to the current state and which one should be returned by get_state if it fails ?

    Read the article

  • Mapping between 4+1 architectural view model & UML

    - by Sadeq Dousti
    I'm a bit confused about how the 4+1 architectural view model maps to UML. Wikipedia gives the following mapping: Logical view: Class diagram, Communication diagram, Sequence diagram. Development view: Component diagram, Package diagram Process view: Activity diagram Physical view: Deployment diagram Scenarios: Use-case diagram The paper Role of UML Sequence Diagram Constructs in Object Lifecycle Concept gives the following mapping: Logical view (class diagram (CD), object diagram (OD), sequence diagram (SD), collaboration diagram (COD), state chart diagram (SCD), activity diagram (AD)) Development view (package diagram, component diagram), Process view (use case diagram, CD, OD, SD, COD, SCD, AD), Physical view (deployment diagram), and Use case view (use case diagram, OD, SD, COD, SCD, AD) which combines the four mentioned above. The web page UML 4+1 View Materials presents the following mapping: Finally, the white paper Applying 4+1 View Architecture with UML 2 gives yet another mapping: Logical view class diagrams, object diagrams, state charts, and composite structures Process view sequence diagrams, communication diagrams, activity diagrams, timing diagrams, interaction overview diagrams Development view component diagrams Physical view deployment diagram Use case view use case diagram, activity diagrams I'm sure further search will reveal other mappings as well. While various people usually have different perspectives, I don't see why this is the case here. Specially, each UML diagram describes the system from a particular aspect. So, for instance, why the "sequence diagram" is considered as describing the "logical view" of the system by one author, while another author considers it as describing the "process view"? Could you please help me clarify the confusion?

    Read the article

  • iptables rules keep showing up

    - by Omriko
    I just installed an ubuntu precise server, after a few weird communications issues I checked the iptables list and found: Chain INPUT (policy DROP) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT tcp -- 10.0.0.0/24 anywhere tcp spts:1024:65535 dpt:ssh state NEW ACCEPT icmp -- anywhere anywhere state NEW ACCEPT icmp -- anywhere anywhere state NEW ACCEPT icmp -- anywhere anywhere state NEW ACCEPT icmp -- anywhere anywhere state NEW DROP tcp -- anywhere anywhere tcp dpt:10520 state NEW DROP udp -- anywhere anywhere udp spts:1:65535 dpt:31337 state NEW DROP udp -- anywhere anywhere udp spts:1:65535 dpt:31338 state NEW DROP udp -- anywhere anywhere udp spts:1:65535 dpt:54320 state NEW DROP udp -- anywhere anywhere udp spts:1:65535 dpt:54321 state NEW DROP tcp -- anywhere anywhere tcp dpt:12345 state NEW DROP tcp -- anywhere anywhere tcp dpt:12346 state NEW DROP tcp -- anywhere anywhere tcp dpt:20034 state NEW DROP tcp -- anywhere anywhere tcp dpt:16600 state NEW DROP tcp -- anywhere anywhere tcp dpt:16660 state NEW DROP tcp -- anywhere anywhere tcp dpt:65000 state NEW DROP udp -- anywhere anywhere udp dpt:34555 state NEW DROP udp -- anywhere anywhere udp dpt:35555 state NEW DROP udp -- anywhere anywhere udp spts:netbios-ns:netbios-dgm dpts:netbios-ns:netbios-dgm state NEW DROP tcp -- anywhere anywhere tcp spts:1024:65535 dpt:netbios-ssn state NEW DROP tcp -- anywhere anywhere tcp spts:1024:65535 dpt:microsoft-ds state NEW DROP udp -- anywhere anywhere udp spt:microsoft-ds dpt:microsoft-ds state NEW DROP udp -- anywhere anywhere udp spts:1024:65535 dpt:microsoft-ds state NEW DROP tcp -- anywhere anywhere tcp spts:1024:65535 dpt:loc-srv state NEW DROP tcp -- anywhere anywhere tcp spts:1024:65535 dpt:5000 state NEW DROP tcp -- anywhere anywhere tcp spts:1024:65535 dpts:1025:1029 state NEW DROP udp -- anywhere anywhere udp spts:1:65535 dpt:loc-srv state NEW ACCEPT tcp -- anywhere anywhere tcp spts:1024:65535 dpt:28082 state NEW DROP all -- anywhere anywhere state NEW Chain FORWARD (policy DROP) target prot opt source destination Chain OUTPUT (policy DROP) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT tcp -- anywhere anywhere tcp spts:tcpmux:65535 dpts:tcpmux:65535 state NEW ACCEPT udp -- anywhere anywhere udp dpts:1:65535 state NEW ACCEPT icmp -- anywhere anywhere state NEW ACCEPT tcp -- anywhere anywhere tcp spts:1024:65535 dpt:28082 state NEW DROP all -- anywhere anywhere state NEW I tried to wipe the rules, I disabled UFW, Ive rewritten and saved iptables rules according to this guide, but every minute or so the old rules return.... I checked crontab for scheduled tasks, there is nothing in there but still these rules appear every minute... please help!

    Read the article

  • Designing a state machine in C++

    - by skyeagle
    I have a little problem that involves modelling a state machine. I have managed to do a little bit of knowledge engineering and 'reverse engineer' a set of primitive deterministic rules that determine state as well as state transitions. I would like to know what the best practises are regarding: How to rigorously test my states and state transitions to make sure that the system cannot end up in an undeetermined state. How to enforce state transition requirements (for example, it should be impossible to go directly from stateFoo to StateFooBar, i.e. to embue each state with 'knowlege' about the states it can transition to. Ideally, I would like to use clean, pattern based design, with templates wherever possible. I do need somewhere to start though and I would be grateful for any pointers (no pun intended), that are sent my way.

    Read the article

  • UML Class Diagram: Abstract or Interface?

    - by J Smith
    I am modeling a class diagram and have spotted an opportunity to simplify it slightly. What I want to know is, would this it be better to implement an abstract class or an interface? The scenario is this, I have the classes: Artist Genre Album Song All of which share the methods getName, setName, and getCount (playcount that is). Would it be best to create an abstract 'Music' class with the aforementioned abstract methods, or should I create an interface, since the classes that implement the interface have to include all of the interface's methods (I think, correct me if I'm wrong). I hope I've given enough detail, please ask questions if I haven't. Thanks!

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >