Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

  • To create a chess board that will update depending on where pieces are. This involved:

    1. Giving each piece a unique number depending on location then running that through to check where it is.

    2. Making sure that the pawn would update what piece it is when it's at the end of it's opponent board.

  • To allow user input, check that it's a valid input (A6, B3, etc...), and check if the user's moves or valid or invalid before letting them make them.


    1. 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.

  • Determining if the board is in checkmate or check and giving a special output with that, to end the game and get the option to start a new one.


  • 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.
  • The most important thing I learned was to plan out my project before I do it. I restarted this project four times just to change the way I was holding data.

    1. 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.

  • Creating a cheat mode for testing things.

    1. 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.

  • Then there are a few just small C++ things I learned such as:

    1. 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.

    2. 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:
  • Improving the checkmate function. This would likely be done by doing something similar to checking for whether or not the king is in check. It would have all of the squares of that piece on the way to the king in a list and check if any pieces on the king's same team would be able to intercept them. That being said I think the program is good enough right now, even though users only have one chance to save their king from check. I'll probably revisit this and add it at a later date but I've spent too long on this project given the scope of it so I'm cutting myself off so I can learn more in less time.

  • Adding an AI opponent. I'm not too sure how I'd go about this other than making the AI make random moves that aren't good. I want to revisit this at a later date but right now I think it would be more efficient for me to spend my time on something else.

  • 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.

    About

    No description, website, or topics provided.

    Resources

    Stars

    0 stars

    Watchers

    1 watching

    Forks

    Releases

    Packages

    Contributors

    Languages