How computer works in playing chess?

Sort:
Sqod
HGMuller wrote:
This is usually handled by having a double set of parameters, one valid for the opening phase, the other for the end-game phase, and then interpolating between the resulting evaluations based on some 'phase' indicator, usually the material present (e.g. 8*nQ + 4*nR + 2*nB + 2*nN, where nQ is the number of Queens (opponent or total), etc.). The 'piece-square table' for the King (which for every square lists the number of points it is worth to have a King there) used for the end-game evaluation then strongly encourages centralization, while the King-Safety term is absent. And in the opening evaluation you would use a PST that strongly encourages a King to be in/near one of his own corners, and give very large penalties for squares near it that are attacked by opponent pieces.
 
As to the arrays:
 
One usually does not store trees. The search just traverses them, using a recursive tree walk. Usually the trees are too big to fit in RAM, and using disk is too slow to be competative. So one makes a tree walk to a certain nominal depth, and then when there is time left, completely redoes the tree walk with some more nodes spreouting from the former end leaves. You try to save some info on as many nodes as you can in a 'transposition table', organized as a hash table. Typivally only the score (and whether that was exact or just a lower or upper bound), the best move, and the depth of the search that provided that info (to judge if it is accurate enough to use straight away when you encounter it again, or that you need to redo the search with a larger depth or to get a sharper bound on the score).
 
 

Thanks.

I was thinking about this yesterday, and came up with a solution similar to what you described. Just because the move number is high (say 40) doesn't mean the position is necessarily in the endgame. For example, the Ruy Lopez is really odd-looking because it keeps almost all the pieces on the board for dozens of moves into the game. The board looks like somebody scrambled it from the initial position, without removing any pieces!) Therefore it is largely the number of pieces on the board that determines the "age" of the position. There might be other interesting measures of game age, though, like a count of how far the pieces have moved from their original positions (e.g., imagine a game that went something like 1. Nf3 Nf6 2. Ng1 Ng8 3. Nc3 Nc6 4. Nb1 Nb8 5. Na3 Na6, etc. for a while!). The count of pawn advances might also be a good indicator. An ideal learning system, though maybe too lengthy to be practical, would be to use that age value as a continuous variable that influenced the heuristics proportionally as they were learned.

I think I understand what you're saying about tree search. I suppose after the search, which is done node-by-node without saving all the nodes along the way, reaches its end, an evaluation score is made and assigned to the node that started the search, so the search itself was merely regarded as the scratchpad derivation of the score, and is regarded as unworthy of being saved. (Human memory doesn't work that way--it saves everything it sees, at least for a while, but we'll ignore that observation.) OK, that makes sense, thanks.

P.S.--A quote for nartreb/bertran:

----------

Our starting point [was that] we don't care about intelligence. We really care about just computational speed—what happens, you just put in speed. And it's interesting. For people doing massive computation, that's how you can speed things up, [and it's] a very interesting problem by itself. But, at the end, when we actually tried to beat Kasparov, we realized something: that you really need to put the intelligence in [as well]. You need to put the chess knowledge in. Because then the compounding effect, the fact that search was going to enhance your knowledge, become even more pronounced.

http://arstechnica.com/gaming/2011/08/force-versus-heuristics-the-contentious-rise-of-computer-chess/2/

HGMuller
Sqod wrote:
I think I understand what you're saying about tree search. I suppose after the search, which is done node-by-node without saving all the nodes along the way, reaches its end, an evaluation score is made and assigned to the node that started the search, so the search itself was merely regarded as the scratchpad derivation of the score, and is regarded as unworthy of being saved. (Human memory doesn't work that way--it saves everything it sees, at least for a while, but we'll ignore that observation.) OK, that makes sense, thanks.

Exactly. The basic routine of almost all Chess programs is something like:

Search(depth)

{

  if(ProbeHashTable(depth) == OK) return HashTableScore();

  bestScore = -INFINITE;

  if(depth <= 0) bestScore = Evaluation();

  for(move = NextMove()) {

    if(depth > 0 || Is_Capture(move)) {

      MakeMove(move);

      score = -Search(depth-1);

      UnMakeMove(move);

      if(score > bestScore) { bestScore = score, bestMove = move; }

    }

  }

  SaveInHashTable(bestScore, bestMove);

  return bestScore;

}

 

(Where I left out the technical details of alpha-beta pruning, but which contains a capture search and transposition table.)

Sqod

Thanks.

Aha, recursive functions! Yes, recursive functions could replace trees of pointers. I never thought of that; I just thought chess programs probably used pointers.

but

O.o

Saving this thread for future reference...intersting.

Sqod

I keep thinking about this thread, too, especially since my field is computers and A.I. Here are a few additional thoughts I had since this thread was raging:

(1) I'd love to see a forum here just about computer chess. I have a large number of ideas for chess-related programs, especially for improving them. Much of that information would be too specialized or technical for the average chess player, so I'm hesitant to post it anywhere here.

(2) Here are some quotes I came across recently that support what I was saying earlier in this thread:

(p. 17)
   It is not enough to know that combinations arise from forced
moves; it is also necessary to show why the possibilities for
combinations exist. For example, it is very seldom possible to
mate the enemy king quickly if it is defended by pawn cover,
has many pieces nearby for defense, and has plenty of room to
maneuver. In such a position it makes no practical sense to
search for a mating combination. But if the enemy king is
confined and has few defenders and weak pawn cover, then
experienced players will know that a mating combination may
be possible. The same situation occurs for other types
of combinations.

(p. 214)
   Chess calculation is not a simple matter of "If I move here,
he'll move there" repeated over and over. Calculating chess
variations is a winnowing process of first selecting a set of
moves to consider as candidates, and then using the time
available to examine these candidates in sufficient detail. In this
way you chart the course of the game, at least in the short term.
You must also consider your opponent's replies to each
candidate move based on their apparent merit. This is not a
simple matter. We have neither the time nor the mental capacity
to examine every possible move deeply and thoroughly.
Computers do that. Until quite recently, computers simply
calculated all possible replies to all possible moves. Suppose
you have a position with 30 legal moves (most positions have
even more possibilities). If you look at each position for ten
seconds, just to evaluate it by counting material or some other
simplistic method, then the first move takes 300 seconds, or five
(p. 215)
minutes to work out. But of course in reply to each of your 30
moves, the opponent may have 30 different replies, so that
zooms to 150 minutes, and you are still at move one. Since most
tournaments allow you two hours for 40 moves by each
player, this method simply isn't practical.

Palatnik, Sam, and Lev Alburt. 2013. Chess Tactics for the Tournament Player. New York, NY: Chess Information & Research Center.

(3) One problem with throwing away the explored branches of a tree search, as the above recursive function approach does, is that only a numerical score is saved before the branch is thrown away. Because of this, anything interesting noticed during that search is thrown away, and more importantly, the branches do not communicate with each other. Here's a perfect example of what I mean...

In one tournament game I had a won game since I'd won the exchange, but I was in time trouble, so for several moves before the first time control, we were moving quickly, too quickly for deep analysis. Immediately after the time control passed, I had a huge amount of time to sit there and analyze what plan I should follow next. I considered different plans like moving my rook to the 7th rank or advancing my pawns. During two of such considerations, I noticed two different checkmates, both involving my rook on the king side. The fact there was an important and common attribute between those two evaluations of different lines made me wonder if I had a *forced* checkmate somewhere that was common to *all* the lines I was searching. I remember he had his king moved up to close to the front of my pawns on the king side, way in front of the rest of his pieces, and so I looked at how he might get checkmated with my rook up there. Sure, enough, it was a mate-in-three, where all he could do is interpose a bishop to stall the mate for one move. So I moved my rook up, I believe Re5, ready to shift it laterally to the king side (that's why I hadn't seen that move before: I wasn't used to using rooks in a lateral fashion so early in the game), and I tried not to look smug while waiting for him to resign. Sure enough, after a few minutes he said quietly, "It looks like I forgot one," knocked his king over, and shook my hand. He was a higher-rated player, too.

My point is that if I'd been doing that search like a computer, I would have looked at both those lines, thrown away the interesting information I'd noted along the way, and started over from scratch on searching a new line. The two lines would have nothing that related one to the other like that. I claim that noticing a repeated pattern like that is an important part of human problemsolving, especially in chess, and that's one reason computers don't play chess as well as humans, except for their sheer speed, accuracy, and memory size.