Questions tagged [chess]

Chess is a strategic game played with two players on a checkered grid. This tag is for challenges related to chess or any variation on chess.

Filter by
Sorted by
Tagged with
13 votes
3 answers
2k views

Print all legal chess moves

The game of chess has moves. Lots of moves. But how many, exactly? In this challenge, you must print all possible chess moves for a single player (black or white — you choose). Moves are distinguished ...
anatolyg's user avatar
  • 13.6k
8 votes
3 answers
711 views

Implement a 2-player version of 1D Chess

The game is played on a 1x8 board with the following setup: KNR..rnk White's pieces are on the left, while black's pieces are on the right. The king (K) can move 1 ...
Quadruplay's user avatar
10 votes
5 answers
530 views

Is the king in check?

Challenge: Given a 2D array (8x8) of characters, is the enemy king in check? The program should return true if and only if the king is currently in check. Standard chess rules apply. Specifications: ...
Mickey's user avatar
  • 111
10 votes
5 answers
771 views

Find the Chess960 starting positions from its integer ID

Chess960, a.k.a. Fisher random chess, is a variation of the game of chess. In classic chess the starting positions are always the same. In chess960 they vary. Before each game of chess960 one random ...
Kjetil S's user avatar
  • 5,897
12 votes
7 answers
1k views

Horsey sightseeing

A knight's tour is a sequence of moves of a knight on a chessboard such that the knight visits every square only once. For those who are not aware of how knights in chess work, knights are capable of ...
totallyhuman's user avatar
  • 17.2k
16 votes
9 answers
594 views

Minimal number of jumps to reach a square

A Knight in chess moves two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of a capital L) Given a Knight current ...
Luis felipe De jesus Munoz's user avatar
10 votes
5 answers
1k views

Decode Chess Move

As the title says, given a valid chess move in algebraic notation, produce the string describing the move. Example: ...
Luis felipe De jesus Munoz's user avatar
19 votes
14 answers
2k views

Rook Polynomials

In combinatorics, the rook polynomial \$R_{m,n}(x)\$ of a \$m \times n\$ chessboard is the generating function for the numbers of arrangements of non-attacking rooks. To be precise: $$R_{m,n}(x) = \...
alephalpha's user avatar
6 votes
0 answers
348 views

Crazyhouse chess KoTH

What is Crazyhouse Chess? Crazyhouse Chess is a chess variant that is basically normal chess except you can place a piece you previously captured back on the board instead of a regular turn. Bot ...
user avatar
25 votes
16 answers
4k views

Is it a plausible chess move?

Not a duplicate of the valid move challenge because that asks for specific pieces. Backstory The other night I was doing a little trolling with ChatGPT and chess. I was trying to get it to call me out ...
lyxal's user avatar
  • 33.3k
8 votes
4 answers
383 views

Simultaneously solve N-queens and no-3-in-line

An intriguing MathsSE question asked if there were large N-queens solutions where no three queens lie on a line. That question's body included the unique 4×4 solution up to symmetries ...
Parcly Taxel's user avatar
  • 3,737
9 votes
3 answers
365 views

Knook to Mate... With Portals!

Alternatively: Now you're checking with portals! Inspired this challenge I am somewhat of a self-declared Chess Anarchist. That means that when I play chess, en passant is forced (else the brick gets ...
lyxal's user avatar
  • 33.3k
24 votes
18 answers
3k views

Knight to fork!

In chess, fork means to target two pieces with just one piece, and one of the best pieces for forking is the knight. In this challenge, you will be given three coordinates in ...
Mehan Alavi's user avatar
6 votes
2 answers
377 views

Is this position a pure mirror mate?

Task A pure mirror checkmate is a checkmate position, where the mated king is surrounded by 8 empty squares which are attacked or guarded by the winning side exactly once. You will be given a valid ...
double-beep's user avatar
12 votes
0 answers
486 views

Is it a legal atomic chess move?

Background and Rules There is a variant of chess called atomic chess, which follows essentially the same rules as normal chess, except that pieces explodes other pieces around them when captured. In ...
Aiden Chow's user avatar
  • 13.3k
11 votes
3 answers
386 views

Parlett's movement notation

Some chess variants use interesting non-standard pieces. In order to concisely describe new pieces or to describe pieces without requiring everyone to memorize a bunch of non-standard names some new ...
Wheat Wizard's user avatar
  • 98.7k
22 votes
9 answers
1k views

A pieceful standoff

