anchor.diff:  -author("Christopher Meiklejohn <christopher.meiklejohn@gmail.com>").
   
   -export([run/1,
  -         client/8,
  +         client/9,
            server/2]).
   
   -behaviour(lasp_simulation).
  
positive.code:     {ok, _} = lasp:update(Ads, {remove, Ad}, Ad).
  
  %% @doc Client process; standard recurisve looping server.
  client(SetType, CounterType, SyncInterval, Runner, Id, AdsWithContractsId, AdsWithContracts0, Counters0) ->
      receive
          terminate ->
              ok;
          view_ad ->
              Counters = case dict:size(Counters0) of
                  0 ->
                      Counters0;
                  _ ->
                      %% Select a random advertisement from the list of
                      %% active advertisements.
                      Random = random:uniform(dict:size(Counters0)),
                      {Ad, Counter0} = lists:nth(Random, dict:to_list(Counters0)),
                      {ok, Counter} = CounterType:update(increment, Id, Counter0),
                      dict:store(Ad, Counter, Counters0)
              end,
  
              %% Notify the harness that an event has been processed.
              Runner ! view_ad,
  
              client(SetType, CounterType, SyncInterval, Runner, Id, AdsWithContractsId, AdsWithContracts0, Counters)
      after
          SyncInterval ->
              {ok, AdsWithContracts, Counters} = synchronize(SetType, AdsWithContractsId, AdsWithContracts0, Counters0),
              client(SetType, CounterType, SyncInterval, Runner, Id, AdsWithContractsId, AdsWithContracts, Counters)
      end.
  
  %% @doc Generate advertisements and advertisement contracts.
  
negative.code:                                             Id,
                                              AdsWithContracts,
                                              undefined,
                                              dict:new(),
                                              dict:new()])
                                  end, lists:seq(1, NumClients)),
      {ok, State#state{client_list=Clients}}.
  