Đang chuẩn bị liên kết để tải về tài liệu:
Data Structures and Program Design in C++ phần 4

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

Tham khảo tài liệu 'data structures and program design in c++ phần 4', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Section 5.4 Tree-Structured Programs Look-Ahead in Games 203 5.4.4 Refinement 149 The outline of Section 5.4.3 leads to the following recursive function. int look_ahead const Board game int depth Move recommended Pre Board game represents a legal game position. Post An evaluation of the game based on looking ahead depth moves is returned. The best move that can be found for the mover is recorded as Move recommended. Uses The classes Stack Board and Move together with function look_ahead recursively. if game.done depth 0 return game.evaluate else Stack moves game.legal_moves moves int value best_value game.worst_case while moves.empty Move try_it reply moves.top try_it Board new_game game new_game.play try_it value look_ahead new_game depth - 1 reply if game.better value best_value try_it is the best move yet found best_value value recommended try_it moves. pop return best_value The reference parameter Move recommended is used to return a recommended move unless the game is over or the depth of search is 0 . The reference parameter Board game could be specified as a value parameter since we do not want to change the Board in the function. However to avoid a possibly expensive copying operation we pass game as a constant reference parameter. Observe that the compiler can guarantee that the object Board game is unchanged by the function look_ahead because the only Board methods that are applied have been declared with the modifier const. Without this earlier care in our definition of the class Board it would have been illegal to pass the parameter Board game as a constant. 204 Chapter 5 Recursion 5.4.5 Tic-Tac-Toe Study main program We shall finish this section by giving implementations of the classes Board and Move for use in the game of tic-tac-toe noughts and crosses . Here the classes consist of little more than a formal implementation of the rules of the game. We leave the writing of a main program that harnesses these classes with the function look_ahead to play

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.