Questions tagged [chess]

This tag is for the game of Chess and problems getting computers to play it. Use this tag for questions about algorithms and other programming problems specifically related to chess playing. Do not use this tag for general programming questions just because your program plays chess.

Chess is a strategic, symmetrical board game with the goal of placing the opponent's leader piece, known as the King, under attack from one of your pieces such that they are unable to avoid being captured by the next turn. This is known as being placed in "checkmate".

Computer chess engines have become increasingly complex since the early 2000s when they became able to beat the world's leading chess grand masters. Some of the leading chess engines as of 2022 are the opensource Stockfish and Google's AlphaGo.

One might presume that due to the deterministic nature of chess it might be possible to "solve" the game such that a victory or draw would be guaranteed. However, due to the enormous number of possible variations in Chess it remains unsolved even by the most advanced chess engines.

Some current popular evaluation methods used are the Monte Carlo tree search and Minimax search.

External links

1386 questions
110
votes
27 answers

Is there a perfect algorithm for chess?

I was recently in a discussion with a non-coder person on the possibilities of chess computers. I'm not well versed in theory, but think I know enough. I argued that there could not exist a deterministic Turing machine that always won or stalemated…
Overflown
  • 1,830
  • 2
  • 19
  • 25
108
votes
3 answers

What is the significance of initializing direction arrays below with given values when developing chess program?

I am new to competitive programming, and I noticed frequently, many of the great coders have these four lines in their code (particularly in those involving arrays): int di[] = { 1, -1, 0, 0, 1, -1, 1, -1 }; int dj[] = { 0, 0, 1, -1, 1, -1, -1, 1…
ejjyrex
  • 1,151
  • 1
  • 10
  • 13
106
votes
19 answers

Knight's Shortest Path on Chessboard

I've been practicing for an upcoming programming competition and I have stumbled across a question that I am just completely bewildered at. However, I feel as though it's a concept I should learn now rather than cross my fingers that it never comes…
Kyle Hughes
  • 1,369
  • 3
  • 14
  • 13
100
votes
31 answers

Programmer Puzzle: Encoding a chess board state throughout a game

Not strictly a question, more of a puzzle... Over the years, I've been involved in a few technical interviews of new employees. Other than asking the standard "do you know X technology" questions, I've also tried to get a feel for how they approach…
Andrew Rollings
  • 14,340
  • 7
  • 51
  • 50
89
votes
4 answers

What are some good resources for writing a chess engine?

I'm interested in writing a chess engine (mostly as a learning exercise) and would be interested in any resources that people know of that could be of interest or use, anything really: Papers, Books, Theory, Tutorials, anything that could be useful.
Paul Wicks
  • 62,960
  • 55
  • 119
  • 146
88
votes
3 answers

Object Oriented Design for a Chess game

I am trying to get a feel of how to design and think in an Object Oriented manner and want to get some feedback from the community on this topic. The following is an example of a chess game that I wish to design in an OO manner. This is a very broad…
Sid
  • 1,093
  • 1
  • 9
  • 11
50
votes
13 answers

How hard is it to implement a chess engine?

I'm wondering how hard it would be to implement a chess engine. Are there already open-source implementations? It seems that you'd need a scoring function for a given board constellation, and a very fast way of exploring several likely future board…
Frank
  • 64,140
  • 93
  • 237
  • 324
33
votes
3 answers

Chess game in JavaScript

Is there any Chess game API , purely written in JavaScript ? No Flash! Anybody know the algorithm(in general) used in Chess games ?
sat
  • 40,138
  • 28
  • 93
  • 102
33
votes
4 answers

Using the Universal Chess Interface

I'm planning on making a program that interfaces with a UCI chess engine. I've been doing some research on it, but I want to get a little more information before I get more in depth with it. I was wondering if any of you could provide a few example…
Nathan
  • 73,987
  • 14
  • 40
  • 69
29
votes
8 answers

How to program a neural network for chess?

I want to program a chess engine which learns to make good moves and win against other players. I've already coded a representation of the chess board and a function which outputs all possible moves. So I only need an evaluation function which says…
caw
  • 30,999
  • 61
  • 181
  • 291
27
votes
14 answers

How do I model a chessboard when programming a computer to play chess?

What data structures would you use to represent a chessboard for a computer chess program?
slm
  • 861
  • 2
  • 10
  • 12
23
votes
4 answers

How to find magic bitboards?

const int BitTable[64] = { 63, 30, 3, 32, 25, 41, 22, 33, 15, 50, 42, 13, 11, 53, 19, 34, 61, 29, 2, 51, 21, 43, 45, 10, 18, 47, 1, 54, 9, 57, 0, 35, 62, 31, 40, 4, 49, 5, 52, 26, 60, 6, 23, 44, 46, 27, 56, 16, 7, 39, 48, 24, 59, 14, 12, 55,…
paulwal222
  • 1,488
  • 11
  • 18
23
votes
12 answers

Chess Optimizations

ok, so i have been working on my chess program for a while and i am beginning to hit a wall. i have done all of the standard optimizations (negascout, iterative deepening, killer moves, history heuristic, quiescent search, pawn position evaluation,…
twolfe18
  • 2,228
  • 4
  • 24
  • 25
19
votes
1 answer

Alpha-beta prunning with transposition table, iterative deepening

I'm trying to implement alpha-beta min-max prunning enhanced with transposition tables. I use this pseudocode as reference: http://people.csail.mit.edu/plaat/mtdf.html#abmem function AlphaBetaWithMemory(n : node_type; alpha , beta , d : integer) :…
18
votes
5 answers

12 dominating knights puzzle (backtracking)

I've been searching for hours and haven't found a fully working solution for this kind of puzzle yet. So I followed similar problem with bishops. What I need to do is place 12 knights on the chess board in such a way, that all free squares of the…
RendoJack
  • 366
  • 1
  • 5
  • 17
1
2 3
92 93