Designing an algorithm flow chart
Algorithm design option one - flow diagram
Algorithm design option two - pseudo-code
# for the purpose of this example the array starts at 1
Options ← [“paper”, “rock”, “scissors”] OUTPUT “Please enter your choice: 1, 2, or 3:”
player_choice ← USERINPUT
comp_choice ← RANDOM_INT (1, 3)
IF player_choice = comp_choice THEN OUTPUT “draw”
ELSE IF player_choice = 1 THEN IF comp_choice = 2 THEN winner ← “player” ELSE winner ← “comp” END IF ELSE IF player_choice = 2 THEN IF comp_choice = 3 THEN winner ← “player” ELSE winner ← “comp” END IF ELSE IF player_choice = 3 THEN IF comp_choice = 1 THEN winner ← “player” ELSE winner ← “comp” END IF IF winner = “player” THEN OUTPUT choices[player_choice] + “ beats” + choices[comp_choice] ELSE OUTPUT choices[comp_choice] + “ beats “ + choices[player_choice] END IF
END IFTesting table
Tests will be required to check that the final program runs correctly, although this will be more difficult than example one as one value is a random number. Because of the complexity of the program, validationChecking input data is sensible and in the right format. is not included in the exam question. However, it would be expected if this was a programming project scenario.
| Test no | Description | Test data | Test type | Expected outcome |
| 1 | Both computer and player select 2 | 2 | Normal | “draw” |
| 2 | Computer selects winning choice of rock | 2 | Normal | “rock beats scissors” |
| 3 | Player selects winning choice of paper | 1 | Normal | “paper beats rock” |
| 1 | Both computer and player select 1 | 1 | Normal | “draw” |
| 2 | Computer selects winning choice of scissors | 3 | Normal | “scissors beats paper” |
| 3 | Player selects winning choice of rock | 2 | Normal | “rock beats scissors” |
| Test no | 1 |
|---|---|
| Description | Both computer and player select 2 |
| Test data | 2 |
| Test type | Normal |
| Expected outcome | “draw” |
| Test no | 2 |
|---|---|
| Description | Computer selects winning choice of rock |
| Test data | 2 |
| Test type | Normal |
| Expected outcome | “rock beats scissors” |
| Test no | 3 |
|---|---|
| Description | Player selects winning choice of paper |
| Test data | 1 |
| Test type | Normal |
| Expected outcome | “paper beats rock” |
| Test no | 1 |
|---|---|
| Description | Both computer and player select 1 |
| Test data | 1 |
| Test type | Normal |
| Expected outcome | “draw” |
| Test no | 2 |
|---|---|
| Description | Computer selects winning choice of scissors |
| Test data | 3 |
| Test type | Normal |
| Expected outcome | “scissors beats paper” |
| Test no | 3 |
|---|---|
| Description | Player selects winning choice of rock |
| Test data | 2 |
| Test type | Normal |
| Expected outcome | “rock beats scissors” |
The problem has now been fully decomposed and an algorithm has been designed.