ensure_loaded('agents.pl').
ensure_loaded('knowledge.pl').

:- dynamic common_knowledge/1.

% Setting common knowledge
set_common_knowledge(_, 0).
set_common_knowledge(Phi, Num) :- Num > 0, 
						set(everybody_knows(Phi)),
						Next is Num - 1,
						set_common_knowledge(everybody_knows(Phi), Next).

% Set common_knowledge
set(common_knowledge(Phi)) :- num_agents(Num), 
						Num >= 0, 
						set_common_knowledge(Phi, Num).

% Query common_knowledge(phi) -> phi ^ E(phi) ^ EE(phi) ...
common_knowledge(_, 0).
common_knowledge(Phi, Num) :- Num > 0,
						everybody_knows(Phi),
						Next is Num - 1,
						common_knowledge(everybody_knows(Phi), Next).
common_knowledge(Phi) :- num_agents(Num),
						Num >= 0,
						common_knowledge(Phi, Num).