This challenge requires a small amount of knowledge about chess. A description of the details required can be found at the bottom if you are not familiar with chess or want a refresher. For a certain ...
Wheat Wizard's user avatar
  • 98.7k
26 votes
14 answers
3k views

Print every Fool's Mate

In chess, the Fool's Mate is the fastest possible way to reach checkmate. It is reached with Black's second move. In chess notation, one possible sequence of moves that achieves Fool's Mate is ...
Pandu's user avatar
  • 722
9 votes
3 answers
1k views

The smallest number of steps for a chess piece to reach a position

I have previously posted a challenge, smallest number of steps for a knight in chess. Now I would like to go a step further by adding the possibility to choose your piece. If you place a piece on any ...
Bjop's user avatar
  • 435
33 votes
31 answers
5k views

A challenge for rookies

Print or return the following string: ...
Sisyphus's user avatar
  • 14.8k
24 votes
15 answers
3k views

smallest number of steps for a knight in chess

If you place a knight on any square of a chessboard, what is the smallest amount of steps to reach every position? Rules It is an 8 by 8 board. The knight starts at an arbitrary position, taken as ...
Bjop's user avatar
  • 435
24 votes
8 answers
2k views

Seeing the queen's lasers

In chess, the queen piece can move arbitrarily far in each cardinal and intercardinal direction. What does this mean? Well, I'll show you with an ASCII drawing: ...
thejonymyster's user avatar
12 votes
11 answers
2k views

Convert Descriptive Notation to Algebraic Notation

Introduction Many old chess books use descriptive notation to notate squares on a chessboard, naming the file (column) of the square based on the starting piece positions of White or Black, depending ...
qwr's user avatar
  • 12.1k
23 votes
35 answers
4k views

Generate All 8 Knight's Moves

Introduction In chess, Knights can move two squares in one direction, and then one square in an orthogonal direction. On an x/y plane, these can be thought of as being a relative change of coordinates,...
chakra's user avatar
  • 330
12 votes
7 answers
742 views

Knights Jam | Chess

