Labs 6: Building a Better Chessmaster 8000 ------------------------------------------ Ojectives --------- To gain experience in teamwork on a larger project. To obtain experience in Object-Oriented Design with Java. To demonstrate and gain experience in planning and executing test techniques for a non-trivial system. Introduction ------------ Welcome to The Big One (ominous low music plays). This is a 4-person programming assignment in Java. There are no restrictions on which version of Java you must use, though we suggest 1.2.2. Your task is to program a robust chess program, supporting many of the popular tools and features of standard chess programs. Chess is one of the most complex games, but the rules themselves are rather simple. This assignment is broken up into 4 weeks, and four different deliverables. Attendance for this IS required every week in order for you to ask questions to the TA's and to meet with your group members. There will be a sign-up sheet, and any week missed will count 5 points off of your group's total grade for that lab portion. The Rules of Chess ------------------ Board Setup ----------- 1: The lower left square is always black. 2: The colors alternate across rows and columns. 3: The board is 8 squares by 8 squares 4: Peices of the two players are black and white 5: The beginning postion is this: Black ----------------- |r|n|b|q|k|b|n|r| ----------------- |p|p|p|p|p|p|p|p| Note 1: As a convention in this NFO file, all ----------------- Black pieces will be expressed in lower | | | | | | | | | case letters. ----------------- | | | | | | | | | Note 2: K - King ----------------- Q - Queen | | | | | | | | | B - Bishop ----------------- N - Knight | | | | | | | | | P - Pawn ----------------- |P|P|P|P|P|P|P|P| ----------------- |R|N|B|Q|K|B|N|R| ----------------- White Moves: ------ Note: Except where noted, pieces may not "jump" over other pieces. Note: White has the first move, and players alternate making turns with any piece they wish. King (K)- This piece may move one square in any direction. --------------- | | | | | | | | --------------- | | |*|*|*| | | --------------- | | |*|K|*| | | --------------- | | |*|*|*| | | --------------- | | | | | | | | --------------- | | | | | | | | --------------- Queen (Q)- This piece acts like a combination Rook and Bishop. She may move any number of squares in any direction. --------------- | |*| |*| |*| | --------------- | | |*|*|*| | | --------------- |*|*|*|Q|*|*|*| --------------- | | |*|*|*| | | --------------- | |*| |*| |*| | --------------- |*| | |*| | |*| --------------- Rook (R)- This piece may move on both ranks and files any number of spaces. --------------- | | | |*| | | | --------------- | | | |*| | | | --------------- |*|*|*|R|*|*|*| --------------- | | | |*| | | | --------------- | | | |*| | | | --------------- | | | |*| | | | --------------- Bishop (B)- This piece may move diagonally only any number of spaces. Note that since diagonals only consist of one color, a bishop is confined to only one color. Black and White each have 1 bishop able to travel on each color. --------------- | |*| | | |*| | --------------- | | |*| |*| | | --------------- | | | |B| | | | --------------- | | |*| |*| | | --------------- | |*| | | |*| | --------------- |*| | | | | |*| --------------- Pawn (P)- This piece may move foward one or two spaces on its first move only, after which it may only move one square. Capturing with this peice is different and will be covered later. --------------- | | | | | | | | --------------- | | |p| | | | | Note: Since the two middle pawns have not yet moved, --------------- they can move either one or two spaces |p|*|^| |*| | | --------------- ^ - possible moves for the Black pawns |^|*|^| |P| | | --------------- | |P| | | | | | --------------- | | | | | | | | --------------- Knight (N)- This piece moves very strange. It looks like an "L". This piece moves two spaces on a rank or file, then it turns 90 degrees and moves again. Knights are allowed to jump over other pieces in doing this. Here are the possible moves: --------------- | | | | | | | | --------------- | | | |*| |*| | --------------- | | |*| | | |*| Note: Neither the White nor Black pawns prevent the --------------- White knight from moving. | | |P|p|N| | | --------------- | | |*| | | |*| --------------- | | | |*| |*| | --------------- Capturing Pieces ---------------- Pieces are captured simply by moving on top of them using a normal move with your piece, except for the pawn. The pawn may only caputure one space diagonally in front of it. Here is an example: --------------- | | | | | | | | --------------- | | | | | | | | --------------- The White pawn is able to capture either Black pawn, | | |p| |p| | | and both black pawns are able to capture the White pawn --------------- depending on whose move it is. | | | |P| | | | --------------- | | | | | | | | --------------- | | | | | | | | --------------- The knight only captures on the final square he gets to, not on any of the others he passes through in doing the "L" manuever. Check ----- Check is defined as the condition in which one players king is threatened to be captured on the next move. A player may not make a move which places them in check. Here is an example: --------------- | | | |r| | |k| --------------- | | | | | | | | The White king is in check due to Black's rook. --------------- | | | | | | | | --------------- | | | | | | | | --------------- | | | | | | | | --------------- | | | |K| | | | --------------- --------------- | | |r|r| |k| | --------------- | | | | | | | | The White king may not move onto the square marked "x", --------------- nor can his bishop move, since that would put him in | | | | | | | | check due to Black's rook on the left. --------------- | | | | | | | | --------------- | | |B| | | | | --------------- | | |K|x| | | | --------------- Program details --------------- You are to make a graphical version of chess (no command-line output at all). "GIF" files are provided for the pieces and the board. The base program should have these following features: 1) White and black are able to play the game given the rules above. 2) Illegal moves are not allowed to be played. The program should warn them of this and not allow them to make an illegal move. 3) Moves should be made by clicking on the square of the piece you want to move then clicking on the square you want to move it to. This chess system is based on the "touch-move" rule. Once you touch a piece, that is the piece you must move. 4) Your program should allow captures, and remove the captured pieces from play. 5) Your program should have a menu allowing the start of a new game. 6) Your program should have a way to close out the program both on the window and from the menu. 7) Implement an algorithm that announces when a player is in check. In addition, your program should be able to both load and save chess positions into a file format to be released the second week of the project. Chess positions are an integral part of the game for learning from others mistakes and from the genius of others. Loading and saving games should be accessible from the menu. The additional parts of the GUI may either be implemented in a MDI (Multiple Document Interface) format where there are many smaller windows inside one large parent window (think Word or Excel here), or in multiple top-level windows on the desktop. You will not be allowed to make a GUI that is composed of only one top-level window. Besides these basic features you must pick _5_ of the following features to implement for full credit on this project. Doing more than 5 of these features gets you extra credit on the lab8 portion of your grade. 1) Implement an algorithm that announces checkmate. This is much more difficult that announcing check. In checkmate, there is no way for the other player to make a move that prevents the capture of the king on the next move. Note that this condition corresponds to not being able to get out of check. A player may get out of check in three ways: 1) Moving the king out of danger. Note that the king may not move so that another piece may also capture him. 2) Capture the piece attacking the king. This may not always be possible, as there may be more than one piece attacking the king. 3) Move a peice between the attacking piece and the king. This is similar to 2, in that if more than one piece is attacking the king, this is not possible for both pieces. --------------- |k|Q| | | | | | --------------- | | |K| | | | | The Black king is checkmated. --------------- | | | | | | | | --------------- | | | | | | | | --------------- | | | | | | | | --------------- | | | | | | | | --------------- --------------- |k| | | | | | | --------------- | |Q| | | | |r| Black is not in checkmate, because the White queen may --------------- be captured by the Black rook. | |K| | | | | | --------------- | | | | | | | | --------------- | | | | | | | | --------------- | | | | | | | | --------------- --------------- |k| | | | | | | --------------- | | | | | | |r| Black is not in checkmate, since his rook can block --------------- the White rook in the corner. | | | | | | | | --------------- | | | | | | | | --------------- | | | | | | | | --------------- |R|R|K| | | | | --------------- 2) Add a clock to your program that counts down for each player. The clock starts counting down for a player when the other player moves, and stops counting down when the player makes his/her move. If the clock reaches zero, the player loses. The timer should be able to be turned off and on depending on the wishes of the players. The program should also allow the players to change the amount of time at the start of the game only. Both players must also have the same time constraints. Default should be 10 minutes. Also, for every move that a player makes, he gains 5 seconds back on his/her clock. (Hint: Look at the JTimer class). 3) Implement an algorithm that checks for a condition called stalemate. Stalemate is defined as not being in check, but being unable to move any piece legally. In this situation, the game ends in a tie. Here is an example. --------------- |k| | | | | | | --------------- | |R| | | | | | Black has been stalemated by White, as the king cannot --------------- move to any square legally, and neither can his pawn. | |K| | | |p| | --------------- | | | | | |P| | --------------- | | | | | | | | --------------- | | | | | | | | --------------- 4) Allow a method for one player to offer the other a draw. A draw is a tie, and the game ends. This usually occurs when neither player has sufficient pieces to checkmate the other. The other player may accept or decline. If the other player declines, play continues as normal. This must be an option accessible from the menu. 5) Implement the castling rule. In this rule, the king moves 2 spaces to the right or the left, and the rook in the direction he moves is placed immediately to the other side of the king. For this move to be legal, the following conditions must be met: 1) Neither the king nor the rook that he is castling with may have moved before. 2) The king cannot be in check, nor can he be in check on any square in the castling manuever. 3) No piece may be in the way of either the king or the rooks path. Here are the two examples of castling (seen from white's viewpoint): ----------------- |R| | | |K| | |R| ----------------- /\ / \ / \ ----------------- ----------------- | | |K|R| | | |R| |R| | | | |R|K| | ----------------- ----------------- --------------- | | |k|r| | | | --------------- | | | | | | | | The White king is unable to castle since he is in --------------- check. | | | | | | | | --------------- | | | | | | | | --------------- | | | | | | | | --------------- |R| | |K| | |R| --------------- --------------- | | | | |K|r| | --------------- | | | | | | | | The White king is unable to castle in either direction --------------- because doing so would place him in check by one of | | | | | | | | Black's pieces. --------------- |b| | | | | | | --------------- | | | | | | | | --------------- |R| | |K| | |R| --------------- To make this move with the interface defined above, the player should act like he is making a normal move with the King two spaces to the left or right. 6) Allow the players to flip the board around 180 degrees so that black is on the bottom and white is on the top. This is often convenient to see the board from a different angle. Note that if you implement option 10, the notations must be accounted for, as well as the labeling. 7) Implement the standard scoring system. In this system, Queens are worth 9 points, Rooks are worth 5, Bishops and Knights are both worth 3 points, and Pawns are worth 1 point. Whenever a player's piece is captured, his score goes down that many points. Both players start the game with 39 points. This must be a feature able to be turned on and of from the GUI. Note that if you implement Option 9, points are added when a pawn is promoted. 8) Implement the "en passant" rule, French for "in passing". This compensates for the pawn's ablility to move two squares on its first move. For this rule to be invoked, this must be the situation: --------------- | | | | | | | | --------------- | | |p| | | | | Black's pawn would be captured if he moved one space --------------- forward. | | | | | | | | --------------- | | | |P| | | | --------------- | | | | | | | | --------------- | | | | | | | | --------------- --------------- | | | | | | | | --------------- | | | | | | | | Black moves his pawn two spaces forward to avoid --------------- capture. | | | | | | | | --------------- | | |p|P| | | | --------------- | | | | | | | | --------------- | | | | | | | | --------------- --------------- | | | | | | | | --------------- | | | | | | | | White captures Black's pawn en passant anyway as if --------------- Black had only moved one space. | | |P| | | | | --------------- | | | | | | | | --------------- | | | | | | | | --------------- | | | | | | | | --------------- This move may only be made by a Pawn, and only when the other player tries to move a pawn two spaces to avoid capture. 9) Implement the feature of chess where if a pawn makes it to the back row of the other side of the board from where he started, the player may promote the pawn to any piece of his choosing, except for another king or pawn. This promotion takes place immediately. This is known as pawn promotion, and is a major factor in most games toward the end, then the players have few other pieces to play. Be sure to account for this if you implement Option 7. 10) Implement the algabraic notation for recording the game. In this system, moves are notated by letters and numbers corresponding to the starting position of the piece, and the square that it ends on. If there is a capture, indicate it with an 'X' after the move. Castlings are noted by "O-O" for a castle to the right and "O-O-O" for a castle to the left. These directions are reversed for black. If a pawn captures en passant, indicate it normally, plus an 'X' for a capture, plus "(e.p.)" to designate en passant. In the case of pawn promotion, notate the move as normal, and then put the symbol for the piece promoted to in parenthesis beside the move. These extra notations are only necessary if you have implemented these other features. These should be part of the GUI, and also be able to be turned on and off, although the notation must be kept for the entire game. Here is the numbering system for the board: ----------------- 8|r|n|b|k|q|b|n|r| So the starting position of whites queen is d1. ----------------- If white were to move the pawn in front of the king 7|p|p|p|p|p|p|p|p| two spaces, it would be notated as: ----------------- 1. e2-e4 6| | | | | | | | | ----------------- Black's move should go on the same line, so if Black 5| | | | | | | | | did the same with his king's pawn, it would look like ----------------- this: 4| | | | | | | | | 1. e2-e4 e7-e5 ----------------- 2. d2-d3 (this would be white's second move) 3| | | | | | | | | ----------------- 2|P|P|P|P|P|P|P|P| If a move puts the other player in check, indicate it ----------------- with a "+" after the move. If a move results in 1|R|N|B|Q|K|B|N|R| checkmate, append a "#" to the move. ----------------- a b c d e f g h If you implement this, be sure to put the letters and numbers on the GUI, so that the players can easily look over the game. Also be sure to flip the numbers if you implement option 6. Deliverables: ------------- Week One: Part 1: Your group is to turn in a plain ASCII text report on your group's plans for the project. This should include what extras you are going to implement, and how you are going to divide tasks between group members. Details are important, and the more detailed your plan is, the easier it will be to code this project. Part 2: There are two items to turn in for this deliverable. Part one is a sequence diagram for the most complex part of your program. This may be done in another program, or may be hand-drawn. However, to turn it in it must be a GIF-type image file. If you use a scanner, this should not be difficult. If you use another program, it should have an option to export to a GIF file. Part two is a UML diagram for your project. This UML should follow what is taught in class. You may either hand-draw, or use another program to create it, but as above, a GIF file is the only format we will accept. (This means no JPEGS or bitmaps or pieces of paper). Only one of each for your group is necessary. Week Three: This week also has two deliverables. The first one is the completed program itself. We ask you to turn in only the .java files and the images that are necessary to run the program. Note that inability to compile results in a 0 for 6c. In addition, you are individually to turn in problems and modifications that you had to make to your design. We want to hear what you did, and how well you feel you worked with the group. If your design changed, tell us why and provide an updated UML diagram for your project. Be aware that we will be asking you to do a getback and a compile during the lab period for Week 4, and an in-lab demonstration of your program, so make sure that your code works on the machines in the States cluster, under either Linux or NT (you may choose either one). Week Four: You are to prepare and turnin a test plan using the format discussed in class. The section on test cases should have both the expected and actual results for each test. Your test plan should discuss the coverage criteria that your tests achieved. Blackbox tests should be run at the system level, whitebox unit tests should be discussed in the test plan for ONE module (class). At least one function of McCabe measure greater than 5 must be tested to a coverage higher than Branch. Your test plan should be submitted in ASCII text format. You should also submit any test harness and driver software (sources) so you can obtain credit for appropriate work. Usage of the harness and drivers should be discussed somewhere in your test plan document. The Fine Print: --------------- If your program fails to compile, a zero will result for lab6c. If your project generates uncaught exceptions, whatever portion of the program that was being tested will be graded as a zero. Failure to turn in a GIF file or a plain-text ASCII file will result in a zero. Failure to attend lab will result in a 5-point deduction from that lab grade for the entire group. Every group member will receive the same grade. If you have a problem with your group, let us know immediately so we can resolve the problem. Note: This lab is probably far from perfect, although we try. All questions should be asked on the class newsgroup, or to your TA.