Chessboard

Show off your games, demos and other (playable) creations.
User avatar
Roland Chastain
Prole
Posts: 34
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.

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
(29.76 KiB) Downloaded 390 times
chessboard-20190917.love
(30.11 KiB) Downloaded 237 times
chessboard-20190914.love
(14.94 KiB) Downloaded 232 times
chessboard.love
(13.05 KiB) Downloaded 455 times
Last edited by Roland Chastain on Sat Sep 21, 2019 6:15 am, edited 3 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: 34
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: 1911
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: 34
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: 34
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: 34
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 281 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: 3436
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: 34
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: No registered users and 36 guests