My Android dev blog
Linux support I guess

Linux support I guess

I spent the last few days working on porting the game to PC. I had already completed the very basics including all the 3D rendering a month ago or so. Now Text rendering, inputs and most of the misc stuff like charts work as well.
I previously had no real UI scaling (It would always be enlarged in the same manner as the screen size was enlarged). Of course this was bullshit so I am currently working on getting proper scaling going.

I spent the last few days working on porting the game to PC. I had already completed the very basics including all the 3D rendering a month ago or so. Now Text rendering, inputs and most of the misc stuff like charts work as well.

I previously had no real UI scaling (It would always be enlarged in the same manner as the screen size was enlarged). Of course this was bullshit so I am currently working on getting proper scaling going.

Mipmapping and anisotropic filtering

AI Insights #2

On-Line Planning

An On-Algortihm has refers to an algorithm which does not just receive an input and calculates the fitting output (eg. Input: Goal, Output: Plan) but rather continously reads inputs and reacts with outputs.

That is, we do not directly formulate our plan and instead perform the search “live”. We use a stack containing the objectives to be achieved and start from the current position and introduce the goal objective. The inital goal objective will be requested from the Behavior Model to gibve the AI goals which are conformant with its behavioral parameters. Then in each time step we do the following:

  1. Can we directly fullfil the current objective with some action? If so, execute that action. Mark the current objective as finished.
  2. Is it not possible to achieve the current objective as of now but there exists a sub objective which would make the current objective achievable? Introduce this sub objective and make it our new current objective.
  3. Are we unable to do anything to get closer to achieving our goal?
    Pass.
  4. Should the objective not have been completed within the time limit, mark the current objective a failed and make pop it from the stack.

Note that using a stack for achieving our objectives limits the planning capabilities. In traditional partial-order planning achieving a state of the form “Goal A AND Goal B” is complicated because we cant just first achieve Goal A and then Goal B. After all, we may no longer satisfy goal A after achieving Goal B.

This is why we need to be critical when introducing new sub objectives or executing an action to achieve a sub objective. We must always inquire the entire stack if this new objective/action is conformant with all lower objectives. 

The following example demonstrates how the AI may reason with this kind of approach and how the interaction between the Planning Model and the Behavior Model looks like.

image

The AI attempts to formulate a plan to expand its number of holdings, however, while trying to make money to stock up the troops, it realized that it cannot realize the goal and eventually the objective times out.

From here on the AI must reevaluate whether the objective to expand the army should still be pursued or if it should be popped from the stack. Fo example, the target X may have by now lost troops due to another war and a declaration of war at this point of time might befeasable.

AI Insights #1

I want to write a bit about the AI in Sword&Scrolls, so here we go.

When tackling AI for systems involving different aspects such as warfare, diplomacy and management it can be hard to even figure out where to start. So for anybody interested and working on his own strategy game AI, I wanted to provide some insight into how the AI in Sword&Scroll is built and operates.

Models

The starting point is, as always with complex systems, to divide the problem into smaller sub problems and solve these independently and then add interaction at a later point.

The AI of Sword&Scroll consists of several Models (also called agents in the literature). A model is nothing but one component of the AI system dedicated to solving one sub problem. Models may be request information from other models and ask them to solve something for them. In the terminology of traditional AI a construct like this is called multi-agent-system.

image

Sword&Sword uses 3 models to drive the behavior of the AI.

  1. The Planning Model is responsible for tasks which require consistency in the long term and where one has to perform a chain of basic actions to achieve a result.
    For example, in order to win in a war against somebody with a larger army, you need to expand your own army. This in return requires money which must be acquired. In other words, the AI needs to be able to perform some sort of logical reasoning.
  2. The Behavior Model takes unique parametrization of the AI into account. For example, we may not want everybody to be a war-mongerer and act differently.
    In contrast to the other models, this model does not perform any direct actions. Instead it manifests the uinque AI behavior by providing the other models with means for judging how good an action (or the gamestate resulting from an action) would be and by choosing parameters for their actions.
  3. The Army Model ensures that the AI can fight wars. In contrast to the Planning Problem where we have many actions which must be executed in the right order, the army model only has 1 significant action: MoveArmyToPosition(X) (Note that not-moving can also be modeled with this action)
    The important task lies in finding the right parameter X.

