lichess.org
Donate

How hard would it be to create a chess playing program?

I don't mean an engine, but simply a board that only allows legal moves and recognize checks, checkmate and stalemate.

As a guy with no programming experience, i believe this would be mindbogglingly complex.
This thing has already in progress as far as I'm concerned. I always wanted an own chess GUI but I chose the wrong langauge. By now I realized that the way to go is Java, because JavaFX provides a very capable GUI environment, also it is fast and portable.

By now I have a Java application which knows the rules of the game, so it can check the legality of moves, it supports drag and drop move input, understands san notation, therefore it can parse PGNs ( even complicated ones with variations and files containing multiple games ). It can run a UCI engine and represent its analysis graphically. In the latest version the board is resizable and configurable ( colors, margins, padding etc. can be fine tuned ). It also has a book building capability ( you can annotate moves and transpositions are handled correctly ). The deep analysis function allows you to evaluate all the moves in the given position with the engine, and these evaluations become part of the book.

You can find it here:

github.com/javachessgui/javachessgui2

In this latest version the move generation and the engine driver is well separated from the GUI ( which was not the case in the first version ) so anyone who wishes to have an own Java chess program can use those classes. I can assure you that move generation and correct fen/sen representation requires hard work to get right in a bug free way so it is useful to have a class that does this for you if you want an own application.
You mean for someone with no programming experience? For an experienced programmer it should be very easy. Even writing a basic engine from scratch is not particularly hard, but a little time consuming. For someone with no programming experience I imagine the difficulty ranging from easy to near impossible. It depends on the person. IMO the easy part is doing it at all, the hard part is doing it elegantly, but for a non-CPU intensive application like this it's not very important to do it elegantly.
I am curious. Why are you asking opinions on this? Thinking of doing this yourself?
It's pretty simple to do. Have a grid of which piece is on it and define the movement of each piece:

enum Piece {
None,
Rook,
Bishop,
Knight,
Etc.
}

//What moves are stored in
struct Coordinate {
int x, y;
}

//The board
Piece[][] Pieces = new Piece[8][8];

for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
list<Coordinate> Moves = new List<Coordinate> ();
switch (Pieces[i][j])
{
case Piece.None:
break;

case Piece.Rook:
/*Cast across the grid horizontally and stop in a direction if that coordinate has a unit blocking further movement*/
break;

case Knight:
/*For all 8 possible moves, check if a piece is occupying that coordinate or if it's on the board (0 <= c <= 7)*/
break;

case Piece.Bishop:
/*Like the rook, but diagonally*/
break;
}
}
}
Aim for a simple goal, like a program that generates legal knight moves for a knight on some square (rank, file).

Once you've figured that out, do that for the other pieces.

Then allow multiple pieces of the same color to exist on the board at the same time and do legal move generation.

Then allow multiple pieces of either color to exist on the board at the same time and do legal move generation. Congratulations, you've developed a primitive chess program.
Well, you'll have to learn some programming (if it is you). But not much.

A good idea may be to build up the board of interconnected squares. For example, the square a1 has the neighbour squares a2, b2 and b1. A bishop on a1 can move to b2 but not to b1 or a2. Knowing that a bishop can move to b2, it can also move from b2 to its neighbour square c3. This in the case of the bishop continues until you hit the end of the board or a piece of the same color. Or the second piece of another color.

To find checks, you just have to check if any of the pieces can move to the square of (or take, if it makes a difference) the enemy king.
Sorry, of course the movement of the bishop just ends after you hit the first piece, but the move in legal or not depending on the color of the piece.
Yeah, it might be better to store piece data with a class instead of an enum. Seriously though, you're kind of nitpicking. Just add an if statement comparing the detected piece's team to the current checked piece.

This topic has been archived and can no longer be replied to.