ebook img

Artificial Intelligence in Games(2022)[Dent][9781003305835] PDF

310 Pages·2022·17.887 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Artificial Intelligence in Games(2022)[Dent][9781003305835]

Artificial Intelligence in Games This book covers all the necessary topics that a professional game AI programmer needs to know, from math and steering behaviours to terrain analysis, pathfinding, and decision-making. Written to be easily accessible, each topic is accompanied by an example game that allows the reader to add their own code to see the effects their changes have. Each chapter is split into two parts. The first part covers the necessary theory in a friendly, conversational manner, using visual examples and fictional game scenarios to give additional context. The second part is a coding tutorial in C# for the topic at hand. Each chapter has its own example game available to download, written in C# in the Unity Game Engine. This book will be suitable for students and aspiring games programmers looking to gain a grounding in game AI techniques. Paul Roberts is a Lead AI Games Programmer who has worked for companies such as Activision, Team17, Traveller’s Tales and Sumo Digital. Credits include Call of Duty: Strike Team, Pitfall!, Worms Revolution and The Lego Movie: The Video Game. Artificial Intelligence in Games Paul Roberts Illustrations by Nicholas Dent First edition published 2023 by CRC Press 6000 Broken Sound Parkway NW, Suite 300, Boca Raton, FL 33487-2742 and by CRC Press 4 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN CRC Press is an imprint of Taylor & Francis Group, LLC © 2023 Paul Roberts Reasonable efforts have been made to publish reliable data and information, but the author and publisher can- not 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, transmit- ted, 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, with- out 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: Roberts, Paul (Game programmer), author. | Dent, Nicholas (Illustrator), illustrator. Title: Artificial intelligence in games / Paul Roberts ; illustrated by Nicholas Dent. Description: First edition. | Boca Raton : CRC Press, 2023. | Includes bibliographical references and index. | Summary: “This book covers all the necessary topics that a professional game AI programmer needs to know, from math and steering behaviours to terrain analysis, pathfinding, decision making, and more. Written to be easily accessible, each topic is accompanied by an example game, where the reader can add their own code to see the effects their changes have. This book will be suitable for students and aspiring games programmers looking to gain a grounding in game AI techniques”-- Provided by publisher. Identifiers: LCCN 2022005391 | ISBN 9781032305950 (hardback) | ISBN 9781032033228 (paperback) | ISBN 9781003305835 (ebook) Subjects: LCSH: Computer games--Programming. | Computer games--Design. | Video games--Design. | Artificial intelligence. Classification: LCC QA76.76.C672 R6327 2023 | DDC 794.8/1526--dc23/eng/20220412 LC record available at https://lccn.loc.gov/2022005391 ISBN: 9781032305950 (hbk) ISBN: 9781032033228 (pbk) ISBN: 9781003305835 (ebk) DOI: 10.1201/9781003305835 Typeset in Times LT Std by KnowledgeWorks Global Ltd. Access the Support Material: https://www.routledge.com/9781032033228 Contents Chapter 1 Introduction ..........................................................................................1 About the Author ..................................................................................1 Who Is this Book for? ..........................................................................1 How to Read this Book ........................................................................1 Accompanying Framework ..................................................................2 What Is Game AI? ................................................................................2 Game AI and Game Genres ..................................................................6 Chapter 2 Math .....................................................................................................9 What Is a Vector? ..................................................................................9 Dot Product ........................................................................................13 Rotation ..............................................................................................21 Math – Practical ................................................................................25 Project Overview ................................................................................25 Step-By-Step Guide ............................................................................25 Future Work ........................................................................................27 Chapter 3 Steering Behaviours ...........................................................................29 Steering Forces ...................................................................................29 Combining Behaviours .......................................................................48 Group Behaviours ...............................................................................50 Final Thoughts ....................................................................................54 Steering Behaviours – Practical ........................................................56 Project Overview ................................................................................56 Step-By-Step Guide ............................................................................57 Future Work ........................................................................................72 Chapter 4 Terrain Analysis .................................................................................73 Influence Maps ...................................................................................73 Heat Maps...........................................................................................77 Cell Granularity ..................................................................................81 Final Thoughts ....................................................................................82 Terrain Analysis – Practical ..............................................................83 Project Overview ................................................................................83 Step-By-Step Guide ............................................................................84 Future Work ........................................................................................90 v vi Contents Chapter 5 Pathfinding .........................................................................................91 Spatial Representation ........................................................................91 Pathfinding ..........................................................................................96 Final Thoughts ..................................................................................116 Pathfinding – Practical ....................................................................117 Project Overview ..............................................................................117 Step-By-Step Guide ..........................................................................118 Future Work ......................................................................................123 Chapter 6 Decision-Making ..............................................................................125 Finite State Machine .........................................................................125 Fuzzy State Machine ........................................................................128 Stack-Based FSM .............................................................................129 Behaviour Trees ................................................................................130 Final Thoughts ..................................................................................133 Decision-Making – Practical ...........................................................134 Project Overview ..............................................................................134 Step-By-Step Guide ..........................................................................134 Future Work ......................................................................................149 Chapter 7 Fuzzy Logic ......................................................................................151 Sets ...................................................................................................153 Fuzzy Sets ........................................................................................155 Fuzzy Rules ......................................................................................161 Defuzzification .................................................................................169 Final Thoughts ..................................................................................175 Fuzzy Logic – Practical ...................................................................176 Project Overview ..............................................................................176 Step-By-Step Guide ..........................................................................176 Future Work ......................................................................................194 Chapter 8 Chess AI ...........................................................................................195 Minimax Algorithm ..........................................................................196 Alphabeta Pruning ............................................................................201 Evaluation Functions ........................................................................208 Final Thoughts ..................................................................................217 Chess AI – Practical ........................................................................218 Project Overview ..............................................................................218 Contents vii Step-By-Step Guide ..........................................................................219 Future Work ......................................................................................224 Chapter 9 Genetic Algorithms ..........................................................................227 Initial Population ..............................................................................230 Encoding ...........................................................................................230 Fitness ...............................................................................................232 Selection ...........................................................................................233 Crossover ..........................................................................................240 Mutation ...........................................................................................245 Final Thoughts ..................................................................................246 Genetic Algorithms – Practical .......................................................248 Project Overview ..............................................................................248 Step-By-Step Guide ..........................................................................249 Future Work ......................................................................................261 Chapter 10 Neural Networks ..............................................................................263 Biology .............................................................................................263 Single-Layer Perceptron ...................................................................264 Multi-Layer Perceptron ....................................................................270 Learning............................................................................................273 Game Example: Snake .....................................................................277 Final Thoughts ..................................................................................279 Neural Networks – Practical ............................................................281 Project Overview ..............................................................................281 Step-By-Step Guide ..........................................................................282 Future Work ......................................................................................297 Index ......................................................................................................................299 1 Introduction ABOUT THE AUTHOR My name is Paul Roberts and I am a Lead AI games programmer. I’ve worked on a variety of big releases over the years including titles such as Call of Duty: Strike Team, The Lego Movie: The Video Game and Worms Revolution and have developed quite a few smaller mobile games too, including Power-Up, Pixel 8, Rituals and Captain CupCake and Donut Disaster. I have worked at big studios like Activision, Sumo Digital, Team17 and Traveller’s Tales and been an indie developer at my own studio too – Playing with Giants. I also spent around six years leading the Computer Games Programming undergraduate degrees and master’s degrees at a UK univer- sity, where I was fortunate enough to rewrite all their game AI content and set our students on the right path. I have been programming since the ZX Spectrum days and am currently dabbling in some assembly language programming for the Atari 2600 for fun. I also write novels as a hobby; so if you are a fantasy fan, check out my novel, The Betrayer: Prophecy of the Dragon Book One (Amazon, 2022). WHO IS THIS BOOK FOR? This book was written for anyone wishing to get a grounding in-game AI techniques. I have pitched everything at an undergraduate level, but that does not mean that if you are not currently studying that you cannot get anything from this book. Not at all. I feel that anyone interested in game AI that has never approached the subject before can work their way through this book and gain a lot. There are, however, cod- ing tutorials in each chapter written in C#; so to get the most from these, it would be beneficial if you could already code at a basic level. HOW TO READ THIS BOOK Each chapter is split into two parts. The first gives an overview of the topic in a friendly conversational manner and there are a lot of visual examples and fictional game scenarios to give some context to the area being covered. The second part of each chapter has been written as a coding tutorial. It will guide you through how to code the techniques the first half of the chapter covered. It is recommended that you read both parts of a chapter in order, but if you already have an understanding of an area and wish to jump right into the code, then skip straight to the second half of the relevant chapter. Likewise, if you are not interested in coding the solutions and just want to get an understanding of the different areas of game AI, feel free to just read the first halves. I have compiled the topics for this book in a way that each chapter builds upon the last. If you choose to read the chapters in order, at the end of this book you should DOI: 10.1201/9781003305835-1 1

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.