Author Topic: Chess  (Read 22124 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Chess
« on: April 01, 2020, 02:02:40 pm »

July 22, 2021
A tweak to hopefully let this run in Linux.  Also, the File Menu is more accessible,
being offered as an option at the end of a playback, on the reasonable assumption
that one may wish to replay another game.  And it returns to the state it was last
in, that is, same file highlighted so one doesn't have to scroll down.

July 21, 2021
Little birdie on the Help page. 

July 18, 2021
Playback wasn't handling two checks or promotions in the same move.  Fixed.

July 17, 2021
Noticed that the pieces of Set 3 were a bit distorted compared to previous versions.  Fixed.

July 10, 2021
Saves games in algebraic and descriptive notation.  Also, concluded games (checkmate, draw,
resign) are not modified if one plays them back and retreats moves.

July 9, 2021
Descriptive notation fix.

July 6, 2021
1) Nicer Setup, not that one uses it much.
2) Added Evergreen game to saved files.
3) After file playback, player names revert to former state.
4) compile.bat included to compile both files, not that it'll work if qb64.exe can't be found.

July 4, 2021
Added descriptive notation - activated in the Settings menu, by pressing "N", or by clicking
that area of the screen when History is shown.  Files are saved in algebraic notation regardless,
but are converted to descriptive on playback.   Clicking the clock area and to the left of the
board also does stuff! 

June 20, 2021
Stopping using DOXBOX/PKZIP to create the compressed file, so all files stay lowercase.
This should help Linux users.
Should you not install this in the directory with QB64, like into \chess and QB is at \qb,
it is best compiled with:
\qb\qb64 -x \chess\chess.bas  -o \chess\chess.exe

June 13, 2021
Minor improvements, mainly cosmetic.  Clicking to the left of the board toggles the legend,
and clicking on the clock cycles between regular clock, Nixie tubes, and a graph showing CPU
load and moves per second. 

May 30, 2021
Saves/restores last player names seen.  If null, computer host name used for player.

May 29, 2021
If Dodo resigns and you click Resume, Dodo will not resign again for the current game.
Allows user to practice recognizing/using a checkmate move.  However, the log stops at
the resignation.

May 22, 2021
Dodo/Minimax interface rewritten to use TCP/IP, and put the library and include file in
uppercase to suit the zip (for Linux users).

May 21, 2021

Found a program called MiniMax by Steinwender and Donninger,which compiles and runs
with no changes.  I upgraded it from text to nice pieces, and found a way to get it to play
Dodo.  Minimax is at least 5 times faster, and always wins.  To watch them play, fire up
Dodo with "chess match", or select "m" at the main menu (not shown).  It is unfortunate
that Minimax has very limited takeback and no mouse support or logging.  Currently this
match thing freezes sometimes, but I sense it and terminate the programs in 90 seconds.
Minimax needs to be compiled, of course.  It can be played independently of Dodo too.
Moves are entered in the format like e2e4, and "en" ends.

May 18, 2021
Asks for player name(s).  Defaults to using computer name if none entered.

May 4, 2021
Better perpetual detection and resigns when checkmate impending.

Apr 29, 2021
Smarter, plus silly feature (N)ixie.

Apr 21, 2021
New, lazy way to move pieces - place cursor on piece to be moved, wait until cursor turns
red, move to new square, wait again.  No clicking required.  I call it hover mode, and it can
be turned off in Setup.  Ordinary ways to move using clicking or keyboard/Enter still active.

Mar 23, 2021
Fixed minor bug - moving a piece off the board left a portion of the piece showing off the board.
Working on making it smarter now, esp. in the endgame, which is difficult so updates will be fewer. 

Mar 13, 2021
This will not compile with v1.3.  I don't know why, as I'm not using any of the new 1.5 features.
Haven't tried 1.4.  Anyway, upgrade to 1.5 because it pleases the Flying Spaghetti Monster.

Mar 4, 2021
Hover mode - leave the mouse on a piece or square for 2 seconds and it's selected.  Handy for people with trackpads that don't register a button click reliably.

Feb 26, 2021
Added 6 more chess sets.

Feb 14, 2021

It's a chess program.  It slices, dices and makes Julienne fries.  Written for Windows, but it should mostly
work under Linux.  Haven't a clue about Apple.

Plays legal, including castling and en passant, saves & replays games, takeback option, and a lot of
control over appearance (colors, sets, legend, fullscreen or not, markers, etc.).

I do not include the source in this box because of a comment I saw elsewhere in this forum that posting long
code may slow down the forum.  The source is in the zip attachment.

I've been working on this for over a year, and make updates at least once a week, sometimes a few times a day.
* chess.7z (Filesize: 6.23 MB, Downloads: 190)
« Last Edit: January 17, 2022, 04:37:22 am by Richard Frost »
It works better if you plug it in.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Chess
« Reply #1 on: April 01, 2020, 05:54:57 pm »
Hi Richard
I find your chess very fine!

 compiling the posted code put in QB64folder  together with the content of .ZIP file

I must do these feedbacks:

1. running it I got "Error OUT OF DATA" at line 1277 but going on the track it loads the fonts: data.... and if you substitute
Code: QB64: [Select]
  with
Code: QB64: [Select]
  1. DATA "end"
you fix the bug.  ( ;-)  these typed errors!)

2. the graphic is very fine, but where are the sounds?  I think that is  a must for 3394 lines of code!

3. mouse implemented only for the chessboard: it is a feature, but please send a feedback  to the player that the piece has been taken/choosen by mouse (choose you a sound and/or a different light of the piece and/or a borderlighting of piece or of cell in which it is. For now if I don't move the piece moving the mouse I cannot see that the piece is in my hand and not on the chessboard.

4. the images of piece dragged on the chessboard overwrites also my pieces like in capturing action, and not only for enemy's pieces.
Here it is difficult for me suggesting how to solve this issue, because there are so many ways from alphachannel of piece in  movement to a piece in different grading of colour of the same colour.

I am not able to take a screenshot with PrintScreen key,

After your AI got checkmate  the game stucks and I'm not able to Quit or to play a New Game .  Moreover your program's window is locked and the only combo keys that have worked  id Ctrl+Alt+Canc while no Alt+Enter or Alt+Tab or Ctrl+Esc.
Moreover after going out of program I cannot go into again . Whole window is only black.

Good Job, thanks to share
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Chess
« Reply #2 on: April 01, 2020, 06:25:33 pm »
@Richard Frost

Hi, looking for source code after one zip extraction, I found another .zip in "Other" folder and 2 in "S4" folder. So which is intended source? The one in "Other" did not match the source posted here. Would the source posted here work from main folder on top? Allot of funny images, ha!

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Chess
« Reply #3 on: April 01, 2020, 08:17:04 pm »
Oooops.  Those zip files inside the zip should not be there.  They're
just a waste of space.   I'm using a compressor new to me.  I'll fix
that and upload a new zip.

As to the longer reply, I'll get to that.....will take longer.

Thanks for the feedback!


It works better if you plug it in.

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Chess
« Reply #4 on: April 01, 2020, 08:42:36 pm »
1) I don't understand why putting that marker in lowercase and inside quotes makes a difference, but I'll do it for my version too.  As you can probably tell from the code, there *was* font selection, but it was a hassle and I removed it.

2) There are sounds.  Go into the menu (s twice) and enable them, or just press "n".  The setting will be saved.

3) Yes, I could make a click sound when a piece is selected by the mouse.  Will do.

4) That's a tough one, and will take some time to change, if I can do it at all.  Most of the sets are pictures - only the UGLY set is x/y data.

Alt-Enter should always work, and the fullscreen status saved to be invoked for subsequent play.  I've also had trouble switching to other window if in fullscreen, and don't know why.  WHAT is Ctrl-Alt-Canc?  Goodness, I've never heard of it!
There are 3 screen modes - normal centered, moved to top right, and larger to show think thinking/history/legal/etc.

I still occasionally see issues with it recognizing check. On the other hand, castling and en passant seem pretty solid,
even in file playback.

A fun thing to activate is Rick mode (R) to see three numbers - current moves evaluated per second, top moves evaluated per second, and total moves this game.  The average game is over 50 million moves.  All the "funny" pieces can be seen with
Z (lowercase shows a sample of all sets).  A red t-shirt guy from Star Trek for a pawn is hilarious, IMO.

It works better if you plug it in.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Chess
« Reply #5 on: April 02, 2020, 03:18:39 pm »
Hi Richard
thanks to follow my feedbacks

point 1.
if you READ f$ (at 1277 line) I think that the stored DATA must be a string " " and not an open value like DATA END (at 298 line),   why must it be in lowercase "end" ?  Simply because at 1278 the IF statement uses f$="end" and not f$="END"

point 2.
Thanks, I have not seen them before, now I have enabled/disabled sounds...moreover I have explored the option menu for changing the setting of pieces and chessboard's colors.  Very fine.


point 3.
thanks, quick response.

