🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.prolog
2 messages
2 total messages Started by Bert Edens Mon, 05 Oct 1992 12:05
Question about adding
#1553
Author: Bert Edens
Date: Mon, 05 Oct 1992 12:05
16 lines
968 bytes
Greetings...
    I wanted to get some suggestions on the best way to attack a problem.
I'm writing an adventure-type of game (no, not for a class :-) and wanted
to know the quickest way to add up their total hit points. The fact is
stored like:
    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.

Thanks...
   -Bert

 * Origin: Hillbilly Korner BBS - (501) 751-3714 (1:391/1160)
Re: Question about adding
#1598
Author: 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.
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