I want to implement a handicap for my engine and I'm struggling with it. I using alpha-beta pruning.

In my current approach I set a variance variable in centipawns and let the engine choose a move in the variance range. An example with white to move and variance = 5;

25 d2d4 d5d7 ...
23 e2e4 e5e7 ...
20 b1c3 e5e7 ...
18 g1f3 d5d7 ...

In this case the engine can choose between the first three moves cause they are all in range of 20-25. A random move of those three is picked, all other moves are ignored.

I implemented this and let it run against my "best move engine". To my surprise in 200 games the "best move engine" wins like 95% of the time. Which is in my opinion way to high.

As I dove deeper I realized that the "variance engine" picks sometimes totally blunder moves. Like sacking a queen without any compensation. I triple checked the code for picking the "random" move in the variance range. Its perfectly fine. So I think my alpha-beta is the problem here. Some questions:

  1. Should alpha-beta in general be capable of implementing something like variance picking. If so, what could I have done wrong or what am I missing?
  2. Is there another way of implementing a handicap for an engine. Couldn't really find anything on the internet.
  • Just limit the depth Commented Feb 21, 2020 at 18:35
  • 1
    Since the move choice is in the root position and not in the AB search, there should be nothing in the AB search that would affect the current move choice. You could also try to limit it's poor choice to every fifth move.
    – Mike Jones
    Commented Feb 21, 2020 at 20:30

2 Answers 2


Even one minor error could cost the game against a perfect opponent, so 95% losing rate is generous. However, I don't understand how the "best move" engine could lose any games in the second trail.

  1. The ABSearch could be modified, but it's easier to perform this at the RootSearch function. Since the arrays for the current moves and their respective scores are present here, it's easy to implement, and the RootSearch should be able to self-correct on future moves better than anything done in the current ABSearch. (This is really messy. Sorry.)

  2. I've seen three ways to limit strength.

    a. Make a weak move at a specific interval. When playing against its sponsors, a computer was told to make a random king move every 10 moves.

    b. The computer wasn't allowed to make a move in which the eval was above a threshold. So, for a drawing computer, the computer wouldn't make a move where the eval was above a pawn or had to make a mistake to lower the eval to below this range. This i similar to your variance, but instead of within the top range, it's a final eval of +- a pawn.

    c. The chess engine Galahad (I can't find its source anymore.) allowed you to change some eval constants. Lowering the penalty for a weakness, such as doubled pawns, does lower its strength, but not in a dramatic manner.

Trappy Beowulf trys to implement a more human engine where it does try for traps instead of the best move. I haven't read the code, so I can't explain how it accomplishes this, but I assumed that it goes for simple, one move threats, and when this threat is parried, the positions is slightly worse.

I"d like to give a special thanks to the four examples and the OP for thinking out of the box. Not just trying to be the best, but for being usable.

EDIT: A better example is "c" would be a piece-square value. By adjusting this variable, you could make the computer think that g3 is a better square for the knight than e5. This could be used to make the computer decentralize pieces or make them more defensive. Changing the pawn protection around the king values, you could make the computer make these weakening moves and test your attacking skills. The options are only limited by your imagination.

  • I wouldn't say my engine is playing close to perfect ;). I didn't put any effort on position evaluation yet. The engine is beating me so I guess its around 1500 elo (the "best move engine"), not more. Thats why Im surprised cause there is a large margin of error. Anyway, thanks, Im trying to think about it and if the two of you saying its possible that the win rate is that high Im ok with it.
    – Mewel
    Commented Feb 22, 2020 at 13:31

Does not sound to high to me. Actually I would expect higher.

1 Depends on all the other things your code does and how.

2 Some make mistakes at random.

You could limit how far you look into the future too.

Try making 2nd best (or slightly less good) moves but only when there are many closely evaluated ones. Avoid those bad queen sacs by just picking a really bad one when there are not really any other good alternatives.

  • I tried what you suggested. I set the variance to 1. I only picked between the best and second best move. And set the ply depth to 2. After 1000 games the "best move engine" has 600 wins, 200 draws, and 200 loses. If the variance is that low and the second best move is only picked if close to equal the best move, I think there has to be a bug in alpha-beta or something else is wrong.
    – Mewel
    Commented Feb 21, 2020 at 17:56
  • i think is your assuming what you think should happen to the strength of the two engines when they play. your results sound more reasonable now for what you are trying. see item 1 in my answer again Commented Feb 21, 2020 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.