Refactoring AI

Wrote new code? Fixed a bug? Want to discuss technical stuff? Feel free to post it here.

Moderator: Moderators

EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Refactoring AI

#1 Post by EternalHarvest »

Suggestion: reorganize main AI the same way as homunculus AI was reorganized. There's already some steps in such a direction in svn, just to show how it can be done. That's also for a possible reduce of copy-pasted code all over the slave AI.
Last edited by EternalHarvest on 07 Jul 2010, 00:41, edited 1 time in total.
User avatar
kLabMouse
Administrator
Administrator
Posts: 1301
Joined: 24 Apr 2008, 12:02

Re: Refactoring AI

#2 Post by kLabMouse »

EternalHarvest wrote:Suggestion: reorganize main AI the same way as homunculus AI was reorganized. There's already some steps in such a direction in svn, just to show how it can be done. That's also for a possible reduce of copy-pasted code all over the slave AI.

AI::Slave → AI::Actor::Slave extending Actor::Slave and AI::Actor

AI stuff from Globals, AI.pm, AI::CoreLogic, AI::Attack → AI::Actor::You extending Actor::You and AI::Actor
Nice Idea.
I think, It should be Implemented till OpenKore 2.2 Release.
But, PLEASE Do not touch the OpenKore 2.1 AI Yet.
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: Refactoring AI

#3 Post by EternalHarvest »

Inspected code, but haven't tested results at all (and there are some pseudo-code things that won't compile).

Added Actor support to tasks.

Merged ai_route, slave_route into Actor->route;
processRoute, Slave::processRouteAI into Task::Route;
processMove into Task::Move.

http://openkore.pastebin.com/3bx6Nc6E
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: Refactoring AI

#4 Post by EternalHarvest »

Examples of entities wanted:

1. Base Actor classes (abstract)
BaseActor (examples of class members: nameString) - top-level abstract class with minimal stuff for actors
BaseActor::You - abstract class for main user-controlled (or AI controlled) object

2. Real Actor classes with custom roles, properties and network bindings
RagnarokActor (implementing roles for "object in 2D world", "object with statuses" etc - these are needed too)
RagnarokActor::You (inventory, cart, network bindings)
RagnarokActor::Homunculus (custom properties, network bindings)

3. AI classes
ActorAI (queue, task manager, iterate, queue_attack/queue_route) - top-level abstract class with stuff for AI
ActorAI::You (queue_sit/queue_stand) - main user-controlled object AI, linked with Actor::You kind of object
ActorAI::Homunculus (queue_feed) - custom AI for custom object
User avatar
kLabMouse
Administrator
Administrator
Posts: 1301
Joined: 24 Apr 2008, 12:02

Re: Refactoring AI

#5 Post by kLabMouse »

EternalHarvest wrote:Examples of entities wanted:
3. AI classes
ActorAI (queue, task manager, iterate, queue_attack/queue_route) - top-level abstract class with stuff for AI
ActorAI::You (queue_sit/queue_stand) - main user-controlled object AI, linked with Actor::You kind of object
ActorAI::Homunculus (queue_feed) - custom AI for custom object
Why Do we need ActorAI Classes???
As we want to get loose of AI Queue, we will not need em anymore.
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: Refactoring AI

#6 Post by EternalHarvest »

kLabMouse wrote:Why Do we need ActorAI Classes???
As we want to get loose of AI Queue, we will not need em anymore.
Functions to launch tasks, task manager.
And until AI queue is gone, it's still here.
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: Refactoring AI

#7 Post by EternalHarvest »

Common things in tasks:

Waiting for Network::IN_GAME
- can this be done with mutexes?

Arguments handling and validating
- can be handled in base class

Code: Select all

sub interrupt { $self->{interruptionTime} = time }
sub resume { $self->{giveup}{time} += time - $self->{interruptionTime} }
- can be handled in base class with unified method of storing timeouts in tasks
User avatar
kLabMouse
Administrator
Administrator
Posts: 1301
Joined: 24 Apr 2008, 12:02

Re: Refactoring AI

#8 Post by kLabMouse »

EternalHarvest wrote: Waiting for Network::IN_GAME
- can this be done with mutexes?
Better use Events
EternalHarvest wrote: Arguments handling and validating
- can be handled in base class

Code: Select all

sub interrupt { $self->{interruptionTime} = time }
sub resume { $self->{giveup}{time} += time - $self->{interruptionTime} }
- can be handled in base class with unified method of storing timeouts in tasks
Agree.
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: Refactoring AI

#9 Post by EternalHarvest »

kLabMouse wrote:Better use Events
Give an example?
User avatar
kLabMouse
Administrator
Administrator
Posts: 1301
Joined: 24 Apr 2008, 12:02

Re: Refactoring AI

#10 Post by kLabMouse »

EternalHarvest wrote:
kLabMouse wrote:Better use Events
Give an example?
Network push Event "IN_GAME" to AI, and unlock it's functioning.
the Event System is Native, and you do not need constantly check for that Var.