[問題] C++作OOXX 題目

看板HSNU_1120作者 (司馬中路無敵)時間17年前 (2008/06/02 20:17), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
1. void initializeBoard(Stone board[]); This function initialize board[0]~board[8] to be EMPTY. 2. void printBoard(Stone board[]); This function prints out the board according to the array board[]. For example, below is the board output for board[0]==COMPUTER, board[4]==USER, and all other entries are EMPTY. (Every cell is 5 by 3 char, print out “O” for USER, “X” for COMPUTER). +-----+-----+-----+ | | | | | X | | | | 0| 1| 2| +-----+-----+-----+ | | | | | | O | | | 3| 4| 5| +-----+-----+-----+ | | | | | | | | | 6| 7| 8| +-----+-----+-----+ 3. bool userFirst();. This function asks “Are you taking first? (Y/N): “. It return true for ‘Y’ or ‘y’, false for ‘N’ or ‘n’; it asks repeatedly for other answers. 4. bool isValidMove(int move, Stone board[]); This function returns true if the move is between 0 and 8 and if board[move] is EMPTY. It returns false otherwise. 5. void userMakingMove(Stone board[]); This fucntion repeatedly asks the user "Input a move (0~8): " until the user enter a valid move. Then it sets board[move] to USER. 6. void getValidMoves(Stone board[], int movesArray[], int& numMoves); This function puts all valid moves in movesArray[], and set numMoves to be the number of all valid moves. 7. int getLineScore(Stone s1, Stone s2, Stone s3); This function takes three stones and returns a score according to the following table: Cases Score 9000 3 “X” 90 2 “X” & 1 “ “ 9 1 “X” & 2 “ “ 0 3 “ “ -10000 3 “O” -100 2 “O” & 1 “ “ -10 1 “O” & 2 “ “ 0 Others 8. int getScore(Stone board[]); This function calls getLineScore 8 times. It simply return the summation of eight lineScores. 9. bool shouldTerminate(Stone board[]); This function prints “Computer Wins!!!” and returns true if getScore(board)>1000; it prints “You Win!!!” and returns true if getScore(board) < -1000. It prints“Tie!!!” and returns true if no EMPTY in board[]. It returns false otherwise; 10. void computerMakingMove(Stone board[]); (1) It calls getValidMove(); (2) For every valid move i, it sets board[i]=COMPUTER, then getScore(board), record the maxMove that gets the highest score, then reset board[i]=EMPTY. (3) It sets board[maxMove] = COMPUTER. (4) It calls printBoard(board); Note: Do not modify anything in main(). If your functions are implemented correctly, the program should be able to guess your number. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.4.234 ※ 編輯: hsj8266 來自: 140.112.4.234 (06/02 20:25)
文章代碼(AID): #18G-JBPF (HSNU_1120)