Prolog 使用查询结果进行计算
这当然是个愚蠢的问题,但我自己回答不了。我有以下代码:Prolog 使用查询结果进行计算,prolog,Prolog,这当然是个愚蠢的问题,但我自己回答不了。我有以下代码: %% Ownedby-relationship in monopoly ownedby(bank,weststation). %% Account-Value: account(player1,1500). %% Prices price(weststation,200). %% Buy an estate in monopoly buy(X,Y):- ownedby(bank,X), !, retract(o
%% Ownedby-relationship in monopoly
ownedby(bank,weststation).
%% Account-Value:
account(player1,1500).
%% Prices
price(weststation,200).
%% Buy an estate in monopoly
buy(X,Y):-
ownedby(bank,X),
!,
retract(ownedby(bank, X)),
assert(ownedby(Y,X)),
price(X,Price),
account(Y,Accountold),
retract(account(Y,Accountold)),
assert(account(Y,Accountold-Price)).
%% Example:
buy(player1,weststation).
%% RESULT:
account(player1,X).
1500-200
所以字符串1500和200是串联的,但没有数字被减法…:原因是什么?您的规则需要更正
...
NewValue is Accountold-Price,
assert(account(Y,NewValue)).