AS Computer Studies Finite State Machines 2 Starter Let’s play the Finite State Pirates Game REQUIRES Teacher Prep Objectives • Understand the stages of problem solving. • Become familiar with finite state machines and their purpose. • Be able to create and construct a state transition table • Be able to construct a decision table Recap • A volunteer: Talk through this state transition diagram. 1, B 1, B State1 Start 0, A 0, A State 0 State2 2, ! 2, ! Recap: Light Switch as a table • State Transitions are one way of describing a finite state machine. Light-switch Down State 0 State 1 Light-switch Up • Another way is a State Transition Table. It shows what states a FSM will move to based on the current state and other inputs. (Note there are NO outputs) Input Current State (S0) Next State (S1) Turn Switch On Light switched off Light switched on Turn Switch Off Light Switched on Light Switched off Quick Task: Creating a State Transition Table (PRINT) Input Current State Output Next State 0 S0 A S0 1 S0 B S1 2 S1 Try and complete the State Transition Table 0 1 2 1, B State 1 Start 0, A 0, A State 0 State 2 2, ! 2, ! 1, B Create your own State Transition Table Input Current State Next State <> 2 S0 (locked) S0 (Locked) 2 S0 (Locked) S1 (First) <> 4 S1 (First) S1 (First) 4 S1 (First) S2 (Second) <> 9 S2 (Second) S2 (Second) 9 S2 (Second) S3 (Unlocked) Complete this State Transition Table based on the briefcase FSM. Note, there are NO outputs. <> = not Decision Tables • When solving logical problems there can be A LOT going on. How do make sure that everything is accounted for? • You use a Decision Table! – Show the outcomes for a given logical condition. • Can you work out what each condition shows: conditions condition alternatives actions action entries Steps to making a decision table 1. Draw boxes for the top and bottom left quadrants. 2. List the conditions in the top, left quadrant. When possible, phrase the conditions as questions that can be answered with Yes or No. (You may need to figure these out first) 3. List the possible actions in the bottom, left quadrant. (You may need to figure these out first) 4. Each condition can have Y or N values (so, 2 in total). Multiple the number of conditions by the number of possible values (2). Draw one column through the top and bottom right quadrants for each combination. For example, if there are three conditions then it would be 3*2 = 6 possible columns. 5. Enter all possible combinations of values in the columns in the top, right quadrant of the table. 6. For each column (each unique combination of conditions), mark an X in the bottom, right quadrant in the appropriate action row Whole Class Work through - Let’s draw it together. We will work out a solution - If it is a weekday go to work, even if its raining. If it’s a holiday, don’t go to work. If it’s a holiday and it’s not raining, go on a picnic. If it’s a holiday and it’s raining, relax and watch TV. - What are the rules / conditions? - How many condition alternatives will there be? (multiply the number of possible alternative values together. E.g. Y/N = 2 values. If there were 4 conditions it would be 2*2*2*2 – multiplying the number of rule values together, giving 16 conditions). - What are the actions? The Decision Completed Table Practice Tasks • Now it’s your turn to have a go. • Work through the printed activities: Decision Table Exercises • Teacher Answers • We will step through them. • Need help? Look at examples in your text book.
© Copyright 2026 Paperzz