100 likes | 239 Views
Thursday, February 7, 2013. Project 1, Testing. Header Files. Most end with .h To use header file in program: ‘#include< header.h >’ Programmer can reuse code amongst files Can share declarations amongst several source files Including header file essentially copies contents into program
E N D
Thursday, February 7, 2013 Project 1, Testing
Header Files • Most end with .h • To use header file in program: ‘#include<header.h>’ • Programmer can reuse code amongst files • Can share declarations amongst several source files • Including header file essentially copies contents into program • Less-time consuming • <>: computer looks in standard library path (stdio.h) • “”: computer looks in same path as source file
chess.h • Defines constants • Board • Pieces • Valid/Invalid Moves • Declares methods and parameters
Project 1 • board.c • For the board and printing chess pieces on board • To print board, call print_boardfunction • chess.c • Main function calls move_loop that runs game • Prints board, alternately calls get_valid_move for each player • get_valid_moveprompts for move and callscheck_move which checks validity of move
check.c • General • X-Y coordinates are valid • “from” and “to” are different squares • “from” contains piece of valid color • “to” does not contain piece of same color (can contain piece of opposite color – capturing)
Notes • Queen • check_queen is valid if check_rook or check_bishop is valid! • No need to detect checkmate • Termination occurs at -1 -1 -1 -1 (IMPORTANT) • Required functions
Test Vectors • < and > to redirect input/output to/from file • Automatic comparison, diff
Test Vectors • Reminder: • Make sure output matches EXACTLY • Points will be deducted for errors, including formatting • Watch out for: • Extra spaces • Capitalization, punctuation
Common Compiler Errors • “Incompatible implicit declaration” • Missing library (ie #include <stdio.h>) • “Error: expected ‘;’”… • Syntax error (missing semicolon, parenthesis) • Using printf’s, while tedious, can also be very helpful