2012-12-14 127 views
1

肯定是一個愚蠢的問題,但我不能自己回答。我有以下代碼:使用查詢結果進行計算

%% 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被連接起來,但沒有數字中減去... :(什麼原因德

回答

0

你的規則需要修正

... 
NewValue is Accountold-Price, 
assert(account(Y,NewValue)). 
相關問題