CN109646959B - Method for managing NPC (non-player character) based on state machine and related equipment - Google Patents

Method for managing NPC (non-player character) based on state machine and related equipment Download PDF

Info

Publication number
CN109646959B
CN109646959B CN201811482751.6A CN201811482751A CN109646959B CN 109646959 B CN109646959 B CN 109646959B CN 201811482751 A CN201811482751 A CN 201811482751A CN 109646959 B CN109646959 B CN 109646959B
Authority
CN
China
Prior art keywords
npc
execution queue
npcs
queue
state
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811482751.6A
Other languages
Chinese (zh)
Other versions
CN109646959A (en
Inventor
石仲斌
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Miniwan Technology Co ltd
Original Assignee
Shenzhen Miniwan Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Miniwan Technology Co ltd filed Critical Shenzhen Miniwan Technology Co ltd
Priority to CN201811482751.6A priority Critical patent/CN109646959B/en
Publication of CN109646959A publication Critical patent/CN109646959A/en
Application granted granted Critical
Publication of CN109646959B publication Critical patent/CN109646959B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • AHUMAN NECESSITIES
    • A63SPORTS; GAMES; AMUSEMENTS
    • A63FCARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F13/00Video games, i.e. games using an electronically generated display having two or more dimensions
    • A63F13/60Generating or modifying game content before or while executing the game program, e.g. authoring tools specially adapted for game development or game-integrated level editor
    • A63F13/67Generating or modifying game content before or while executing the game program, e.g. authoring tools specially adapted for game development or game-integrated level editor adaptively or by learning from player actions, e.g. skill level adjustment or by storing successful combat sequences for re-use
    • AHUMAN NECESSITIES
    • A63SPORTS; GAMES; AMUSEMENTS
    • A63FCARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F2300/00Features of games using an electronically generated display having two or more dimensions, e.g. on a television screen, showing representations related to the game
    • A63F2300/60Methods for processing data by generating or executing the game program
    • A63F2300/6027Methods for processing data by generating or executing the game program using adaptive systems learning from user actions, e.g. for skill level adjustment

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Stored Programmes (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The invention discloses a method for managing NPC of a non-player character based on a state machine and related equipment, relating to the field of computer technology application, wherein the method comprises the following steps: determining active NPCs forming an execution queue and stable NPCs forming a non-execution queue in the system; traversing the execution queue every other preset unit time, and meanwhile, carrying out corresponding queue state migration on each active NPC in the execution queue based on a matching result of the current behavior state of the active NPC and a first migration condition; determining the number of times of traversal of the execution queue after traversing the execution queue; when the number of traversal times reaches a preset threshold value, after the next preset unit time, performing corresponding queue state migration on each stable NPC in the non-execution queue based on a matching result of the current behavior state of the stable NPC and a second migration condition; the final behavior state of all NPCs is recorded and the system is shut down. The method improves the efficiency of managing the NPC.

Description

Method for managing NPC (non-player character) based on state machine and related equipment
Technical Field
The invention relates to the field of computer technology application, in particular to a method for managing NPC of a non-player character based on a state machine and related equipment.
Background
Today, the electronic game field is an important part of people's life driven by the internet technology. In a variety of games involving non-player characters NPC, for example: in the RPG game and the sandbox game, there are many NPCs. Among these, the actions of NPC, such as: interactions with the player, interactions with the environment, have a significant impact on the player's play. Therefore, how to manage the large number of NPCs in the system is a fundamental and important issue.
In the prior art, the management of NPC is divided into two main categories, one: based on a neural network or a deep learning algorithm, the method has the advantages of accurate control of the NPC, and has the disadvantages of high cost of training the neural network, large number of computing units and difficulty in realization on an offline personal client; II, secondly: the method has the advantages of simple algorithm and low cost, but relatively has the disadvantages that the NPCs in the system do not need to be controlled by behavior actions all at any time, and the method causes the waste of computing resources and low efficiency.
Disclosure of Invention
Based on this, in order to solve the technical problem of how to manage the NPC of the non-player character based on the state machine in the related art, the invention provides a method for managing the NPC of the non-player character based on the state machine and related equipment.
In a first aspect, a method for managing an NPC of a non-player character based on a state machine is provided, including:
responding to a starting instruction of a user to a system, and determining active NPCs forming an execution queue and stable NPCs forming a non-execution queue in the system;
traversing the execution queue every other preset unit time, and meanwhile, carrying out corresponding queue state migration on each active NPC in the execution queue based on a matching result of the current behavior state of the active NPC and a first migration condition;
determining the number of times of traversal of the execution queue after traversing the execution queue;
when the number of traversal times reaches a preset threshold value, after the next preset unit time, performing corresponding queue state migration on each stable NPC in the non-execution queue based on a matching result of the current behavior state of the stable NPC and a second migration condition;
and responding to a closing instruction of a user to the system, recording the final behavior states of all NPCs and closing the system.
In an exemplary embodiment of the present disclosure, determining, in response to a user start instruction for a system, an active NPC constituting an execution queue and a stable NPC constituting a non-execution queue in the system includes:
responding to a starting instruction of a user to a system, and determining the initial behavior states of all NPCs in the system;
and determining active NPCs forming an execution queue and stable NPCs forming a non-execution queue in the system based on the matching result of the initial behavior states of all the NPCs and preset execution conditions.
In an exemplary embodiment of the disclosure, determining the initial behavior state of all NPCs in the system comprises:
acquiring a record which is closest to the current time point and is stored by a system and related to the behavior states of all NPCs;
and determining the behavior states of all NPCs in the record as the initial behavior states of all NPCs.
In an exemplary embodiment of the present disclosure, determining active NPCs forming an execution queue and stable NPCs forming a non-execution queue based on matching results of initial behavior states of all NPCs and preset execution conditions includes:
determining the initial behavior state meeting the preset execution condition and the corresponding NPC as the active NPC;
determining the initial behavior state which does not meet the preset execution condition and the corresponding NPC as the stable NPC;
sequentially placing the active NPCs in the execution queue according to the sequence of the determination time of the initial behavior states of all the NPCs;
and sequentially placing the stable NPCs in the non-execution queue according to the determined time sequence of the initial behavior states of all the NPCs.
In an exemplary embodiment of the present disclosure, traversing the execution queue every preset unit time, and performing corresponding queue state migration on each active NPC in the execution queue based on a matching result between a current behavior state of the active NPC and a first migration condition, includes:
determining the current behavior state of each active NPC in the execution queue at intervals of a preset unit time;
reserving the current behavior state meeting the first migration condition and the corresponding active NPC in the execution queue;
determining the current behavior state which does not meet the first migration condition and the corresponding active NPC as a stable NPC;
removing the stable NPC from the execution queue and placing the stable NPC in the non-execution queue.
In an exemplary embodiment of the present disclosure, determining the number of traversals of the execution queue each time the execution queue is traversed includes:
adding 1 to a current value of a preset variable after traversing the execution queue, wherein an initial value of the preset variable is 0;
determining a value of the variable as the number of traversals of the execution queue.
In an exemplary embodiment of the disclosure, each time the number of times of traversal reaches a predetermined threshold, after a next preset unit time, performing corresponding queue state migration on each stable NPC in the non-execution queue based on a matching result between a current behavior state of the stable NPC and a second migration condition, including:
determining the current behavior state of each stable NPC in the non-execution queue after the next preset unit time every time the number of traversed times reaches a preset threshold;
determining the current behavior state meeting the second migration condition and the corresponding stable NPC as an active NPC;
removing the active NPC from the non-execution queue and placing the active NPC in the execution queue;
and reserving the current behavior state which does not meet the second migration condition and the corresponding stable NPC in the non-execution queue.
According to a second aspect of the present disclosure, there is provided an apparatus for managing an NPC of a non-player character based on a state machine, comprising:
the system comprises a first determining module, a second determining module and a third determining module, wherein the first determining module is used for responding to a starting instruction of a user to the system and determining active NPCs forming an execution queue and stable NPCs forming a non-execution queue in the system;
the first queue state migration module is used for traversing the execution queue every preset unit time, and meanwhile, performing corresponding queue state migration on each active NPC in the execution queue based on a matching result of the current behavior state of the active NPC and a first migration condition;
the second determining module is used for determining the number of times of traversal of the execution queue after the execution queue is traversed;
a second queue state migration module, configured to perform, every time the number of times of traversal reaches a predetermined threshold, corresponding queue state migration on each stable NPC in the non-execution queue based on a matching result of a current behavior state of the stable NPC and a second migration condition after a next preset unit time;
and the recording module is used for responding to a closing instruction of a user to the system, recording the final behavior states of all the NPCs and closing the system.
According to a third aspect of the present disclosure, there is provided an electronic device for managing an NPC of a non-player character based on a state machine, comprising:
a memory configured to store executable instructions;
a processor configured to execute executable instructions stored in the memory to perform the above-described method.
According to a fourth aspect of the present disclosure, there is provided a computer readable storage medium storing computer program instructions which, when executed by a computer, cause the computer to perform the method described above.
Compared with the conventional technology in which the NPC of the non-player character is managed by circularly traversing the states of all NPCs in the system and then controlling the actions of the NPCs according to the states of the NPCs, the embodiment of the disclosure divides the NPCs into the execution queue and the non-execution queue, circularly traverses the states of the NPCs in the execution queue and then controls the actions of the NPCs according to the states of the NPCs. Meanwhile, whenever the number of traversal times reaches a predetermined threshold, the state of the NPC in the non-execution queue is determined, and the NPC meeting the execution condition is placed in the execution queue. By the method, only the NPC in the execution queue needing to control the action execution is circularly traversed, and the NPC management efficiency is improved.
Additional features and advantages of the disclosure will be set forth in the detailed description which follows, or in part will be obvious from the description, or may be learned by practice of the disclosure.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
FIG. 1 illustrates a flow diagram for managing a non-player character NPC based on a state machine according to an example embodiment of the present disclosure.
Fig. 2 illustrates a block diagram of an apparatus for managing an NPC of a non-player character based on a state machine according to an example embodiment of the present disclosure.
Fig. 3 illustrates a detailed flowchart for determining active NPCs constituting an execution queue and stable NPCs constituting a non-execution queue in a system in response to a user's start-up instruction for the system according to an example embodiment of the present disclosure.
Fig. 4 illustrates a detailed flow chart for determining the initial behavior state of all NPCs in the system according to an example embodiment of the present disclosure.
Fig. 5 is a detailed flowchart illustrating the determination of active NPCs constituting an execution queue and stable NPCs constituting a non-execution queue based on the matching result of the initial behavior states of all NPCs and the preset execution condition according to an example embodiment of the present disclosure.
Fig. 6 is a detailed flowchart illustrating traversing the execution queue every preset unit time, and performing corresponding queue state migration on each active NPC in the execution queue based on a matching result between the current behavior state of the active NPC and a first migration condition according to an example embodiment of the present disclosure.
Fig. 7 illustrates a detailed flowchart for determining the number of traversals of the execution queue each time the execution queue is traversed, according to an example embodiment of the present disclosure.
Fig. 8 is a detailed flowchart illustrating a corresponding queue state transition performed on each stable NPC in the non-execution queue after the next preset unit time based on a matching result between the current behavior state of the stable NPC and a second transition condition each time the number of traversals reaches a predetermined threshold according to an example embodiment of the present disclosure.
FIG. 9 illustrates a diagram of an electronic device that manages a non-player character NPC based on a state machine according to an example embodiment of the present disclosure.
FIG. 10 illustrates a diagram of a computer-readable storage medium for managing a non-player character NPC based on a state machine according to an example embodiment of the present disclosure.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, be embodied in many different forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of example embodiments to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of embodiments of the disclosure. One skilled in the relevant art will recognize, however, that the subject matter of the present disclosure can be practiced without one or more of the specific details, or with other methods, components, devices, steps, and the like. In other instances, well-known technical solutions have not been shown or described in detail to avoid obscuring aspects of the present disclosure.
Furthermore, the drawings are merely schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and thus their repetitive description will be omitted. Some of the block diagrams shown in the figures are functional entities and do not necessarily correspond to physically or logically separate entities. These functional entities may be implemented in the form of software, or in one or more hardware modules or integrated circuits, or in different networks and/or processor devices and/or microcontroller devices.
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
An object of the present disclosure is to improve the efficiency of managing NPCs of non-player characters from a technical aspect. A method for managing NPC of a non-player character based on a state machine according to one embodiment of the present disclosure includes: responding to a starting instruction of a user to a system, and determining active NPCs forming an execution queue and stable NPCs forming a non-execution queue in the system; traversing the execution queue every other preset unit time, and meanwhile, carrying out corresponding queue state migration on each active NPC in the execution queue based on a matching result of the current behavior state of the active NPC and a first migration condition; determining the number of times of traversal of the execution queue after traversing the execution queue; when the number of traversal times reaches a preset threshold value, after the next preset unit time, performing corresponding queue state migration on each stable NPC in the non-execution queue based on a matching result of the current behavior state of the stable NPC and a second migration condition; and responding to a closing instruction of a user to the system, recording the final behavior states of all NPCs and closing the system. Compared with the conventional technology in which the NPC of the non-player character is managed by circularly traversing the states of all NPCs in the system and then controlling the actions of the NPCs according to the states of the NPCs, the embodiment of the disclosure divides the NPCs into the execution queue and the non-execution queue, circularly traverses the states of the NPCs in the execution queue and then controls the actions of the NPCs according to the states of the NPCs. Meanwhile, whenever the number of traversal times reaches a predetermined threshold, the state of the NPC in the non-execution queue is determined, and the NPC meeting the execution condition is placed in the execution queue. By the method, only the NPC in the execution queue needing to control the action execution is circularly traversed, and the NPC management efficiency is improved.
FIG. 1 shows a flow diagram for managing a non-player character NPC based on a state machine according to an example embodiment of the present disclosure:
step S100: responding to a starting instruction of a user to a system, and determining active NPCs forming an execution queue and stable NPCs forming a non-execution queue in the system;
step S110: traversing the execution queue every other preset unit time, and meanwhile, carrying out corresponding queue state migration on each active NPC in the execution queue based on a matching result of the current behavior state of the active NPC and a first migration condition;
step S120: determining the number of times of traversal of the execution queue after traversing the execution queue;
step S130: when the number of traversal times reaches a preset threshold value, after the next preset unit time, performing corresponding queue state migration on each stable NPC in the non-execution queue based on a matching result of the current behavior state of the stable NPC and a second migration condition;
step S140: and responding to a closing instruction of a user to the system, recording the final behavior states of all NPCs and closing the system.
Hereinafter, each step of managing the non-player character NPC based on the state machine in the present exemplary embodiment will be explained and explained in detail with reference to the drawings.
In step S100, in response to a start instruction of a system from a user, an active NPC constituting an execution queue and a stable NPC constituting a non-execution queue in the system are determined.
An active NPC refers to an NPC that interacts with a virtual article, or other NPC, in the system to perform corresponding actions, such as: eating and attacking.
Stable NPC refers to NPC without any interaction, for example: NPC in sleep state.
By the method, the system can perform cycle traversal on the active NPC in the execution queue, so that the execution action of the active NPC is further controlled.
In one embodiment, the NPC has an attribute that is predetermined in the system: the nutritional value is in the range of 0-100. When the nutritional value is greater than or equal to 50, the NPC is in a satiety state, and the NPC is controlled to keep standing still; when the nutrition value is more than 0 and less than 50, the NPC is in a hungry state, and the NPC is controlled to cry; when the nutrition value is reduced to 0, NPC dies, controls NPC to make a falling motion, and eliminates NPC from the picture after a preset time. Wherein, the stable NPC refers to the NPC standing still, and the active NPC refers to the NPC making crying movement.
In one embodiment, as shown in fig. 3, step S100 includes:
step S1001: responding to a starting instruction of a user to a system, and determining the initial behavior states of all NPCs in the system;
step S1002: and determining active NPCs forming an execution queue and stable NPCs forming a non-execution queue in the system based on the matching result of the initial behavior states of all the NPCs and preset execution conditions.
The behavior state refers to the form that NPC shows on the behavior level, and different forms correspond to different behaviors.
The preset execution condition refers to a condition for determining whether the NPC can execute a corresponding action.
By the method, the system divides all NPCs into active NPCs in the execution queue capable of executing the corresponding action and stable NPCs in the non-execution queue incapable of executing the corresponding action.
In one embodiment, as shown in fig. 4, step S1001 includes:
step S10011: acquiring a record which is closest to the current time point and is stored by a system and related to the behavior states of all NPCs;
step S10012: and determining the behavior states of all NPCs in the record as the initial behavior states of all NPCs.
In this way, the initial behavior state of all NPCs at system start-up is determined.
In one embodiment, after receiving a system startup instruction from a user, the latest record about the behavior states of all NPCs is found from the database. The record shows that when the nutritional value of NPC a is 72, the nutritional value of NPC b is 33, the nutritional value of NPC c is 64, and the nutritional value of NPC d is 45, the initial state of NPC a (72) corresponds to a satiety state, the initial state of NPC b (33) corresponds to a hunger state, the initial state of NPC c (64) corresponds to a satiety state, and the initial state of NPC d (45) corresponds to a hunger state. In this example, the significance of NPC nail (72) is: the current nutritional value of NPC nails is 72, and this expression will be continued in the following description.
In one embodiment, as shown in fig. 5, step S1002 includes:
step S10021: determining the initial behavior state meeting the preset execution condition and the corresponding NPC as the active NPC;
step S10022: determining the initial behavior state which does not meet the preset execution condition and the corresponding NPC as the stable NPC;
step S10023: sequentially placing the active NPCs in the execution queue according to the sequence of the determination time of the initial behavior states of all the NPCs;
step S10024: and sequentially placing the stable NPCs in the non-execution queue according to the determined time sequence of the initial behavior states of all the NPCs.
Determining the NPC which needs to execute the action currently as the active NPC by comparing the initial behavior state of the NPC with a preset execution condition, and forming an execution queue; and determining the NPC which does not need to execute the action currently as the stable NPC, and composing a non-execution queue.
In one embodiment, the predetermined execution condition is: the NPC is starved. In the system, the initial state of NPC A is a satiety state, the initial state of NPC B is a hunger state, the initial state of NPC C is a satiety state, and the initial state of NPC D is a hunger state. If the NPC B and the NPC D meet the preset execution conditions, the NPC B and the NPC D are determined to be active NPC, and correspondingly, the members in the execution queue are as follows: NPC B and NPC D; if the NPC A and the NPC C which do not meet the preset execution condition are NPC A and NPC C, determining the NPC A and the NPC C to be stable NPC, and correspondingly, the members in the non-execution queue are as follows: NPC A and NPC C.
In step S110, the execution queue is traversed every preset unit time, and meanwhile, corresponding queue state migration is performed on each active NPC in the execution queue based on a matching result of the current behavior state of the active NPC and a first migration condition.
The first migration condition is used for judging whether the active NPC needs to be removed from the execution queue or not and is placed in a condition of a non-execution queue.
Queue status refers to the representation of the NPC on the queue where it is located, for example: an execution queue, or a non-execution queue.
Queue state transition refers to the transfer of the NPC from the current queue to another queue.
By the method, the queue state is periodically updated for the active NPC in the system, and the active NPC is controlled to execute corresponding actions.
In one embodiment, as shown in fig. 6, step S110 includes:
step S1101: determining the current behavior state of each active NPC in the execution queue at intervals of a preset unit time;
step S1102: reserving the current behavior state meeting the first migration condition and the corresponding active NPC in the execution queue;
step S1103: determining the current behavior state which does not meet the first migration condition and the corresponding active NPC as a stable NPC;
step S1104: removing the stable NPC from the execution queue and placing the stable NPC in the non-execution queue.
In one embodiment, the preset unit time is 5s, and the first transition condition is: the NPC is still starved. In the case where the player does not make any instruction to the NPC, the nutritional value of the NPC decreases by 5 per unit time. When the system is started, the queue is executed: NPC B (33), NPC D (45); non-execution queue: NPC A (72), NPC C (54).
And 5s after the system is started, traversing the execution queue: NPC B (28) and NPC D (40), wherein the NPC B meets the first migration condition and is kept in the execution queue; after the system is started for 7s, the player sends an instruction of feeding to the NPC B, and the nutrition value of the NPC B is increased by 30; after 10s of system startup, traverse the execution queue: NPC B (58) and NPC D (35), and if the NPC B does not meet the first migration condition, the NPC B is determined to be stable NPC, removed from the execution queue and placed in the non-execution queue.
In step 120, each time the execution queue is traversed, the number of times the execution queue has been traversed is determined.
By counting the traversed times of the execution queue in real time, the system can control the management of the NPC in the non-execution queue according to the traversed times.
In one embodiment, as shown in fig. 7, step S120 includes:
step S1201: adding 1 to a current value of a preset variable after traversing the execution queue, wherein an initial value of the preset variable is 0;
step S1202: determining a value of the variable as the number of traversals of the execution queue.
In one embodiment, the preset initial value of the variable is 0, and after the system is started for 5s and the execution queue is traversed for one time, the value of the variable is determined to be 1; after the system is started for 10s, the execution queue is traversed for one time, and the value of the variable is determined to be 2; similarly, each pair of execution queues performs one traversal, and adds 1 to the value of the variable.
In step S130, each time the number of traversal times reaches a predetermined threshold, after the next preset unit time, performing corresponding queue state migration on each stable NPC in the non-execution queue based on a matching result between the current behavior state of the stable NPC and a second migration condition.
The second migration condition is used for judging whether the stable NPC needs to be removed from the non-execution queue and placed in the condition of the execution queue.
By the method, the system carries out queue state migration on the NPCs in the non-execution queue, and the purpose of updating the queue states of all the NPCs is achieved.
In one embodiment, as shown in fig. 8, step S130 includes:
step S1301: determining the current behavior state of each stable NPC in the non-execution queue after the next preset unit time every time the number of traversed times reaches a preset threshold;
step S1302: determining the current behavior state meeting the second migration condition and the corresponding stable NPC as an active NPC;
step S1303: removing the active NPC from the non-execution queue and placing the active NPC in the execution queue;
step S1304: and reserving the current behavior state which does not meet the second migration condition and the corresponding stable NPC in the non-execution queue.
In one embodiment, the predetermined threshold for the number of traversed times is an integer multiple of 3, such as: 3. 6, 9, 12 … … second migration condition: the NPC is starved. After the system starts for 15s, traversing the execution queue: and (3) the NPC (30), the number of the traversal times is 3, and the non-execution queue is traversed when a preset threshold value is reached. After 15s has elapsed, the non-execution queue: NPC A (57), NPC B (53), and NPC C (39). And if the NPC (39) meeting the second migration condition is the NPC C (39), the NPC (39) is determined to be the active NPC, removed from the non-execution queue and placed in the execution queue. Meanwhile, NPC A (57) and NPC B (53) which do not satisfy the second migration condition remain in the non-execution queue.
In one embodiment, in response to a user shutdown command to the system, the final behavioral state of all NPCs is recorded and the system is shut down. The final behavior state of the NPC is the initial behavior state of the NPC when the system is started next time.
In an embodiment, as shown in fig. 2, there is provided an apparatus for managing an NPC of a non-player character based on a state machine, specifically including:
the first determining module 210 is configured to determine, in response to a start instruction of a user on a system, an active NPC forming an execution queue and a stable NPC forming a non-execution queue in the system;
a first queue state migration module 220, configured to traverse the execution queue every preset unit time, and perform corresponding queue state migration on each active NPC in the execution queue based on a matching result of the current behavior state of the active NPC and a first migration condition;
a second determining module 230, configured to determine the number of times the execution queue has been traversed each time the execution queue is traversed;
a second queue state transition module 240, configured to perform, every time the number of times of traversal reaches a predetermined threshold, corresponding queue state transition on each stable NPC in the non-execution queue after a next preset unit time based on a matching result of a current behavior state of the stable NPC and a second transition condition;
and the recording module 250 is used for responding to a closing instruction of the system by a user, recording the final behavior states of all the NPCs and closing the system.
The implementation process of the functions and actions of each module in the device is specifically described in the implementation process of the corresponding step in the method for managing the NPC of the non-player character based on the state machine, and is not described herein again.
It should be noted that although in the above detailed description several modules or units of the device for action execution are mentioned, such a division is not mandatory. Indeed, the features and functionality of two or more modules or units described above may be embodied in one module or unit, according to embodiments of the present disclosure. Conversely, the features and functions of one module or unit described above may be further divided into embodiments by a plurality of modules or units.
Moreover, although the steps of the methods of the present disclosure are depicted in the drawings in a particular order, this does not require or imply that the steps must be performed in this particular order, or that all of the depicted steps must be performed, to achieve desirable results. Additionally or alternatively, certain steps may be omitted, multiple steps combined into one step execution, and/or one step broken down into multiple step executions, etc.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, or by software in combination with necessary hardware. Therefore, the technical solution according to the embodiments of the present disclosure may be embodied in the form of a software product, which may be stored in a non-volatile storage medium (which may be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which may be a personal computer, a server, a mobile terminal, or a network device, etc.) to execute the method according to the embodiments of the present disclosure.
In an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above method is also provided.
As will be appreciated by one skilled in the art, aspects of the present invention may be embodied as a system, method or program product. Thus, various aspects of the invention may be embodied in the form of: an entirely hardware embodiment, an entirely software embodiment (including firmware, microcode, etc.) or an embodiment combining hardware and software aspects that may all generally be referred to herein as a "circuit," module "or" system.
An electronic device 400 according to this embodiment of the invention is described below with reference to fig. 9. The electronic device 400 shown in fig. 9 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 9, electronic device 400 is embodied in the form of a general purpose computing device. The components of electronic device 400 may include, but are not limited to: the at least one processing unit 410, the at least one memory unit 420, and a bus 430 that couples various system components including the memory unit 420 and the processing unit 410.
Wherein the storage unit stores program code that is executable by the processing unit 410 to cause the processing unit 410 to perform steps according to various exemplary embodiments of the present invention as described in the above section "exemplary methods" of the present specification. For example, the processing unit 410 may perform step S100 as shown in fig. 1: responding to a starting instruction of a user to a system, and determining active NPCs forming an execution queue and stable NPCs forming a non-execution queue in the system; step S110: traversing the execution queue every other preset unit time, and meanwhile, carrying out corresponding queue state migration on each active NPC in the execution queue based on a matching result of the current behavior state of the active NPC and a first migration condition; step S120: determining the number of times of traversal of the execution queue after traversing the execution queue; step S130: when the number of traversal times reaches a preset threshold value, after the next preset unit time, performing corresponding queue state migration on each stable NPC in the non-execution queue based on a matching result of the current behavior state of the stable NPC and a second migration condition; step S140: and responding to a closing instruction of a user to the system, recording the final behavior states of all NPCs and closing the system.
The storage unit 420 may include readable media in the form of volatile storage units, such as a random access memory unit (RAM)4201 and/or a cache memory unit 4202, and may further include a read only memory unit (ROM) 4203.
The storage unit 420 may also include a program/utility 4204 having a set (at least one) of program modules 4205, such program modules 4205 including, but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may comprise an implementation of a network environment.
Bus 430 may be any bus representing one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
The electronic device 400 may also communicate with one or more external devices 500 (e.g., keyboard, pointing device, bluetooth device, etc.), with one or more devices that enable a user to interact with the electronic device 400, and/or with any devices (e.g., router, modem, etc.) that enable the electronic device 400 to communicate with one or more other computing devices. Such communication may occur via input/output (I/O) interfaces 450. Also, the electronic device 400 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the internet) via the network adapter 460. As shown, the network adapter 460 communicates with the other modules of the electronic device 400 over the bus 430. It should be appreciated that although not shown in the figures, other hardware and/or software modules may be used in conjunction with electronic device 400, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, or by software in combination with necessary hardware. Therefore, the technical solution according to the embodiments of the present disclosure may be embodied in the form of a software product, which may be stored in a non-volatile storage medium (which may be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which may be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the embodiments of the present disclosure.
In an exemplary embodiment of the present disclosure, there is also provided a computer-readable storage medium having stored thereon a program product capable of implementing the above-described method of the present specification. In some possible embodiments, aspects of the invention may also be implemented in the form of a program product comprising program code means for causing a terminal device to carry out the steps according to various exemplary embodiments of the invention described in the above section "exemplary methods" of the present description, when said program product is run on the terminal device.
Referring to fig. 10, a program product 600 for implementing the above method according to an embodiment of the present invention is described, which may employ a portable compact disc read only memory (CD-ROM) and include program code, and may be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited in this regard and, in the present document, a readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
A computer readable signal medium may include a propagated data signal with readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A readable signal medium may also be any readable medium that is not a readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device and partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., through the internet using an internet service provider).
Furthermore, the above-described figures are merely schematic illustrations of processes involved in methods according to exemplary embodiments of the invention, and are not intended to be limiting. It will be readily understood that the processes shown in the above figures are not intended to indicate or limit the chronological order of the processes. In addition, it is also readily understood that these processes may be performed synchronously or asynchronously, e.g., in multiple modules.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This application is intended to cover any variations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.

Claims (9)

1. A method for managing NPCs of a non-player character based on a state machine, the method comprising:
responding to a starting instruction of a user to a system, and determining active NPCs forming an execution queue and stable NPCs forming a non-execution queue in the system;
traversing the execution queue every other preset unit time, and meanwhile, carrying out corresponding queue state migration on each active NPC in the execution queue based on a matching result of the current behavior state of the active NPC and a first migration condition;
adding 1 to a current value of a preset variable after traversing the execution queue, and determining the value of the variable as the traversed times of the execution queue, wherein the initial value of the preset variable is 0;
when the number of traversal times reaches a preset threshold value, after the next preset unit time, performing corresponding queue state migration on each stable NPC in the non-execution queue based on a matching result of the current behavior state of the stable NPC and a second migration condition;
and responding to a closing instruction of a user to the system, recording the final behavior states of all NPCs and closing the system.
2. The method of claim 1, wherein the determining active NPCs constituting an execution queue and stable NPCs constituting a non-execution queue in the system in response to a user start instruction to the system comprises:
responding to a starting instruction of a user to a system, and determining the initial behavior states of all NPCs in the system;
and determining active NPCs forming an execution queue and stable NPCs forming a non-execution queue in the system based on the matching result of the initial behavior states of all the NPCs and preset execution conditions.
3. The method of claim 2, wherein determining the initial behavior state of all NPCs in the system comprises:
acquiring a record which is closest to the current time point and is stored by a system and related to the behavior states of all NPCs;
and determining the behavior states of all NPCs in the record as the initial behavior states of all NPCs.
4. The method of claim 2, wherein the determining active NPCs forming an execution queue and stable NPCs forming a non-execution queue based on the matching result of the initial behavior states of all NPCs and a preset execution condition comprises:
determining the initial behavior state meeting the preset execution condition and the corresponding NPC as the active NPC;
determining the initial behavior state which does not meet the preset execution condition and the corresponding NPC as the stable NPC;
sequentially placing the active NPCs in the execution queue according to the sequence of the determination time of the initial behavior states of all the NPCs;
and sequentially placing the stable NPCs in the non-execution queue according to the determined time sequence of the initial behavior states of all the NPCs.
5. The method of claim 1, wherein traversing the execution queue every preset unit time, and performing corresponding queue state migration on each active NPC in the execution queue based on a matching result of a current behavior state of the active NPC and a first migration condition comprises:
determining the current behavior state of each active NPC in the execution queue at intervals of a preset unit time;
reserving the current behavior state meeting the first migration condition and the corresponding active NPC in the execution queue;
determining the current behavior state which does not meet the first migration condition and the corresponding active NPC as a stable NPC;
removing the stable NPC from the execution queue and placing the stable NPC in the non-execution queue.
6. The method of claim 1, wherein the performing a corresponding queue state transition for each stable NPC in the non-execution queue after a next preset unit time based on a matching result of a current behavior state of the stable NPC and a second transition condition each time the number of traversed times reaches a predetermined threshold comprises:
determining the current behavior state of each stable NPC in the non-execution queue after the next preset unit time every time the number of traversed times reaches a preset threshold;
determining the current behavior state meeting the second migration condition and the corresponding stable NPC as an active NPC;
removing the active NPC from the non-execution queue and placing the active NPC in the execution queue;
and reserving the current behavior state which does not meet the second migration condition and the corresponding stable NPC in the non-execution queue.
7. An apparatus for managing NPCs of a non-player character based on a state machine, comprising:
the system comprises a first determining module, a second determining module and a third determining module, wherein the first determining module is used for responding to a starting instruction of a user to the system and determining active NPCs forming an execution queue and stable NPCs forming a non-execution queue in the system;
the first queue state migration module is used for traversing the execution queue every preset unit time, and meanwhile, performing corresponding queue state migration on each active NPC in the execution queue based on a matching result of the current behavior state of the active NPC and a first migration condition;
a second determining module, configured to add 1 to a current value of a preset variable after the execution queue is traversed, and determine the value of the variable as the number of times the execution queue has been traversed, where an initial value of the preset variable is 0;
a second queue state migration module, configured to perform, every time the number of times of traversal reaches a predetermined threshold, corresponding queue state migration on each stable NPC in the non-execution queue based on a matching result of a current behavior state of the stable NPC and a second migration condition after a next preset unit time;
and the recording module is used for responding to a closing instruction of a user to the system, recording the final behavior states of all the NPCs and closing the system.
8. An electronic device for managing an NPC of a non-player character based on a state machine, comprising:
a memory configured to store executable instructions;
a processor configured to execute executable instructions stored in the memory to implement the method of any of claims 1-6.
9. A computer-readable storage medium, characterized in that it stores computer program instructions which, when executed by a computer, cause the computer to perform the method according to any one of claims 1-6.
CN201811482751.6A 2018-12-05 2018-12-05 Method for managing NPC (non-player character) based on state machine and related equipment Active CN109646959B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811482751.6A CN109646959B (en) 2018-12-05 2018-12-05 Method for managing NPC (non-player character) based on state machine and related equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811482751.6A CN109646959B (en) 2018-12-05 2018-12-05 Method for managing NPC (non-player character) based on state machine and related equipment

Publications (2)

Publication Number Publication Date
CN109646959A CN109646959A (en) 2019-04-19
CN109646959B true CN109646959B (en) 2022-03-08

Family

ID=66112711

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811482751.6A Active CN109646959B (en) 2018-12-05 2018-12-05 Method for managing NPC (non-player character) based on state machine and related equipment

Country Status (1)

Country Link
CN (1) CN109646959B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112657187A (en) * 2020-12-24 2021-04-16 北京像素软件科技股份有限公司 NPC control method, device, server and storage medium

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101957751A (en) * 2010-06-04 2011-01-26 福建星网锐捷网络有限公司 Method and device for realizing state machine
CN102142009A (en) * 2010-12-09 2011-08-03 华为技术有限公司 Method and device for matching regular expressions
CN102467414A (en) * 2010-11-19 2012-05-23 阿里巴巴集团控股有限公司 State machine control method, device and state machine system
CN103116685A (en) * 2011-11-17 2013-05-22 苏州蜗牛数字科技股份有限公司 Interaction method of game player and non-player character (NPC) in network games
CN103577704A (en) * 2013-11-13 2014-02-12 北京像素软件科技股份有限公司 Event handling method and device through NPC in game system
CN105117575A (en) * 2015-06-17 2015-12-02 深圳市腾讯计算机系统有限公司 Behavior processing method and device
CN105204935A (en) * 2015-09-30 2015-12-30 北京奇虎科技有限公司 Automatic server opening method and device
CN106390456A (en) * 2016-09-30 2017-02-15 腾讯科技(深圳)有限公司 Generating method and generating device for role behaviors in game

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101957751A (en) * 2010-06-04 2011-01-26 福建星网锐捷网络有限公司 Method and device for realizing state machine
CN102467414A (en) * 2010-11-19 2012-05-23 阿里巴巴集团控股有限公司 State machine control method, device and state machine system
CN102142009A (en) * 2010-12-09 2011-08-03 华为技术有限公司 Method and device for matching regular expressions
CN103116685A (en) * 2011-11-17 2013-05-22 苏州蜗牛数字科技股份有限公司 Interaction method of game player and non-player character (NPC) in network games
CN103577704A (en) * 2013-11-13 2014-02-12 北京像素软件科技股份有限公司 Event handling method and device through NPC in game system
CN105117575A (en) * 2015-06-17 2015-12-02 深圳市腾讯计算机系统有限公司 Behavior processing method and device
CN105204935A (en) * 2015-09-30 2015-12-30 北京奇虎科技有限公司 Automatic server opening method and device
CN106390456A (en) * 2016-09-30 2017-02-15 腾讯科技(深圳)有限公司 Generating method and generating device for role behaviors in game

Also Published As

Publication number Publication date
CN109646959A (en) 2019-04-19

Similar Documents

Publication Publication Date Title
US11748389B1 (en) Delegated decision tree evaluation
US11269656B2 (en) Method and device for setting operating system
WO2023221979A1 (en) Control method and apparatus for virtual robot, and device, storage medium and program product
CN115209965A (en) Provision management for video games during game preview
CN109646959B (en) Method for managing NPC (non-player character) based on state machine and related equipment
CN114647550A (en) Process control method, device, storage medium and electronic equipment
CN112807695B (en) Game scene generation method and device, readable storage medium and electronic equipment
CN113407343A (en) Service processing method, device and equipment based on resource allocation
WO2023169173A1 (en) Memory cleaning method and apparatus, storage medium, and electronic device
CN116866661A (en) Video prerendering method, device, equipment and storage medium
CN114092608B (en) Expression processing method and device, computer readable storage medium and electronic equipment
US10608900B2 (en) Generating a deferrable data flow
CN114090054A (en) Intelligent equipment upgrading method and device, storage medium and electronic equipment
CN115193048A (en) Virtual item processing method and device, storage medium and electronic equipment
CN114669055A (en) Control method and device based on game running environment, electronic equipment and computer program product
CN114116090A (en) Information display method and device, electronic equipment and computer readable storage medium
WO2021084101A1 (en) Systems and methods for replacing a theme of a virtual environment
CN113365171B (en) Screen sound box processing method and device, electronic equipment and storage medium
CN114816629B (en) Method and device for drawing display object, storage medium and electronic device
US20230409387A1 (en) Automatic selection of computer hardware configuration for data processing pipelines
CN109033768B (en) Charging method and device based on intelligent mobile terminal and terminal
CN106775465A (en) Date storage method, device and electronic equipment
CN115373840A (en) Map management method, map management device, storage medium and electronic device
WO2024130954A1 (en) Game skill processing method and apparatus, computer storage medium, and electronic device
US20230122202A1 (en) Grounded multimodal agent interactions

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant