https://youtu.be/uNyqrT9Pus8

3.A.i: The purpose of my program is to alleviate boredem by providing a platform to play chess with your friends.

3.A.ii: My game allows the player to choose a chess piece and then calculate the possible moves that piece can make based on the rules of chess. After finding the moves which can be made, my program will dipsplay those moves. Then, when a player chooses one of those possible moves the program updates the game in order to reflect that move being made.

3.A.iii The inputs are all clicks by the player and they can have different outputs depending on the circumstances. If you click on a piece which is not yours or click on an empty square there will be no output. If you click on your own piece which has available moves the output will be displaying those moves. If you have already clicked on a piece and you click on one of the moves being displayed the output will be actually moving the piece to that spot.

3.B.i

3.B.ii The variable representing the list is called “moves” as it is generated in the getTotalMoves() method, but when it is called in getObstructedMoves() its name is changed to totalMoves to better represent it in that specific code segment. This is possible because these code segments are two seperate methods.

3.B.iii The data in this list represents the total moves that a piece can make. This code specifically represents the total moves that a Knight would be able to make.

3.B.iv This list manages complexity by neatly storing all of the possible moves that a piece, in this case the Knight, can move. This is useful for many reasons, and the code would be very difficult to recreate without this. Without this list, each move would need to be stored in a seperate variable. That in itself is not too bad, but the purpose of the “moves” list is to later filter through it in order to find which moves are not available. Without a list it would be incredibly difficult and tedious to go through this filtering process. Instead of using some kind of loop, like the forEach() method I used, you would have to individually check each move and then determine whether that move is possible or not. Then you’d have to find some way to show that the move isn’t possible, as you would be unable to just remove it from a list like I do currently. There are other programs which perform similar functions on the list of total moves so each of those would also have to be recreated in this way which would make this program way more complex than it needs to be.

3.C.i

3.C.ii This procedure is what actually moves the piece. This is the backbone of the functionality of the program. This method which I created is how anything changes in the game state, how a piece moves from one square to another.

3.C.iii

3.c.iii In my first code segment given the move function checks if the move which has been given is in the available moves for that piece. We can also see the available moves function which combines the captures and the free moves. To start at the lowest level, the available captures function iterates through each obstructed move and selects only the ones that have a piece that is the opposite color to the piece which is moving. It then returns these moves as those are the moves which the piece can make to capture another piece. The get free moves function does something similar but the opposite. It takes the total moves and removes all of the moves which are obstructed by something. That way the only moves remaining are the free moves which the piece can make and that list is returned. Finally these two lists are combined together in the get available moves function. In the move function itself that get available moves function is called that then runs the subsequent functions. Once the list of available moves has been generated the move function checks to see if the place that the piece has been told to move is actually a move that piece can make. If it is then the move is made. If not then the function does nothing.

3.D.i First Call:
In the first call the movePiece function will have parameters of currentM = “b1” and newM = “c3” and the board is in the following position:

Second Call:
In the second call the movePiece function will have parameters of currentM = “b1” and newM = “b3” and the board is in the same position as above.

3.D.ii, First Call Conditions:
The condition checks if the new move which was passed through is included in the list of available moves, which it is. Therefore it will change the board state, making the piece move.

Second Call Conditions:
The condition checks if the new move which was passed through is included in the list of available moves, which it isn’t. It then checks if the piece is castling, which it is not.

3.D.iii First Call Result:
The code it will change the board state, making the piece move. This is later displayed on the players screen.

Second Call Result:
Since both conditions are false the code does nothing.