Pattern Hatching by John Vlisside discusses
the Mememento pattern on pages 102 to about 106+
How to Design Programs
An introduction to Programming and Computing
Matthias Felleisen (scheme language)
Friday, December 08, 2006
Tuesday, December 05, 2006
matt buckland : ai book excerpts
Buckland, Mat.
Programming game AI by example / by Mat Buckland.
p. cm.
Includes index.
ISBN 1-55622-078-2 (pbk.)
1. Computer games — Design. 2. Computer games — Programming. 3.Computer
graphics. I. Title.
QA76.76.C672B85 2004
794.8'1526 — dc22
class State
{
public:
virtual void Execute (Troll* troll) = 0;
};
Now imagine a Troll class that has member variables for attributes such as health, anger, stamina, etc., and an interface allowing a client to query and adjust those values. A Troll can be given the functionality of a finite state machine by adding a pointer to an instance of a derived object of the State class, and a method permitting a client to change the instance the pointer is pointing to.
class Troll
{
/* ATTRIBUTES OMITTED */
State* m_pCurrentState;
public:
/* INTERFACE TO ATTRIBUTES OMITTED */
void Update()
{
m_pCurrentState->Execute(this);
}
void ChangeState(const State* pNewState)
{
delete m_pCurrentState;
m_pCurrentState = pNewState;
}
};
Programming game AI by example / by Mat Buckland.
p. cm.
Includes index.
ISBN 1-55622-078-2 (pbk.)
1. Computer games — Design. 2. Computer games — Programming. 3.Computer
graphics. I. Title.
QA76.76.C672B85 2004
794.8'1526 — dc22
class State
{
public:
virtual void Execute (Troll* troll) = 0;
};
Now imagine a Troll class that has member variables for attributes such as health, anger, stamina, etc., and an interface allowing a client to query and adjust those values. A Troll can be given the functionality of a finite state machine by adding a pointer to an instance of a derived object of the State class, and a method permitting a client to change the instance the pointer is pointing to.
class Troll
{
/* ATTRIBUTES OMITTED */
State* m_pCurrentState;
public:
/* INTERFACE TO ATTRIBUTES OMITTED */
void Update()
{
m_pCurrentState->Execute(this);
}
void ChangeState(const State* pNewState)
{
delete m_pCurrentState;
m_pCurrentState = pNewState;
}
};
Subscribe to:
Posts (Atom)