This is a project that I worked on during the school year and briefly over summer to exercise my C++ knowledge. My goal is to create a chess game that can be played in terminal in C++.
This is project is finished but may be revisited at a later date for future additions.
Going into this I thought chess would be a nice, simple first project in C++. I was very wrong.
My goals for this chess game involved a few things:
- Giving each piece a unique number depending on location then running that through to check where it is.
- Making sure that the pawn would update what piece it is when it's at the end of it's opponent board.
- The latter was the most time consuming of everything since I had to learn the rules of chess rather than just loosely know them then apply them in code. This includes making specific cases such as if it's a pawn's first move it can move up two spaces.
Now, the important part, what have I learned. This time around I didn't have to learn new code on my own since I was in a CS 121 class which taught C++ and instead I learned more so how to better plan projects and some cool tricks I can use in the future.
- At first I put all of my pieces into variables, pawn1, pawn2, etc... But that was a lot of variables. So then I decided to hold it in an array of 64. To which I showed my teacher and he told me that once we learned 2D arrays I would want to use them for this project instead. So I went ahead and learned 2D arrays a bit ahead of schedule and used a array[8][8]. I also tried two separate arrays one for columns[8] and one for rows[8]. To put it simply I could not make up my mind and wasted a ton of time because of that. I ended up doing an array[64] just because I prefered the way you could check pieces in it. That being said any of these array options, and the variable option would also work fine.
- I only realized how helpful this would be when I was trying to test if my pawns could promote properly and each test was taking around a minute for me to move my pawns all the way up to the other end of the board. In the future I would make something I could enter which would turn off all of the checks I go through when moving pieces so I could teleport my pawn up, turn off the cheats, and then move my pawn forward one and see if it promotes.
- I can use .at(#) on strings since I learned strings are basically a vector of integers and characters and when I use this it returns the ASCII value. I continued to use ASCII values throughout this whole project in order to check various things, such as if a piece was moving onto a teammate piece.
- I also learned that in the future I should use more than 3 files for all of my code (this may obvious but in my class we focused on using a three file format, one for main, one for functions, and one for the header). Instead my functions file ended up very long because that's where the majority of the code is and I could probably split it up into multiple files to make things easier on myself.
Future Potential Additions:
Overall, I just need to learn how to plan out my projects better ahead of time and hopefully I'll be able to do that going forward. Although, I think with my next project it may be difficult to do so given I don't know the capabilities of the game engine, GoDot and that project is going to be how I learn GoDot.