AI FOR GAMES AI FOR EVERYTHING Artificial intelligence (AI) is all around us. From driverless cars to game-winning computers to fraud protection, AI is already involved in many aspects of life, and its impact will only continue to grow in the future. Many of the world’s most valuable companies are investing heavily in AI research and development, and not a day goes by without news of cutting-edge breakthroughs in AI and robotics. The AI for Everything series will explore the role of AI in contemporary life, from cars and aircraft to medicine, education, fashion, and beyond. Concise and accessible, each book is written by an expert in the field and will bring the study and reality of AI to a broad readership including interested professionals, students, researchers, and lay readers. AI for Immunology AI for Radiology Louis J. Catania Oge Marques AI for Cars AI for Games Hanky Sjafrie & Josep Aulinas Ian Millington AI for Digital Warfare AI for School Teachers Niklas Hageback & Daniel Hedblom Rose Luckin & Karine George AI for Art AI for Learners Niklas Hageback & Daniel Hedblom Carmel Kent, Benedict du Boulay & Rose Luckin AI for Creativity Niklas Hageback AI for Social Justice Alan Dix and Clara Crivellaro AI for Death and Dying Maggi Savin-Baden For more information about this series please visit: https://www.routledge.com/AI-for-Everything/book-series/AIFE A I F O R G A M E S IAN MILLINGTON First Edition published 2022 by CRC Press 6000 Broken Sound Parkway NW, Suite 300, Boca Raton, FL 33487-2742 and by CRC Press 2 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN © 2022 Ian Millington CRC Press is an imprint of Taylor & Francis Group, LLC Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint. Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, access www.copyright.com or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. For works that are not available on CCC please contact [email protected] Trademark notice: Product or corporate names may be trademarks or registered trademarks and are used only for identification and explanation without intent to infringe. Library of Congress Cataloging-in-Publication Data Names: Millington, Ian, author. Title: AI for games / Ian Millington. Description: Fourth edition. | Boca Raton : CRC Press, 2022. | Includes bibliographical references and index. Identifiers: LCCN 2021027654 | ISBN 9780367643447 (hardback) | ISBN 9780367643430 (paperback) | ISBN 9781003124047 (ebook) Subjects: LCSH: Computer games—Programming. | Artificial intelligence. | Computer animation. Classification: LCC QA76.76.C672 M549 2022 | DDC 794.8/1525—dc23 LC record available at https://lccn.loc.gov/2021027654 ISBN: 978-0-367-64344-7 (hbk) ISBN: 978-0-367-64343-0 (pbk) ISBN: 978-1-003-12404-7 (ebk) DOI: 10.1201/9781003124047 Typeset in Joanna by codeMantra CONTENTS Author vii Introduction 1 1 What Is AI? 3 2 Model of Game AI 11 3 Algorithms and Data Structures 17 4 Game AI 21 5 Techniques 47 6 Supporting Technologies 65 Index 71 AUTHOR Ian Millington is a British developer and author of books and courses on software development, particularly in the fields of artificial intelli- gence, decision support, and game physics engine development. Also an AJAX technology pioneer, Millington is attributed with creating a model of distributed power for management of a creative game with a troupe system style of play. INTRODUCTION Game development lives in its own technical world. It has its own idioms, skills, and challenges. That’s one of the reasons games are so much fun to work on. Each game has its own rules, its own aesthetic, and its own trade-offs, and the hardware it will run on keeps chang- ing. There’s a reasonably good chance you will be the first person to meet and beat a new programming challenge. Despite numerous efforts to standardize game development in line with the rest of the software industry (efforts that go back at least 25 years), the style of programming in a game is still rather unique. There is a focus on speed, but it differs from real-time pro- gramming for embedded or control applications. There is a focus on clever algorithms, but it doesn’t share the same rigor as database server engineering. It draws techniques from a huge range of differ- ent sources, but almost without exception modifies them beyond resemblance. And, to add an extra layer of intrigue, developers make their modifications in different ways, often under extreme time pres- sure, and tailored entirely to the game at hand, leaving algorithms unrecognizable from studio to studio or project to project. As exciting and challenging as this may be, it makes it difficult for new developers to get the information they need. Twenty years ago, it was almost impossible to get hold of information about tech- niques and algorithms that real developers used in their games. There was an atmosphere of secrecy, even alchemy, about the coding tech- niques in top studios. Then came the Internet and an ever-growing range of websites, along with books, conferences, and periodicals. It is now easier than ever to teach yourself new techniques in game development. DOI: 10.1201/9781003124047-1