0

I was hoping to attempt creating a bot to automatically play a video game, and was wondering if Optaplanner could be used for task planning for the bot.

The bot has a starting state, desired end state, and different tasks it can perform. The goal would be to use optaplanner to find a viable sequence of Tasks to make the bot go from the starting state to the desired end state, optimizing to be lowest cost.

Bot:

  • State:
    • items in inventory
    • current location

Task:

  • examples: gather 1 wood, craft a bucket
  • each task has "requirements" on the current state -- f(currentState) -> boolean
  • a task transitions the bot to a new state -- f(currentState) -> newState
  • has a cost heuristic: f(currentState) -> int
  • tasks can be repeated. For example, the bot may need to gather 5 wood (gather wood task, repeated 5 times)
  • tasks might go unused. For example, if the desired end state is to have a metal bucket, there is no need to perform the gather wood task.

Is this possible with Optaplanner? What is the correct way to model this problem?

Any assistance/guidance would be appreciated, I've combed through most of the Optaplanner documentation and examples already.


I've looked into @PlanningListVariable, but I'm not sure this fits my use case. The docs say:

Each planning value is assigned to exactly one planning entity.

In my case, the Task would be the planning value, and the Bot would be the planning entity (?). But, many Tasks might be unused and should not be assigned at all... so it doesn't seem correct.

es1ph
  • 1
  • 1

1 Answers1

0

This is an example of a domain/constraints that is very difficult to model in OptaPlanner. Your planning entities form an unbounded series of actions, with each action potentially affecting future actions (for instance, in order to craft a bucket, you need 3 iron, which is gathered by past actions). This means that:

  • Changing a past action will very likely violate a constraint involving future actions. This make it very hard for OptaPlanner to change past actions unless all/most actions after it are also removed.

  • You need to take a "guess" at the maximum number of actions it will take to reach your goal, since you cannot add planning entities in a move currently (https://issues.redhat.com/browse/PLANNER-2642).

What you can do instead is use OptaPlanner as the "strategy generator" for the bot. This architecture would have four components:

  • An information collector, which takes information from the screen or Minecraft API and converts it into problem facts to be used by the other components.

  • A step decider, which decides what immediate action to take in order to advance towards the given final goal. It could be something like "gather wood", "mine ore" or "get items into inventory". This would be a "short-sighted" planner; it converts the abstract final goal into a more concrete sub-goal that OptaPlanner can understand and solve.

  • A strategy generator, which creates a plan for the action decided by the step decider that the action implementer will execute. This is where OptaPlanner will come in. For each goal, you'll need to define a constraint provider that evaluates the effectiveness of a plan. For instance, for the "gather wood" action, it would be a vehicle routing problem where you route the player (acting as the vehicle) from their current location (the depot) to trees to gather wood. A plan would be the trees to visit. To overcome the fact all trees need to be visited, you would have a second virtual/fake entity that will be assigned all unvisited trees and any trees assigned to the virtual/fake entity will not impact the score.

  • The action implementer, which takes the plan generated by the strategy generator and implement it. This would be the part of the bot deciding all the inputs. It would be a "reactive" component, since it may need to deal with unforeseen problems (like a zombie). It does not make any big decisions, and try (to it best ability) to follow the plan created by the strategy generator. It is mostly responsible for navigating the world and handling combat situations.

Christopher Chianelli
  • 1,163
  • 1
  • 8
  • 8
  • Thanks for the detailed response. Regarding the second point (since you cannot add planning entities in a move): you mean it's not possible to write a custom move that modifies a PlanningListVariable (i was imagining that I would have a PlanningListVariable with a list of Tasks to perform)? – es1ph Nov 05 '22 at 04:41
  • You can create a custom move for list variables, but that move cannot create new problem facts or entities. Additionally, there are some properties that PlanningListVariable have; namely: each planning value appear in at exactly one PlanningListVariable, order matters, and the planning value cannot appear multiple times in the same PlanningListVariable. This means to add new tasks, you need to add new planning values in the custom move, which is not supported yet. Thus, you would need to precreate all possible tasks (including some that will be extras) before hand. – Christopher Chianelli Nov 05 '22 at 05:46