Artificial Intelligence for Games by Ian Millington
Author:Ian Millington [Millington, Ian & Funge, John]
Language: eng
Format: epub
Published: 2014-05-04T04:00:00+00:00
438 Chapter 5 Decision Making
5
def matchesItem(item, bindings):
6
7
# Is the item of the same type?
8
if not item insistence Datum: return false
9
10
# Does the identifier match?
11
if identifier.isWildcard() and
12
identifier != item.identifier: return false
13
14
# Does the value fit?
15
if minValue <= item.value <= maxValue:
16
17
# Do we need to add to the bindings list?
18
if identifier.isWildcard():
19
20
# Add the binding
21
bindings.appendBinding(identifier, item)
22
23
# Return true, since we matched
24
return true
25
else: return false
The isWildcard method should return true if the identifier is a wild card. If you used strings as
identifiers and wanted to use LISP-style wild-card names, you could check that the first character
is a question mark, for example. The implementation on the website uses a 4-byte number as
an identifier and reserves the first bit to indicate if the identifier is a wild card. The isWildcard
method simply checks this bit.
Library
The bindings list has been given an appendBinding method that adds an identifier (which is
always a wild card) and the database item it was matched to. If we are using an STL list in C++,
for example, we could have it be a list of pair templates and append a new identifier, item pair.
Alternatively, we could use a hash table indexed by identifier.
Data Group Matching
A test data group will match a database data group if its identifier matches and if all its children
match at least one child of the database data group. Not all the children of the database data group
need to be matched to something.
For example, if we are searching for a match to:
1
(?anyone (Health 0-54))
5.8 Rule-Based Systems
439
we would like it to match:
1
(Captain (Health 43) (Ammo 140))
even though ammo isn’t mentioned in the test data group.
The matchesItem function for data groups has the following form:
1
struct DataGroupMatch(DataNodeMatch):
2
3
# ... Member data as before
4
5
def matchesItem(item, bindings):
6
7
# Is the item of the same type?
8
if not item insistence DataGroup: return false
9
10
# Does the identifier match?
11
if identifier != WILDCARD and
12
identifier != item.identifier: return false
13
14
# Is every child present
15
for child in self.children:
16
17
# Use the children of the item as if it were a
18
# database and call matches recursively
19
if not child.matches(item.children):
20
return false
21
22
# We must have matched all children
23
24
# Do we need to add to the bindings list?
25
if identifier.isWildcard():
26
27
# Add the binding
28
bindings.appendBinding(identifier, item)
29
30
return true
Summary
Figure 5.47 shows all our classes and interfaces in one diagram.
440 Chapter 5 Decision Making
Figure 5.47
UML of the matching system
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8301)
Test-Driven Development with Java by Alan Mellor(6728)
Data Augmentation with Python by Duc Haba(6641)
Principles of Data Fabric by Sonia Mezzetta(6393)
Learn Blender Simulations the Right Way by Stephen Pearson(6292)
Microservices with Spring Boot 3 and Spring Cloud by Magnus Larsson(6165)
Hadoop in Practice by Alex Holmes(5959)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5807)
RPA Solution Architect's Handbook by Sachin Sahgal(5561)
Big Data Analysis with Python by Ivan Marin(5367)
The Infinite Retina by Robert Scoble Irena Cronin(5252)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(5148)
Pretrain Vision and Large Language Models in Python by Emily Webber(4331)
Infrastructure as Code for Beginners by Russ McKendrick(4091)
Functional Programming in JavaScript by Mantyla Dan(4038)
The Age of Surveillance Capitalism by Shoshana Zuboff(3955)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3805)
Embracing Microservices Design by Ovais Mehboob Ahmed Khan Nabil Siddiqui and Timothy Oleson(3609)
Applied Machine Learning for Healthcare and Life Sciences Using AWS by Ujjwal Ratan(3580)
