//run an automatic game. tla1 and tla2 should be set up prior to calling int autoGame(Unit *u[]) { bool done = false; // set up the board setUpBoard(u); while (!done) { // do a turn ++numTurns; doTurn(u); if (oneLeft(u))done = true; } if (AUTOTOURNEY) { if (winner == tla[0])return 2; else if (winner == "tie")return 1; } return 0; }
int main() { Unit *u[NUM]; char line[1024]; bool done = false; numTurns = 0; srand(time(NULL)); // if running an auto tourney, just do that and quit if (AUTOTOURNEY) { autoTourney(u); return 0; } // set up the board setUpBoard(u); display(u); cin.getline(line, 1023); cout << sout.str(); sout.str(""); while (!done) { // do a turn ++numTurns; doTurn(u); display(u); cin.getline(line, 1023); cout << sout.str(); sout.str(""); if (line[0] == 'q')done = true; if (oneLeft(u))done = true; } return 0; }
void play(){ setUpBoard(); numMoves = 0; pelletsLeft = 194; printscores(); //cursor pos is data[row-1][col-1] while (1){ while ((c = getkey()) == KEY_NOTHING); if (c == KEY_RIGHT){ if (data[row-1][col] == '#') ; else{ numMoves++; putchar(' '); data[row-1][col-1] = ' '; //special middle area if (row == 12 && col == 23) xt_par2(XT_SET_ROW_COL_POS, row=12, col=1); else xt_par2(XT_SET_ROW_COL_POS, row, ++col); if (data[row-1][col-1] == '*') pelletsLeft--; putchar('<'); printscores(); if (pelletsLeft == 0){ endGame(); break; } } } else if (c == KEY_LEFT){ if (data[row-1][col-2] == '#') ; else{ numMoves++; putchar(' '); data[row-1][col-1] = ' '; //special middle area if (row == 12 && col == 1) xt_par2(XT_SET_ROW_COL_POS, row=12, col=23); else xt_par2(XT_SET_ROW_COL_POS, row, --col); if (data[row-1][col-1] == '*') pelletsLeft--; putchar('>'); printscores(); if (pelletsLeft == 0){ endGame(); break; } } } else if (c == KEY_UP){ if (data[row-2][col-1] == '#') ; else{ numMoves++; putchar(' '); data[row-1][col-1] = ' '; xt_par2(XT_SET_ROW_COL_POS, --row, col); if (data[row-1][col-1] == '*') pelletsLeft--; putchar('V'); printscores(); if (pelletsLeft == 0){ endGame(); break; } } } else if (c == KEY_DOWN){ if (data[row][col-1] == '#') ; else{ numMoves++; putchar(' '); data[row-1][col-1] = ' '; xt_par2(XT_SET_ROW_COL_POS, ++row, col); if (data[row-1][col-1] == '*') pelletsLeft--; putchar('A'); printscores(); if (pelletsLeft == 0){ endGame(); break; } } } if(c == KEY_F3){ play(); break; } if(c == KEY_F2)break; } getkey_terminate(); xt_par0(XT_CLEAR_SCREEN); }