🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #1598

Re: Question about adding

#1598
From: Richard A. O'Keefe
Date: Thu, 08 Oct 1992 06:14
23 lines
1357 bytes
In article <718322659.0@nwark.FidoNet>, Bert.Edens@f1160.n391.z1.FidoNet.Org (Bert Edens) writes:
>     monster(orc,4).
> where the latter is the number of hit points. What I want to do is add up a
> group of them and get the total hit points for an attack party. For
> example, it might be:
>     monster(orc,4). monster(kobold,5). monster(goblin,8).
> and I want to add them up.

You need a way to represent what is in the attack party.
For argument's sake, let's assume that a hit party is represented by
a list of HowMany*MonsterType pairs, e.g. [2*goblin,3*orc].

attack_party_hit_points(Monsters, HitPoints) :-
	attack_party_hit_point_loop(Monsters, 0, HitPoints).

attack_party_hit_point_loop([], HP, HP).
attack_party_hit_point_loop([K*M|KMs], HP0, HP) :-
	monster(M, H),
	HP1 is HP0 + K*H,
	attack_party_hit_point_loop(KMs, HP1, HP).

The data base is the place for information that doesn't change or changes
very infrequently; terms are the place for information that changes rapidly.
Technical Details
Message-ID: <14969@goanna.cs.rmit.oz.au>
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!goanna!ok
References: <718322659.0@nwark.FidoNet>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!goanna!ok
From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
Newsgroups: comp.lang.prolog
Subject: Re: Question about adding
Message-ID: <14969@goanna.cs.rmit.oz.au>
Date: 8 Oct 92 06:14:40 GMT
References: <718322659.0@nwark.FidoNet>
Organization: Comp Sci, RMIT, Melbourne, Australia
Lines: 23