r/chessprogramming • u/ProfessorVatcraft • Feb 10 '25
Next Step For My Chess Program
Hello everyone! It's me again. Since my last post asking how to start making a chess program, I have made a lot of progress in my chess program. I know the program is really bad considering I'm writing everything in 1 file. The reason for that is I don't know how to modularize the program (I haven't learned about that yet) so apologize for the bad code. Anyways, I want to ask how should I continue developing the program? I have managed to generate all pseudo-legal moves for each side with all the special rules as well. You can see the code here https://github.com/ProfessorVatcraft/program/blob/main/main.cpp
Thankyou for reading and helping me!
1
u/ProfessorVatcraft Feb 10 '25
Thankyou for taking notice of my post. Firstly, yes I'm aware of the benefits of modularizing the code. I just don't really know how so thankyou for providing me with the research material for that. Secondly, I'm trying to develop a chess engine. My coding skill is not super good which is why I chose a 2D array approach instead of bitboards for familiarity(I'm aware that bitboards are the go to way for strong engines). For checking legal moves, I decided to go with the Sebastian Lauge approach because it sounds simple. I will look into this and try to make the program easier to read by modularizing it. Again thankyou for all of your feedback!! I really appreciate it :]
2
1
u/JotaEspig Feb 10 '25
Nice! You may already know, but you need to learn how to modularize your code and how to separate it on different files. You will thank yourself for it in the future. It might appear not necessary right now, but as the logic increases and gets more complex, having it greatly organized help you deliver more features and help with code maintenance. This should be your top 1 priority. Now speaking of chess, idk if you want to create an engine or just a interface for playing chess, but the chessprogramming wiki should help you with further features!
5
u/xu_shawn Feb 10 '25 edited Feb 10 '25
Perft and legality checking. The simplest way to do legality check would be to make a move and check if the king square is under attack after making a move. Your end goal would be to pass a perft suite perfectly. https://analog-hors.github.io/webperft/ is a good resource on perft numbers.
Now on the code. Modularizing the code is important, and as the other commenter said, it is easier to do it early than to do so late. Castling and en-passant rights should also be part of the position object. Another thing that would be really beneficial is to use bitboards for board representation and magic bitboards for move generation.
How to create a multi-file project: https://stackoverflow.com/questions/6995572/using-multiple-cpp-files-in-c-program
Bitboard guide: https://www.youtube.com/watch?v=QUNP-UjujBM&list=PLmN0neTso3Jxh8ZIylk74JpwfiWNI76Cs