我正在尝试用 Clingo 编写故事生成器。
我想说的是“如果现有角色生出新角色,就可以诞生新角色。” 我将新字符定义为entity(<int\>)
,这是我能想到的表示实体的最佳方式。我无法对此进行硬编码,因为可以在故事中创建不同数量的实体。
我code
的是:
% Create instances of time, only 3 for testing
time(0..2).
% Arrow of time flows forward
next_t(T, T+1) :- time(T), time(T+1).
% Entity 1 exists at time 0.
entity(1, 0).
% If an entity ever existed, that ID is taken and cannot be assigned to
% other entities
entity_id(ID) :- entity(ID, _).
% If an entity exists, he can give birth to a new entity
% The ID of the new entity will be 1 more than ID of all current entities.
birth(X, Y, T) :- entity(Y, T), X = #max{X1+1:entity_id(X1)}, time(T).
% At each time instant, only 1 entity can be born, as only 1 event can happen per time instant.
% This also should prevent infinite entities to be created.
:- birth(X1, _, T), birth(Y1, _, T), X1!=Y1.
% In case of a birth, create a new entiti the next time instant.
entity(X, T1) :- birth(X, _, T), next(T, T1).
#show entity_id/1.
#show entity/2.
#show birth/3 .
但是,输出是:
entity_id(1) entity(1,0) birth(2,1,0)
entity(2, 1)
从未被创建,也不是entity(3, 2)
or entity(4, 3)
。
我究竟做错了什么?有一个更好的方法吗?