The solution consists of two programs: one for the producer and one for the consumers.

The consumer Karas


First a consumer has to search for a cloverleaf by wandering around randomly. To achieve this, non-deterministic interpretation of state machines must be enabled (use Preferences dialog). Before a consumer Kara steps on a cloverleaf block, he must acquire the critical section to make sure that no other Kara is working on the same block.

After stepping on a cloverleaf, Kara first searches the end of the block and then replaces the cloverleafs. Afterwards Kara leaves the block and releases the critical section. When leaving the cloverleaf block, Kara has to make sure the he does not collide with another Kara. Finally, having left the block, Kara restarts searching for another block of leafs.

The producer Kara


The producer first has to find an empty field to start laying down a row of cloverleafs. In the state "walk", Kara knows that the field behind him is empty (leftmost image above). If the field ahead is also empty, he changes into the state "lay leaf" with a certain probability (second image). If the field ahead is not empty, he turns and looks for another empty field.

In the state "lay leaf", Kara tests if the field ahead and the fields to his left and right are empty. If so, he lays down a cloverleaf and takes a step forward (middle image). He continues laying down cloverleafs with a certain probability while the three fields next to him are empty. Otherwise, he changes to the state "walk" to look for a new position for a cloverleaf block.

Hint: To avoid that a consumer Kara starts replacing a block before the producer has finished laying it down, the state "lay leaf" is marked as a critical section.