# Designing an algorithm

## 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 IF 

## Testing 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, is not included in the exam question. However, it would be expected if this was a programming project scenario.

Test noDescriptionTest dataTest typeExpected outcome
1Both computer and player select 22Normal“draw”
2Computer selects winning choice of rock2Normal“rock beats scissors”
3Player selects winning choice of paper1Normal“paper beats rock”
1Both computer and player select 11Normal“draw”
2Computer selects winning choice of scissors3Normal“scissors beats paper”
3Player selects winning choice of rock2Normal“rock beats scissors”

The problem has now been fully decomposed and an algorithm has been designed.