简体   繁体   English

使用查询结果进行计算

[英]Use a queries result for calculation

surely its a stupid question but i can't answer it myself. 当然这是一个愚蠢的问题,但我自己无法回答。 I have the following code: 我有以下代码:

%% 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

so the strings 1500 and 200 are concatenated but no numbers are substracted ... :( whats teh reason ? 所以字符串1500和200是连接在一起的,但是没有数字被减去... :(这是什么原因?

your rule needs a correction 您的规则需要更正

...
NewValue is Accountold-Price,
assert(account(Y,NewValue)).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM