Chess engines use a complex algorithm called a search tree to calculate and evaluate the possible moves in a game of chess. The search tree algorithm allows the engine to analyze the possible outcomes of every possible move several moves ahead, so the engine can make an informed decision about which move is best.

The logic used by chess engines can be broken down into several steps:
- Generate all possible legal moves: The engine generates a list of all the possible moves for the current player.
- Evaluate each move: The engine uses a scoring system to evaluate each move based on factors such as the value of the piece being moved, the position of the piece on the board, and the potential threats and opportunities presented by the move.
- Build a search tree: The engine creates a search tree to evaluate each possible move several moves ahead. This search tree allows the engine to calculate the possible outcomes of every possible move and to determine which move is most likely to lead to a winning position.
- Prune the search tree: The engine prunes the search tree to eliminate branches that are unlikely to lead to a winning position. This helps to speed up the analysis and reduce the number of calculations needed to find the best move.
- Choose the best move: The engine uses the search tree to identify the move that is most likely to lead to a winning position. The move is then executed, and the process starts over again for the next turn.
Overall, the logic used by chess engines is based on evaluating the potential outcomes of each move and selecting the move that is most likely to lead to a winning position. This requires a sophisticated algorithm that can calculate and evaluate thousands of possible moves in a matter of seconds.