简体   繁体   中英

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 ?

your rule needs a correction

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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