Thread View: comp.lang.prolog
1 messages
1 total messages
Started by Cyberman
Fri, 09 Oct 1992 00:39
Re: question about adding
Author: 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads