本文整理汇总了C++中AI::doAIMove方法的典型用法代码示例。如果您正苦于以下问题:C++ AI::doAIMove方法的具体用法?C++ AI::doAIMove怎么用?C++ AI::doAIMove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AI
的用法示例。
在下文中一共展示了AI::doAIMove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
Board board = newBoard();
Player player = newPlayer(1, PLAYER, board),
current;
AI ai = newAI(board);
WINDOW *status;
bool isRunning = TRUE;
int key;
initscr(); /* Start curses mode */
start_color(); /* Color mode */
cbreak(); /* Disable line-break mode */
keypad(stdscr, TRUE); /* Enable getch for function keys */
curs_set(0); /* Remove cursor */
noecho(); /* Disable echo */
init_pair(1, COLOR_YELLOW, COLOR_BLACK);
init_pair(2, COLOR_RED, COLOR_BLACK);
init_pair(3, COLOR_YELLOW, COLOR_YELLOW);
init_pair(4, COLOR_RED, COLOR_RED);
status = newwin(25, 20, 0, 0);
current = player;
boardDraw(board);
statusDraw(status, current, ai);
ungetch('a'); /* Skip first getch() */
while(isRunning) {
if((key = getch()) == KEY_F(1)) {
isRunning = FALSE;
break;
}
if(current == player) {
if(player->doMove(player, key)) {
/* Pass turn to AI */
current = ai->player;
ungetch('a'); /* Skip the next keystroke and instantly go to the AI */
}
} else {
ai->doAIMove(ai);
if(ai->player->doMove(ai->player, key)) {
/* Pass turn to AI */
current = player;
ungetch('a'); /* Skip the next keystroke and instantly go to the AI */
}
}
boardDraw(board);
statusDraw(status, current, ai);
if(board->isBoardFull(board)) {
getch();
wmove(status, 13, 1); wclrtoeol(status);
wattron(status, A_BOLD);
wprintw(status, "Draw Game!");
wattroff(status, A_BOLD);
wrefresh(status);
isRunning = FALSE;
getch();
}
if(board->checkForWin(board, current->getID(current))) {
int pid = current->getID(current);
getch();
wmove(status, 13, 1); wclrtoeol(status);
wattron(status, A_BOLD | COLOR_PAIR(pid));
wprintw(status, "%s", (pid == 1)?"Player":"AI");
wattroff(status, A_BOLD | COLOR_PAIR(pid));
wprintw(status, " won!");
wrefresh(status);
isRunning = FALSE;
getch();
}
}
board->destroyBoard(board);
free(player);
free(ai);
endwin();
return 0;
}