Question

I am trying to program a little game and for that I need to determine which's players turn. I am solving it firstly with a Nassi-Schneiderman diagram with a variable turn whic can be 1 or 2, but my problem is that I end up with too much branched decision blocks. (In the first round player 1 begins always, the player that loses starts in every other case, if it is a tie player 1 begins)

Do I need another variable or has someone an idea on how I can solve my problem without making it too complicated?

Was it helpful?

Solution

You need only one multiple branching block with 4 alternatives (I try to describe this in text form, drawing the diagram is left as an exercise to the reader, which means you):

Title: choose starting player for next game.

Question: Outcome of the previous game?

  • player 1 wins -> player 2 is next
  • player 2 wins -> player 1 is next
  • tie -> player 1 is next
  • no previous game -> player 1 is next

Now place this block inside a loop block with just two sub-blocks "choose starting player for next game" and "play next game".

Side note: as you can see in this example, the expressiveness of Nassi-Shneiderman diagrams is not really better than simple pseudo-code, or even real code in a language like Python (but pseudo-code is way easier to create using a keyboard). That's probably the reason why these kinds of diagrams are not very popular any more today.

OTHER TIPS

To keep the complexity manageable, you cannot put everything in a single diagram (regardless of what notation you use), but you have to create separate diagrams that represent different portions of the game and/or highlight different aspects.

One split I would make in your case is to use separate diagrams for determining the initial player in a round and for switching turns during a round. The second one would represent a function that receives the initial player as a parameter.

Licensed under: CC-BY-SA with attribution
scroll top