Skip to Content
Lua游戏AI开发指南
book

Lua游戏AI开发指南

by Posts & Telecom Press, David Young
May 2024
Beginner to intermediate
327 pages
4h 38m
Chinese
Packt Publishing
Content preview from Lua游戏AI开发指南

第8章 感知

本章主题:

  • 创建、发送和接收事件;
  • 赋予智能体视觉和听觉;
  • 创建相互竞争的智能体团队;
  • 根据事件消息更新行为;
  • 通过消息管理智能体间的通信。

现在,我们的智能体对于沙箱是一个全知全能的存在。通过直接选择敌人的位置,智能体能快速而准确地做出反应,游戏玩家可能认为这是在作弊。为了让智能体的交互和反应更为真实可信,我们需要实现感知系统。本质上说,就是为智能体赋予看、听和相互交流的能力。

到目前为止,我们的智能体都在它们各自的虚拟机中运行,相互通信并不容易。为了解决这个问题,我们会创建一种叫事件的数据结构,它可以在智能体以及沙箱之间进行传递。

创建事件,简单来说就是创建一个具有一点限制的Lua表。由于事件是由沙箱序列化并传递到每个虚拟机中的,只有一些简单的表属性可以添加到事件中。

每个可支持的属性如表8-1所示。

表8-1

事件属性类型

描述

Boolean布尔值

一个或为真或为假的Lua值

Number数字

Lua数字,内部是以浮点值表示

Object对象

一个代码对象、沙箱、沙箱对象或者智能体

String字符串

任何Lua字符串值

Vector向量

任何由Vector.new创建的向量

提示.tif 

事件内部不能有嵌套的表格,任何不被支持的属性类型在序列化时都会被丢弃。这是目前沙箱C++端事件序列化中的一个限制。

创建好事件后就可以发送给沙箱了。由于所有的对象都由沙箱实例所拥有,事件的派发是由沙箱在内部处理的。在发送事件时,需要提供一个消息类型字符串,用来帮助事件接收者解析事件的数据。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python迁移学习

Python迁移学习

Posts & Telecom Press, Dipanjan Sarkar, Raghav Bali, Tamoghna Ghosh
R深度学习权威指南

R深度学习权威指南

Posts & Telecom Press, Joshua F. Wiley
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua

Publisher Resources

ISBN: 9781836205555