point 4.
it is good enough for now, I have not seen in your code but if you use _PUTIMAGE , can you use a bit littler or bigger image of the piece take by mouse ? (really I don't know how hard is the realization of  this idea...)

Thanks to read
------
About AI, it need to enpower its engine about at least the possibility of continue the game

in a second game AI (leading black pieces) has not recognized the check, and then the checkmate when I have captured the black King, going on with the game.
see this screenshot

 
Chess RFrost  AI  bug.jpg
Programming isn't difficult, only it's  consuming time and coffee

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Chess
« Reply #6 on: April 02, 2020, 08:29:33 pm »
The case for that "end" must match, I know, but I still  don't see why it needs quotes.  Doesn't on my system.  Are you using
Linux?  It'd be interesting to know if this thing runs on the Linux version of QB64. 

I am using _PUTIMAGE for all sets except the one in the screenshot you took. Unlike PUT, it doesn't have the AND/OR/XOR
option, so moving the pieces in any other way is not possible, because I'd be moving the background too and it'd look very
ugly.  Speaking of ugly, why are you using that particular set?  You like it?  I was going to delete it!  The only benefit of
that set is that the colors can be changed.

What I will do, eventually, is convert all sets to x/y data so that I *can* use PUT, or even PSET for a fun dissolve/assemble
type of move. 

Perhaps _PUTIMAGE can do the job, if I make some color transparent.  I'm still learning how to use RGBA.  Likely still
involve a massive edit to all the images.

Yes, I'm aware it sometimes doesn't recognize being in check.   It's somewhat rare now, I hope.  I'll probably lick that bug
completely within a month and upload again.

Not sure what your point 4 is. Show a bigger or smaller piece if it has been selected by the mouse?  That should be easy to
do - for 3 of the 5 sets. Not sure I'd like it though.  Wouldn't the red cursor used for the arrow keys be nicer?  It is annoying when one gets out of synch and has to press Enter twice or click twice.  I had a "To?" caption before  for the 2nd phase of a move, but it looked so....amatuerish. There didn't seem to be any need of any indicator when using  the mouse. 

It changes a lot every day, since it's my primary activity.  Not  sure how often I should upload updates - certainly not daily! 
I'll  aim for about once a month.  My lastest version can be used as a  screensaver - computer plays itself endlessly.  If the background graphics are active it uses a lot of CPU time tho.

Thank you for taking the time to test it.
It works better if you plug it in.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Chess
« Reply #7 on: April 03, 2020, 07:34:15 am »
Hi Richard

I love chess game so if you post something about it I look at and I play!

And now you know why all these feedbacks from me.

about   
Quote
The case for that "end" must match, I know, but I still  don't see why it needs quotes.  Doesn't on my system
I must admit that the " " are not necessary and it is a my limit thinking that READ need of " " to recognize a string or character. I have used so few times READ and DATA, so I have little experience with them.
The real issue was the difference between uppercase and lowercase.

About visibility of piece in moving (in the hand of player) is just a step forward to be more visually clear, it is not a must.

---------------
more about AI
when I have played with black against AI with white,  I am not able to castle . Please try to see if it is an issue on my Pc or an AI error.

Thanks to read
Programming isn't difficult, only it's  consuming time and coffee

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Chess
« Reply #8 on: April 03, 2020, 04:07:05 pm »
Shucks.  Are you sure it was legal to castle at the time - not in check, not moving into or thru a check, no
pieces in between, and the king and rook concerned had never moved?

I was wrong about _PUTIMAGE being a limiting factor, at least concerning these images.  They have no
background, so I can move them smoooooothly with the mouse.  Working on it. 

Thanks again for the feedback, and new ideas.


It works better if you plug it in.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Chess
« Reply #9 on: April 03, 2020, 07:33:23 pm »
Hi
Yes  all pieces (king and Rook have made no movement before, and King doesn't fall under attack during its travel from e8 to g8 and king is not under check) are in good state to make castle.

about running in Linux...
I have tried, but I've got always error about file to load... the path appears wrong but if I go to find them they are there!
Also if I change the path adding ".\" or "./" !  Bad File name is the  error coming out on running the compiled file.
Programming isn't difficult, only it's  consuming time and coffee

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Chess
« Reply #10 on: April 03, 2020, 09:23:55 pm »
Linux cares about case with filenames.  Likely what's on the disk doesn't match what
the code expects.  A later version will search for files using both cases, as I did for some
other program.  I'm under the impression, perhaps mistaken, that Linux users are a
tiny minority, so it's not a priority.
It works better if you plug it in.

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Chess
« Reply #11 on: May 16, 2020, 11:16:46 am »
Updated!   Modifying the original message doesn't seem to flag a change, so.....

Plays legally.   Crappy endgame, since the rules I've given it are simple.  Pretty
challenging for midgame tho.  Most of the code is for graphics - the pieces themselves,
the plasma effect, etc., and for configurartion and showing the thinking, file playback, etc. 

Hard to believe a chess program (almost complete!) was done in under 1K, twice!


« Last Edit: May 16, 2020, 11:18:21 am by Richard Frost »
It works better if you plug it in.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Chess
« Reply #12 on: May 16, 2020, 05:09:04 pm »
Hi Richard
Nice update!
Programming isn't difficult, only it's  consuming time and coffee

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Chess
« Reply #13 on: May 17, 2020, 05:08:47 am »
Richard, I looked at this program today: a remarkable achievement.  But I found that a moved piece would "stick" to the cursor afterwards, even after the next move (by the computer).  To mitigate this you have to move the stuck piece to an illegal position & then you are allowed to move the next piece - see given video.  Also, there is no .bas file in the .zip so you have to save the .bas file from here and then reboot QB64 so that it recognises the folder structure.  Also I xould not change from full screen to window (except by commenting the _FULLSCREEN line).
https://youtu.be/1F7PHia3YRQ

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Chess
« Reply #14 on: May 17, 2020, 11:56:35 am »
Nice game! and lovely graphics!
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials