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
24 votes
13 answers
2k 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 ...
  • 707
8 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 ...
  • 405
30 votes
29 answers
4k views

A challenge for rookies

Print or return the following string: ...
  • 12.9k
22 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 ...
  • 405
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: ...
11 votes
11 answers
1k 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 ...
  • 11.2k
12 votes
7 answers
717 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 ...
  • 3,049
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 (...
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 ...
  • 3,635
22 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 ...
  • 12.3k
9 votes
0 answers
339 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 ...
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 \\ \...
  • 22.6k
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 ...
  • 11.2k
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 ...
  • 28.3k
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 ...
  • 26.3k
8 votes
5 answers
397 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. ...
  • 1,399
9 votes
1 answer
326 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, ...
  • 2,949
26 votes
2 answers
604 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 ...
  • 2,539
32 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 ...
11 votes
4 answers
379 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 ...
  • 9,791
13 votes
6 answers
971 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 ...
  • 66.1k
113 votes
10 answers
10k 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 ...
  • 30.9k
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 ...
  • 139k
14 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 ...
  • 964
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 ...
  • 3,981
2 votes
1 answer
192 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 ...
14 votes
5 answers
644 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 ...
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 ...
  • 10.7k
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 ...
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 ...
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 ...
11 votes
1 answer
468 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. ...
  • 13k
9 votes
0 answers
425 views

The N Queens Problem, but with Fairy Chess Pieces

Fairy Chess is a sort of generalized chess that allows unconventional pieces. The eight queens puzzle is a classic problem where you have to put 8 queens on a chess board such that no two queens ...
  • 9,791
26 votes
8 answers
2k views

Mutually Attacking Queens

Let an 8x8 chessboard be represented by any two distinct values, with one value being an empty square and the other being a queen. In the following examples, I use 0s as the empty squares and 1s as ...
  • 879
26 votes
10 answers
2k views

Knight Distance

In Chess, a Knight on grid \$(x, y)\$ may move to \$(x-2, y-1)\$, \$(x-2, y+1)\$, \$(x-1, y-2)\$, \$(x-1, y+2)\$, \$(x+1, y-2)\$, \$(x+1, y+2)\$, \$(x+2, y-1)\$ or \$(x+2, y+1)\$ in one step. Imagine ...
  • 30.8k
27 votes
1 answer
688 views

Three-Dimensional Chess

In order to defend someone’s baffling decision, people often say that that person is going over everyone’s heads and playing “3-dimensional chess”. Now it’s your chance to play 3-dimensional chess! ...
  • 6,546
20 votes
4 answers
3k views

Is it a valid chess move?

Alternate name: ChessMoveQ Given a list of up to 32 elements, each consisting of 4 elements, and a second list with 4 elements, determine whether the move detailed ...
21 votes
11 answers
4k views

Where can the knight be in N moves?

This is Hole-3 from The Autumn Tournament of APL CodeGolf. I am the original author of the problem there, and thus allowed to re-post it here. Given: a number of turns (please state if no movements ...
  • 28.3k
30 votes
50 answers
10k views

How many Wazirs can be placed on an N×N Chessboard?

Suppose a new fairy chess piece named the Wazir is introduced to chess. Wazirs can move from a position (x, y) to:  (x+1, y)  (x, y+1)  (x-1, y)  (x, y-1) That is, they move orthogonally like the rook,...
  • 467
19 votes
5 answers
1k views

Is this a losing square?

There is a game called Get Home that is played on the a chess board. In this game there is a single piece that is moved by both players in turns. There are some rules to how the piece can be moved. ...
  • 90k
26 votes
4 answers
790 views

When Fibonacci meets the Queens

(inspired by Helka's response to my random pairing of "chess" and "Fibonacci" tags in chat) Fibonacci The Fibonacci numbers are one of the more well-known sequences in mathematics, where each number ...
  • 42.9k
16 votes
12 answers
2k views

N-Queens Puzzle

(Despite 60+ questions tagged chess, we don't have a simple n-queens challenge.) In chess, the N-Queens Puzzle is described as follows: Given an n x n chessboard ...
  • 42.9k
9 votes
2 answers
1k views

Smallest chess game compression

Inspiration: Heavily inspired by Smallest chess board compression I decided to make a similar but distinctly different competition. tl;dr Take the file Chess_Games.txt and compress it as much as ...
  • 235
16 votes
4 answers
619 views

Peaceable coexisting armies

In the game of chess, there is piece called the queen that may attack any other piece that is on the same row, column or diagonal. In chess there are typically two sides, black and white, with each ...
  • 90k
12 votes
6 answers
702 views

Is this string valid FEN?

The challenge Write a program or function which takes a string input as a function parameter or from stdin and determines if it is a valid FEN string. Input You can assume the input will only ever ...
  • 783
17 votes
4 answers
555 views

Knight-fill a grid

A knight fill is a flood fill using the connectivity of the knight chess piece. Specifically: 1 1 1 1 0 1 1 1 1 (0 is the initial point, 1s show the ...
  • 8,351
17 votes
6 answers
723 views

Working on my Knight moves

Hexagonal chess describes a family of chess variants played on a board where the cells are hexagons instead of the traditional squares. There are many such variants; in this challenge we'll be ...
  • 42.9k
19 votes
5 answers
862 views

Chess Analysis with Limited Information

In this challenge, you are given a limited amount of information about a particular game of chess, and you need to predict who won the game. You are given two sets of data: Piece counts (What pieces ...
26 votes
2 answers
885 views

Escape a chessboard

You find yourself on a chessboard, as one does. You can see the exit but it is awfully far away and you would rather not walk all the way. Luckily some locals have offered you a ride. A Knight, a ...
  • 90k
1 vote
0 answers
318 views

Generalization of Eight Queen Puzzle [closed]

Here's one generalized version of the famous Eight Queen's Puzzle: Given an n × n chess board, and an integer ...
  • 147