Polling

From Gamewiki

Jump to: navigation, search

Suppose some action needs to be triggered by information gathered from many places in your gamelet. For example, there may be a number of monsters roving around the gamelet, and the gamelet should end when no monsters survive. How can you tell when none are left? Create a polling agent, and a variable that all agents can access (a global variable in Agentsheets.) The polling agent sets the variable to zero, broadcasts a “sign in” message, and sends itself a “check” message. Each monster agent responds to the “sign in message” by setting the variable to 1. The polling agent responds to the “check” message by testing the global variable: if its value is zero, there can’t be any monsters left, and the game should end.

Personal tools