Power Sources

version 1 by Emily Short

  • Home page
  • Beginning
  • Previous
  • Next



  • Part 2 - Battery Power

    Section 1 - Batteries

    A battery is a kind of thing. A battery has a number called charge. The charge of a battery is usually 60.

    A rechargeable battery is a kind of battery. A rechargeable battery has a number called maximum charge. The maximum charge of a rechargeable battery is usually 60.

    Definition: a battery is discharged if its charge < 1.
    Definition: a rechargeable battery is fully charged if its charge is its maximum charge.

    [We make this rule occur at the beginning of the every turn rules so that if the devices are themselves doing something every turn while switched on, we don't get a sequence where the player removes a battery, the robot dog barks one last time anyway, and only then do we get the robot dog shutdown message.]
    A first every turn rule (this is the check power sources rule):
        follow the energy management rules.

    The energy management rules are a rulebook.

    An energy management rule (this is the deplete or recharge batteries rule):
        repeat with hollow running through battery compartments:
            if the hollow is part of a device (called the machine):
                if a battery (called cell) is in the hollow:
                    if the machine is wall-powered:
                        if the cell is a rechargeable battery and charge of the cell is less than the maximum charge of the cell:
                            increase the charge of the cell by the battery recharge of the machine;
                            if the charge of the cell is greater than the maximum charge of the cell:
                                now the charge of the cell is the maximum charge of the cell;
                            if the cell is fully charged and the player can see the machine:
                                carry out the notifying of full charge activity with the machine;
                    otherwise if the machine is switched on:
                        decrease the charge of the cell by the battery drain of the machine;
                        if the player can see the machine:
                            carry out the warning about the failure activity with the machine.