main.cpp
来自「数据结构与程序设计教材源码 数据结构与程序设计教材源码」· C++ 代码 · 共 71 行
CPP
71 行
#include "../../C/UTILITY.H"
#include "../../C/UTILITY.CPP"
#include "MOVE.H"
#include "MOVE.CPP"
typedef Move Stack_entry; // Type for Stack entries.
#include "../../2/STACK/STACK.H"
#include "../../2/STACK/STACK.CPP"
#include "BOARD.H"
#include "BOARD.CPP"
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;
}
}
main()
{
Board game;
Move next_move;
game.instructions();
cout << " How much lookahead?";
int looka;
cin >> looka;
while (!game.done()) {
if (looka > 0)
look_ahead(game, looka, next_move);
else {
Stack moves;
game.legal_moves(moves);
moves.top(next_move);
}
game.play(next_move);
game.print();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?