The knight is a chess piece that, when placed on the o-marked square, can move to any of the x-marked squares (as long as they ...
DialFrost's user avatar
  • 5,079
18 votes
11 answers
1k views

Identify a "reverse checkers" position

Task A reverse checkers position is a chess position where every piece for one player is on one colour and every piece for the other player is on the other colour. Your task is to find if the given (...
double-beep's user avatar
25 votes
31 answers
3k views

Generate the Chess Numbers™

I was browsing Stack Overflow when I saw this post in Puzzling in the hot network questions and decided to make a challenge out of it (all credit goes to the creator of the challenge). Overview A ...
Seggan's user avatar
  • 5,317
24 votes
12 answers
2k views

Greedy queens sequence

Challenge Implement the "greedy queens" sequence (OEIS: A065188). Details Taken from the OEIS page. This permutation [of natural numbers] is produced by a simple greedy algorithm: starting ...
pajonk's user avatar
  • 16k
10 votes
0 answers
377 views

Chess Squad March

Find the moves that bring a chess squad to a given destination. You control a chess squad consisting of a king and several other pieces, on a larger chess board. Your army is placed so that no piece ...
Valentin Brasso's user avatar
23 votes
13 answers
1k views

Generalised multi-dimensional chess knight's moves

Multi-dimensional chess is an extension of normal chess that is played on an 8x8x8x8... "board". In normal 2D chess, a knight's move is a movement by a vector of \$ \begin{bmatrix} \pm 2 \\ \...
pxeger's user avatar
  • 23.7k
13 votes
8 answers
1k views

Is this FEN board a Fischer random chess starting board?

Introduction Fischer random chess, also known as Chess960 for the 960 valid starting boards, is a variant of chess where each player's pieces are randomly shuffled at the start. As a reminder, each ...
qwr's user avatar
  • 12.1k
18 votes
9 answers
1k views

Dimensional Chess positions

Task Any one of these two: Determine if a given position (an ordered non-empty collection of integers in the range ‒8 to 8, or ‒7 to 7 if you want) is a valid Dimensional Chess position. List all the ...
Adám's user avatar
  • 30.2k
24 votes
4 answers
2k views

Is it a chess cycle?

Inspired by a discussion from the Esolangs.org unofficial Discord Server. Instructions A chess cycle is an arrangement of a chess board where each piece must attack one other piece, and only one other ...
Razetime's user avatar
  • 27.1k
9 votes
5 answers
432 views

Print the Najdorf Sicilian

The Najdorf Variation of the Sicilian Defence is an opening often played at the highest level of chess. It is named after GM Miguel Najdorf and is known for being extremely sharp and theory heavy. ...
EnderShadow8's user avatar
  • 1,429
10 votes
1 answer
347 views

Win a KQ vs K endgame

Win a K vs KQ endgame Summary The goal of this challenge is to create a program or function which will win a Chess game with a King and Queen against a lone King. The user will specify three squares, ...
79037662's user avatar
  • 2,999
26 votes
2 answers
650 views

Chess murder mystery

You know how many and which kinds of chess pieces were murdered. Can you come up with any possibility for who killed whom and how? Background During the course of a game of chess, there are between 2 ...
A. Rex's user avatar
  • 2,579
33 votes
12 answers
3k views

The Knight's Dialer

Imagine you place a knight chess piece on a phone dial pad. This chess piece moves from keys to keys in an uppercase "L" shape: two steps horizontally followed by one vertically, or one step ...
Olivier Grégoire's user avatar
11 votes
4 answers
418 views

Holey Knight's Tour

Given a rectangular board of cells with some number of holes in it, determine whether it is possible to complete a "holey knight's tour" (That is, a path that visits every non-hole cell exactly once ...
Beefster's user avatar
  • 9,931
13 votes
6 answers
978 views

Counting Queen's paths on a rectangular chessboard

Task Given two positive integers \$m,n\$, imagine a chessboard of size \$m \times n\$. A chess queen is on the upper-left corner. In how many ways can it reach the lower-right corner, by moving only ...
Bubbler's user avatar
  • 76k
117 votes
10 answers
11k views

Totally Blind Chess

In this challenge, you play chess without seeing any of your opponent's pieces or moves. Or your own pieces. Or whether your own moves succeeded. You send only a stream of moves, with no feedback. If ...
feersum's user avatar
  • 31.4k
34 votes
28 answers
3k views

Count rook moves 1D

Given a position with a row of rooks and/or empty spaces, output how many different rook moves are possible. A rook can move left or right to an empty space, but not to one that requires passing over ...
xnor's user avatar
  • 145k
15 votes
3 answers
1k views

Is it checkmate?

Wholly surprised this hasn't been posted already, given the large number of chess puzzles on the site. While I thought of this myself, credit to Anush for posting it to the sandbox back in March. But ...
Christian Legge's user avatar
13 votes
8 answers
2k views

Is this draw by repetition?

Problem: In chess, there is a somewhat well known rule about draw by repetition. If the same position is repeated 3 times (or more) then the player intending to make the move which will cause the this ...
Expired Data's user avatar
  • 4,001
2 votes
1 answer
197 views

Find all diagonal counts in only one direction [closed]

If I need to get the number of diagonal squares in all directions: I do the following formula 2 N − 2 − |x − y| − |x + y − N − 1| The above example has 13 and ...
Ibrahim Ali's user avatar
17 votes
6 answers
742 views

Passwords Strong Against Bishops

Not to be confused with Password Bishop Goodness! Given a string, answer (truthy/falsy or two consistent values) if it constitutes a password which is strong against bishops. A password is strong ...
Quuxplusone's user avatar
48 votes
8 answers
3k views

N-movers: How much of the infinite board can I reach?

Single moves The board is an infinite 2 dimensional square grid, like a limitless chess board. A piece with value N (an N-mover) can move to any square that is a distance of exactly the square root ...
trichoplax is on Codidact now's user avatar
24 votes
3 answers
2k views

The Path Of The Wildebeest

Golf a program or function which gives the \$n^{\text{th}}\$ location of the wildebeest who starts at square \$1\$ on an infinite chessboard which is numbered in an anti-clockwise square spiral, where ...
Jonathan Allan's user avatar
17 votes
5 answers
1k views

How many moves?

Given two different positions on a chess board and the type of piece, output the minimum number of moves it will take for that piece to go from one position to another. Rules The given piece can be ...
Vedant Kandoi's user avatar
21 votes
11 answers
2k views

A knight's graph on an N-by-N board

In chess, a knight can only move to the positions marked with X relative to its current position, marked with ♞: A Knight's Graph is a graph that represents all legal moves of the knight chess piece ...
Stewie Griffin's user avatar
11 votes
1 answer
515 views

Recording xiangqi moves

The game of xiangqi, also known as Chinese chess, is a chess-like game popular in China, Vietnam, Taiwan, and other East Asian countries. The colours of the two sides in xiangqi are red and black. ...
l4m2's user avatar
  • 23.9k