The Stack Overflow podcast is back! Listen to an interview with our new CEO.

# 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.

85 questions
Filter by
Sorted by
Tagged with
9k views

### Determine the color of a chess square

Your challenge is to write a program that outputs the color of a given square from the chessboard. This is how a chessboard looks: You can see that the square a1 is dark, and h1 is a light square. ...
5k views

### Knight on the Rim is Grim

Introduction Aron Nimzowitsch was a leading chess master and a influential chess writer. In his book 'My System', the first chapter deals about the importance of the center and why you should ...
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 ...
6k views

### Smallest chess board compression

Write an algorithm or program that can encode and decode a chess board. The goal is to make the smallest representation of a chessboard that could be used (once decoded) to determine all movement ...
5k views

For the non-zero digits on a standard numpad 789 456 123 consider placing a chess knight at any digit and moving it around with any number of normal L-shaped ...
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 ...
9k 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 ...
5k views

### Output all the white or black squares of a chessboard

Introduction This is how a chessboard looks like. You can see that a1 is a dark square. However, b1 is a light square. The ...
2k views

### Tell me the moves

Jack and Jane decided to play a game of chess to while away time. Unfortunately, Jack is rather bad at visualizing. He finds it tough to figure the moves possible for a given piece other than a pawn,...
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 ...
448 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! ...
2k views

### Can the king catch the pawn?

Given an input of four integers x1, y1, x2, and y2, output whether a white king in chess (with coordinates (x1, y1)) could catch a black pawn (with coordinates (x2, y2)) and capture it if the pawn ...
2k views

### Chess Tournament

This is a chess-KOTH with simplified rules (because chess itself is already complicated, playing it via a simple program doesn't make it easier). At the moment it is limited to java (version 8), but ...
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), (x+2, y+1) in one step. Imagine an infinite chessboard with only a ...
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 ...
746 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 ...
3k 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 ...
973 views

### N-queen-and-equine quine

There is a variant of the well-known N-queens problem which involves queens and knights and is said to be "considerably more difficult" 1. The problem statement is as follows: You must place an ...
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 ...
714 views

### 8-bit Chess Pixel Counting

Goal You're playing a computerised chess game. The display is in black and white only and the pixels are chunky. White pixels use a lot power compared to black pixels and you're concerned about ...
792 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 ...
1k views

### Play Antichess!

https://en.wikipedia.org/wiki/Losing_chess This is basically Chess Tournament, but for antichess ;) Antichess is one of the many chess variants that have been invented. The goal is to lose all your ...
983 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. ...
2k views

### Chess - Find all legal moves (except castling and en passant)

Write the shortest code that calculates all possible (legal) moves of current player from a given FEN string. What is FEN string? (Wikipedia) Shortest code wins, language doesn't matter. Output ...
683 views

### Seeking Leapers

I recently got a really weird irregular chess board. It's squares are all over the place and not even all connected. At least they're still laid out on a regular grid. I want to adapt the chess rules ...
2k views

### Chess endgame: White to Mate In One

Given an 8x8 grid of letters representing the current state of a game of chess, your program's task is to find a next move for white that results in checkmate (the answer will always be mate in one ...
4k views

### Smallest chess program

Inspired by this recent article telling of a French programmer who wrote a 487 byte 2-player (human vs. human) chess program in Assembly, I wondered how small chess programs could be in other ...
470 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 ...
673 views

### Evaluating the score based from a chess FEN string

Challenge Forsyth–Edwards Notation (FEN) is a standard notation for describing a particular board position of a chess game. Your challenge is to evaluate the score using the FEN string. This is an ...
1k views

### Capture on the Pawn Chessboard

You should write a program or function which receives a string representing a chessboard with only pawns as input and outputs or returns whether any capture is possible on the board. Input is in a ...
1k 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 ...
2k views

### What is the Probability that a Knight Stays on Chessboard?

Given the size of the chess board and initial position of the knight, calculate the probability that after k moves the knight will be inside the chess board. Note:...
1k views

### king + rook vs king

It's the ending of another well played chess game. You're the white player, and you still have a rook and your king. Your opponent only has his king left. Since you're white, it's your turn. Create a ...
647 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 ...
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 ...
329 views

### Chess-olition Derby

What could be more polar opposites than chess and demolition derby. You would think that no one who enjoys one would enjoy the other... until today. Rules The starting position is a standard chess ...
541 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 ...
427 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 ...
356 views

### Chess conversion

There's quite a lot of work that's been done in the world of chess. For example, there is a standardized file format, .pgn, that describes a chess game, including ...
688 views

### Chessboard maze

Chess pieces (kings, queens, rooks, bishops, and knights) and pawns are on a board, but not on the a1 or h8 square. Your task is to travel from the empty a1 to the empty h8 squares, passing through ...
640 views

### Explosions on a chessboard

Atomic chess is a (very fun) variant of chess in which every capture causes an "explosion," destroying the captured piece, the piece doing the capturing, and all non-pawns in a 1-square radius. The ...
565 views

### The lost pawn problem

The lost pawn problem After the chess game ended, a surviving pawn was left behind enemy lines. let's help him find the shortest way back home. The original problem describes a nXn "chess" board, ...
638 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 ...
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 ...
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 ...
591 views

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 ...
769 views

### Solve a Solitaire Chess Puzzle

Recently, I was introduced to a puzzle game known as Solitaire Chess. I'll summarize the rules here: The board is a 4x4 checkerboard. All pieces are the same color (no teams) and all pieces can ...
2k views

### Shortest path for a chess knight

Your program should compute the number of moves it takes a chess knight to reach each square of the chess board. The input will be two space-separated integers representing coordinates of the ...