If you have ever worked on a tactical RPG or some of these consorts you will probably also have used an approach entailing the models 2. and 3. Therefore today I would like to go more into depth regarding the Planning Model.

Planning Model

Lets start of with a very basic question. What is planning?

Planning involves finding a sequence of actions to satisfy a given goal from a given state.

Examples for some goals may be:

  • Expand Holdings
  • Make Money
  • Expand Army
  • Seek Independence

Typically, planning is done in a sort of backtrack search. We start with the goal state and introduce intermediate goals we can achieve via some action until we have found a valid plan.

In Sword&Scroll I want to have many agents. But in each iteration there are several possible actions (building something, sending diplomats, asking for marriage, etc) and to make matters worse most of them have parameters. For example SendDiplomat(X) requires the parameter to whom we want to send a diplomat. This blows up the search space.

We therefore relax the planning problem. Instead of searching for completely specified actions to reach our main goal we dont care about the exact parameters. Instead, we ask the Behavior Model to provide us for any given action the parameters which it thinks suit the AI behavior the most and would be profitable for it.

This approach still leaves two big problem:

  1. The game state changes as time passes, possible invalidating our plan and taking “invalidation of a plan” into account will increase the planning complexity again.
  2. Even with a small set of possible actions developing plans which may take in ingame-time several years to execute (like conquering a holding) the calculation time for the planning will explode.

The second point is especial crucial as I dont want the game to just have 1 AI, but dozens and each having at least a certain degree of playing capabilities. In order to deal with these issues we further relax the Planning Problem.

summer->winter transition and back

summer->winter transition and back

waterfalls

waterfalls

we real politics now

we real politics now

Intrigues, spies and favor

My old machine kinda died and when I got a new laptop I kinda ended up realizing that I could play modern gaems on decent settings on it, so yea… I there went the dev time in the past week. Anyways, I’ve got my fill and heres some progress about implementing intrigues and also how I intend to continue on with this.

Intrigues work similarly as in CKII, you start a plot against some target (For example fabricating a claim on a holding from him) and then you look for supporters who want to support your plot.

If you ask somebody to help you with your plot he gains favor points over you. These points can be used in return to force you to support their plots later on (refusing to repay a favor hits your honor) or also to force you to lend them a loan (Currently there are no other uses, but I intend to add more things).

Each plot requires a certain amount of plot points (I seriously need some cooler names than X points later on) to be realized. These are gathered slowly over time and instantly by receiving supporters. The amount of plot points a House can contribute depends on their court power which reflects their influence on the House you wish to intrigue against. This influence can be increased by marriage, sending a diplomat, being a branch family, being the overlord and also by infiltrating the target House with a spy.

Fabricating claims and planting a spy in the target House are currently the two intrigues I implemented.

A spy enables you to see the military strength of the target House, what they are currently building and it makes it easier to perform intrigues. I will probably also introduce intrigues which are only possible when you have a spy. These are how things stand right now. Next let me talk on how I want to I currently plan to continue this (I say currently because I have revised this entire intrigue thingy dozens of times and I may do it again).

So what are the backdraws when inviting supporters? One thing is, as I mentioned, that they will gain favor over you which they can use against you. There will also be a diplomatic option to reveal a plot to the target House. There will be two ways which enable revealing a plot:

  1. If you are a supporter of the plot you can go and betray the guy who invited you and reveal the plot
  2. There will be a special intrigue which requires you to have planted a spy and which will then reveal what the target House is currently plotting.

In the same way you will also be able to reveal spies. If a plot is revealed it will become more difficult to perform it. Revealed spies will be killed off.

If your plot has been revealed, you will be informed about it, but you will not necessarily know who revealed it. You will only be told who revealed your plot if you have a spy at the target House.

Well, that basically covers my plans for the spy business. I dont want to expand this game mechanic too much since this is not a spy infiltration game.

Pillaging time

Pillaging time