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. In case of promotion, you cannot choose the piece: it's automatically a queen.
The latest version of the project is on Codeberg.
Chessboard
- Roland Chastain
- Prole
- Posts: 41
- Joined: Sat Feb 07, 2015 2:30 pm
- Location: France
- Contact:
Chessboard
- Attachments
-
- chessboard-20240423.love
- (48.11 KiB) Downloaded 186 times
-
- chessboard-20190921.love
- (29.76 KiB) Downloaded 567 times
Last edited by Roland Chastain on Thu Apr 25, 2024 10:15 am, edited 9 times in total.
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: 41
- Joined: Sat Feb 07, 2015 2:30 pm
- Location: France
- Contact:
Re: Chessboard
Thank you very much.Ikroth wrote:Wow, this looks really awesome!
Yes, good idea. I will think of a not too complicated way to do that.Ikroth wrote:It would great if when you picked up a piece it showed you where you are able to legally move it.
Re: Chessboard
I love the classic font style chess board. I am so tempted to fork this.
Re: Chessboard
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:
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:
you might as well write:
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.
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
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]')
Code: Select all
return aBoardValue == "P" or aBoardValue == "p"
But yep, it's a decent start.
Good job.
- Roland Chastain
- Prole
- Posts: 41
- Joined: Sat Feb 07, 2015 2:30 pm
- Location: France
- Contact:
Re: Chessboard
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.whitebear wrote:I love the classic font style chess board. I am so tempted to fork this.
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: 41
- 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.ivan wrote:Not a bad start.
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.
Thank you.ivan wrote:But yep, it's a decent start.
Good job.
- Roland Chastain
- Prole
- Posts: 41
- 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).
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.
- zorg
- Party member
- Posts: 3468
- 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: 41
- Joined: Sat Feb 07, 2015 2:30 pm
- Location: France
- Contact:
Re: Chessboard
Great! Thank you very much.zorg wrote:Here you go: hungarian.lua
Who is online
Users browsing this forum: No registered users and 4 guests