• Register
Weekly Recap: 21-3-2016 -> 28-3-2016

In this Weekly Recap, I discuss the new AI and a couple of additional minor changes to the game.

Posted by on

## Weekly Recap

### 21-3-2016 -> 28-3-2016

Hi there! Welcome to "Weekly Recap", the series where I weekly discuss the new features which I've added into the game!

This week, I've worked on improving the strategic-ness of the game, and I've upgraded the AI to have a defense ability. Let's see how it all works!

### The AI: Defense

Defense is, although it might not seem, one of the easiest pieces of AI to code. It's not that hard to do, because it involves nothing more than a series of checks to see what's the best option. It then executes that best option, and there we have it; Done.

With that said, it's not a piece of cake either. Chess is a complex game with many different rules, and it never really comes down to "a list of standard checks", as things will vary slightly in each game. For an AI, however, this isn't really a big deal, so I went and set up a list of things for the AI to follow in order for it to select the "best opportunity".

Below is a *.gif demonstrating three examples. I'll go over each example in more detail, and why the decision made is the best decision.

You can see how the AI thinks about the problem, and then makes a particular decision. If you're a little familiar with chess, one of the three examples provided here seems a little akward, but I'll get into more detail about that one later.

### Undefended vs. defended pieces

The first scenario is a classical "undefended vs. defended" scenario. The black pawn is being threatened by two pawns from team white. Remember that pawns take diagonally, and thus are both threatening the black pawn.

The best decision for the black pawn here, is to recapture. However, which of the two pawns is best to capture?

As demonstrated in the *.gif earlier, the AI decides to take the most right pawn. We can easliy see why, by thinking ahead one step in time. Imagine if the black pawn took the left-handed pawn of team white. We can see that this pawn is "guarded" or, "defended" by another white pawn. If black were to take this pawn, he would be "re-taken" on the next turn.

However, the pawn on the right is undefended. Taking this pawn will have no negative effect for the black pawn, and he would be able to easily make a retreat, or bring more pieces in to help him out.

### Higher valued pieces

In the example above, black's bishop is being threatened by the same pawn structure we've come across before. The bishop can either of two things here; Take the pawn (and be re-taken), or move away from the threat.

The AI decided to move away from the threat, which is by far the best solution. The reason for this is really easy to explain; A bishop is worth more, relative to a pawn.

You can see why a bishop is worth more: It can move 3 tiles in one turn, instead of just 1. This makes the bishop faster vs. a pawn, and allows it to threaten multiple pieces and cause something known in Chess as a "pin" (which pawns are unable to pull off).

If the bishop were to take the pawn, it would win a pawn, but the bishop would immediatly be retaken in return. It's a lot better for the bishop to make use of it's long diagonal, and possibly renew the threat against the pawns from a safer distance.

### Higher valued pieces 2.0

Just like in the previous example, this is a case of higher valued pieces, only now in the benefit of black. Black has merely a simply pawn, under threat by white's bishop, which is protected both by a rook and a pawn!

In the *.gif, the AI makes a fundamental mistake, by taking the bishop. The reason for this happening, is because the point value of a bishop and a rook were equal, and it chose to take the bishop instead. Can you see why this was an incorrect decision?

Let's start by considering why we should take, and not simply run away. The reason is rather simple; The fact that the bishop and rook are defended, doesn't matter to the pawn at all. This is because the bishop and rook both are valued much higher than the pawn is, so "sacrificing" a pawn in order to take either a bishop or a rook, is a no-brainer move.

Of course, black's pawn would be retaken immediatly, but that's why we call it a sacrifice after all.

In our scenario, black should've taken the rook. Not the bishop. The reason for this, is that whenever black takes the bishop, the rook could simply retake black's pawn. Even though black has taken a bishop, white now has a defended rook and black has nothing to do against it.

Let's see what happens if we take the rook instead. The bishop won't be able to retake in this scenario, forcing white to retake black's pawn with his pawn. This deflects the defender of the bishop away, which could allow black to put more pressure on white's bishop, since it no longer has it's defendant.

### The minor changes

Enough of all the Chess talk. Let's go and explore what other things I've added in this week!

I've been working on one big thing, namely multi-selection. So let's cover that first. Below is a *.gif displaying how it works:

You can select multiple pawns / pieces by simply clicking on them, as demonstrated in the *.gif. You can then perform actions simultaneously. In the example above, all pieces are moved to the same square, effectively "piling up" around it.

It currently doesn't work on buildings, but I'm going to implement this anytime soon, because it's nice to multi-select buildings and destroy them all in one click, or force pawns out of multiple buildings in just one click.

I've also been working on re-balancing a couple of pieces. You can see this in the *.gif below:

The pawn hasn't changed much at all, but simply serves as reference material here.

The major changes come in the other pieces. The bishop now has to wait one turn, instead of two, before moving, but still has the same amount of squares it can move along in one turn.

The rook, on the other hand, doesn't have to wait three turns anymore, but one turn aswell. It's also able to move four squares in one turn, instead of just three.

The rook currently is a little over-powered (as a rook costs the same as a bishop), but this is going to change up a bit in the future, whenever local food usage becomes a thing. All this means, is that rooks will eat for (for example) three pawns, where bishops will eat for just two. Having more rooks thus means more farms, thus means more money, even more pawns, more terrain control, etc.

### Final words

I'll be working more on the AI next week, since it's still not perfectly polished and needs more tweaking before it's all neat-o. I've also gotten a snippet of code from Xor which allows me to add directional shading, getting rid of the annoying perspective (things further away from the light get a longer shadow now). I'll be definitely giving it a go and see if I can get it working into the game!

Aside from that, I might do a bit more balancing throughout next week, but I've got no idea what I'm going to balance, nor how I'm going to balance it. That'll all follow from all the playtesting I'll be doing during development.

That is all I have to offer for now! Thank you for reading, and maybe you got a little out of it aswell!