” CSSE2310编程 写作、 写作Data structures编程ExampleExample Design Document for CSSE2310 Assignment X – tictactoe++Data structuresDue to the fixed size of the game board (3×3), I am using a 3×3 array of integers to store thegame state. To avoid using global variables, I have encapsulated this into a type, supported byan enum to capture player identities. PLAYER NONE indicates an empty space.enum player {PLAYER_NONE = 0, PLAYER_X = 1, PLAYER_O = 2);typedef struct gameState {enum player board[3][3]; // Contents of boardenum player who; // Whose turn is it?} gameState;Game logicThe game logic is pretty simple, my main loop just keeps track of whose turn it is, reading thenext move for that player. Handling Of game saving and loading is done in the getInput()function. After each valid move, the function checkWinner() is called to see if anybody haswon the game. checkWinner() it a wrapper function around several other functions that areused to check for rows, columns or diagonals filled by the same player marker. I could haveprobably done this more efficiently.File handlingMy program was required to read several different kinds of files, although there were somethings in common. Files could have comment lines starting with # so I wrote a functioncalled readLineWithComments() to handle this.Using this as a building block, I wrote functions to Handle each of the possible file types Ihad to read.CSSE2310作业 写作、 写作Data structures作业、DisplayEncapsulating the game state into a struct made it really easy for me to write a functiondisplayBoard() which I could update as Required. In particular, the requirement to print rowand column headers, and separator characters between player markers was something I couldjust implement in displayBoard() Without changing the underlying gameState data type. Ireally feel like I learned something About data type abstraction in this assignment.Error handlingThe specification defines a large number of possible error conditions, some of which mightpossibly occur in the same run. A clarification was posted to the course Piazza which said thatonly one error cnodition would be tested at a time, which means that the relative priority oferror states and the order of checking is not critical.My approach to error handling is by printing a hard-coded string and calling exit() witha hard-coded error code, as shown below:if (something bad happened) {printf(SOMETHING BAD HAPPENED\n);exit(15);}Given that there are about 10 possible error codes, this means I have exit() calls scatteredall around my program. On reflection, this approach made it quite painful for me when thespec changed and updated Some error messages and codes. I might think about doing thisdifferently next time. It also made it difficult to debug my program.1如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。