## Chessboard

Show off your games, demos and other (playable) creations.
Roland Chastain
Prole
Posts: 29
Joined: Sat Feb 07, 2015 2:30 pm
Location: France
Contact:

### Chessboard

Hello everybody!

I would like to present my LÖVE chessboard. It's a chessboard with an arbitrator (but without an artificial opponent). To move a piece, drag and drop it.

I made that chessboard in order to test under pleasant conditions my script chessgame.lua, and because I wanted to try to do something with LÖVE. I was surprised to see how easy it was to do what I wanted, with a few lines of code.

It's a programming exercise and my first LÖVE project, so any suggestion about the code is welcome.

All the chess rules are implemented, except threefold repetition (but it would be very easy to add). In case of promotion, you cannot choose the piece: it's automatically a queen. It's because I didn't see a simple way to ask the user choice, and didn't want to break my head about that.
Attachments
chessboard-20190921.love
chessboard-20190917.love
chessboard-20190914.love
chessboard.love
Last edited by Roland Chastain on Sat Sep 21, 2019 6:15 am, edited 3 times in total.

Ikroth
Citizen
Posts: 72
Joined: Thu Jul 18, 2013 4:44 am

### Re: Chessboard

Wow, this looks really awesome! It would great if when you picked up a piece it showed you where you are able to legally move it.

Roland Chastain
Prole
Posts: 29
Joined: Sat Feb 07, 2015 2:30 pm
Location: France
Contact:

### Re: Chessboard

Ikroth wrote:Wow, this looks really awesome!
Thank you very much.
Ikroth wrote:It would great if when you picked up a piece it showed you where you are able to legally move it.
Yes, good idea. I will think of a not too complicated way to do that.

whitebear
Citizen
Posts: 86
Joined: Sun Mar 15, 2009 1:50 am

### Re: Chessboard

I love the classic font style chess board. I am so tempted to fork this.

ivan
Party member
Posts: 1530
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

### Re: Chessboard

The next obvious step would be to support the PGN format.
Disambiguation is hard to implement without making your code super messy.
So you need a fast way to generate all possible moves to a particular square.
Performance is going to be another concern. For example, loading/validating a large PGN file.
One common optimization is to detect "pinned" pieces:
1. If the moving side is not in check AND
2. If the moving piece is not pinned THEN
a lot of calculations can be avoided - you don't need to test if the move opens check for the moving side.

The Lua code needs a little bit of work too.
You don't want to write things like:

Code: Select all

        elseif isKnight(aBoard[x][y]) or isKing(aBoard[x][y]) then
if isKnight(aBoard[x][y]) then
I recommend using "locals" for things like "aBoard[x][y]" because it makes the code shorter and it's faster too.

Personally, I don't see a big advantage of using a 2D table for the board representation. IMO, 1D tables make life a lot easier in this case.
I don't like the use of pattern matching here:

Code: Select all

 return (aBoardValue ~= nil) and string.match(aBoardValue, '[Pp]')
you might as well write:

Code: Select all

 return aBoardValue == "P" or aBoardValue == "p"
In fact I don't think the use of strings is that beneficial in this case. But this could be a matter of debate.

But yep, it's a decent start.
Good job.

Roland Chastain
Prole
Posts: 29
Joined: Sat Feb 07, 2015 2:30 pm
Location: France
Contact:

### Re: Chessboard

whitebear wrote:I love the classic font style chess board. I am so tempted to fork this.
As far as I am concerned, please feel free to do so. The design of the pieces come from Fritz 1.0. When I began my first chess program, I copied manually the pictures with "0" and "1" in a text file, before I learned to read a picture by code.

Later, I added transparency and converted pictures to PNG format.
Last edited by Roland Chastain on Sun Jul 03, 2016 6:18 am, edited 6 times in total.

Roland Chastain
Prole
Posts: 29
Joined: Sat Feb 07, 2015 2:30 pm
Location: France
Contact:

### Re: Chessboard

Thank you for your look into my code, and your very interesting suggestions.

Yes, I was thinking of PGN support, but when I studied the specifications, I found that it was too complicated, especially disambiguation as you said. Thank you for sharing your experience in that matter.
ivan wrote:But yep, it's a decent start.
Good job.
Thank you.

Roland Chastain
Prole
Posts: 29
Joined: Sat Feb 07, 2015 2:30 pm
Location: France
Contact:

### Re: Chessboard

Hello! Here is a new version of the chessboard.

The valid target squares are highlighted. Some improvements have been made in the code. Arbitrator messages are available in french and german languages. To change the language, make a copy (for example) of french.lua named language.lua. If someone would contribute another translation, I would be glad to add it.

P.-S. I forgot to mention that I also changed the mouse cursor (to a grabbing hand).
Attachments
chessboard.love
Last edited by Roland Chastain on Tue Jul 05, 2016 6:52 am, edited 1 time in total.

zorg
Party member
Posts: 2732
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

### Re: Chessboard

Here you go: hungarian.lua

Code: Select all

literals = {
ltDraw = 'Döntetlen!',
ltCheckmate = 'Matt! ',
ltStalemate = 'Patt!',
ltCheck = 'Sakk! ',
ltWhiteToMove = 'Világos lép.',
ltBlackToMove = 'Sötét lép.',
ltWhiteWins = 'Világos nyert.',
ltBlackWins = 'Sötét nyert.'
}

Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

Roland Chastain
Prole
Posts: 29
Joined: Sat Feb 07, 2015 2:30 pm
Location: France
Contact:

### Re: Chessboard

zorg wrote:Here you go: hungarian.lua
Great! Thank you very much.

### Who is online

Users browsing this forum: Bing [Bot] and 3 guests