Article View: comp.lang.prolog
Article #1608Re: question about adding
From: Cyberman
Date: Fri, 09 Oct 1992 00:39
Date: Fri, 09 Oct 1992 00:39
38 lines
1797 bytes
1797 bytes
Bert Edens was espousing about 'Question about adding',
on [10-05-92 12:05] to All!
BE> Greetings...
YEAH well HI! :)
BE> I wanted to get some suggestions on the best way to attack a
BE> problem. I'm writing an adventure-type of game (no, not for a class :-)
BE> and wanted to know the quickest way to add up their total hit points.
BE> The fact is stored like:
BE> monster(orc,4).
this may not be as difficult as you might imagine.
BE> where the latter is the number of hit points. What I want to do is add
BE> up a group of them and get the total hit points for an attack party.
BE> For example, it might be:
BE> monster(orc,4). monster(kobold,5). monster(goblin,8).
BE> and I want to add them up.
This all depends on how you have it stored, if the monster
group is a dbasedomain then you can use findall.
group_hp(Hp_):-findall(Hp,monster_group(_,Hp),Hp_list),
add_list(Hp_list,0,Hp_).
add_list([],Total,Total).
add_list([H|T],Running_total,Result):-
New_running_total = H + Running_total,
add_list(T,New_running_total,Result).
Stephen Cyberman@Toz.Buffalo.NY.US
Scripted at Thu 10-08-1992 11:01:20
... If it weren't for the last minute Windoze would not be done.
--- Blue Wave/QWK v2.10
Technical Details
Message-ID:
<gate.3cqcsB1w165w@toz.buffalo.ny.us>Path:
arc1-ca.pugleaf.net!sparky!uunet!kithrup!hoptoad!pacbell.com!ames!haven.umd.edu!darwin.sura.net!gatech!rutgers!ub!toz!cybermanShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!kithrup!hoptoad!pacbell.com!ames!haven.umd.edu!darwin.sura.net!gatech!rutgers!ub!toz!cyberman From: cyberman@toz.buffalo.ny.us (Cyberman) Newsgroups: comp.lang.prolog Subject: Re: question about adding Message-ID: <gate.3cqcsB1w165w@toz.buffalo.ny.us> Date: 9 Oct 92 00:39:49 GMT Lines: 38 X-Maildoor: WaflineMail 1.00r