Chessboard

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

Chessboard

Post by Roland Chastain »

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.

Image

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. In case of promotion, you cannot choose the piece: it's automatically a queen.

The latest version of the project is on Codeberg.
Attachments
chessboard-20240423.love
(48.11 KiB) Downloaded 186 times
chessboard-20190921.love
(29.76 KiB) Downloaded 568 times
Last edited by Roland Chastain on Thu Apr 25, 2024 10:15 am, edited 9 times in total.
User avatar
Ikroth
Citizen
Posts: 79
Joined: Thu Jul 18, 2013 4:44 am

Re: Chessboard

Post by Ikroth »

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.
User avatar
Roland Chastain
Prole
Posts: 41
Joined: Sat Feb 07, 2015 2:30 pm
Location: France
Contact:

Re: Chessboard

Post by Roland Chastain »

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.
User avatar
whitebear
Citizen
Posts: 86
Joined: Sun Mar 15, 2009 1:50 am

Re: Chessboard

Post by whitebear »

I love the classic font style chess board. I am so tempted to fork this.
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Chessboard

Post by ivan »

Not a bad start.
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.
User avatar
Roland Chastain
Prole
Posts: 41
Joined: Sat Feb 07, 2015 2:30 pm
Location: France
Contact:

Re: Chessboard

Post by Roland Chastain »

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.
User avatar
Roland Chastain
Prole
Posts: 41
Joined: Sat Feb 07, 2015 2:30 pm
Location: France
Contact:

Re: Chessboard

Post by Roland Chastain »

ivan wrote:Not a bad start.
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. :)
User avatar
Roland Chastain
Prole
Posts: 41
Joined: Sat Feb 07, 2015 2:30 pm
Location: France
Contact:

Re: Chessboard

Post by Roland Chastain »

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
(16.43 KiB) Downloaded 446 times
Last edited by Roland Chastain on Tue Jul 05, 2016 6:52 am, edited 1 time in total.
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Chessboard

Post by zorg »

Here you go: hungarian.lua :3

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 :3True 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.
User avatar
Roland Chastain
Prole
Posts: 41
Joined: Sat Feb 07, 2015 2:30 pm
Location: France
Contact:

Re: Chessboard

Post by Roland Chastain »

zorg wrote:Here you go: hungarian.lua :3
Great! Thank you very much. :)
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 8 guests