// Programmieren 1, Praktikum 6, Aufgabe 1 // Author: Sven Eisenhauer // Date: 14.01.2005 // File: tictactoe.cpp // Description: Implementation of class TicTacToe #include "tictactoe.h" #include #include #include using std::cout; using std::endl; using std::cin; TicTacToe::TicTacToe() :nrFields(9) { for (int i=0;i (i+49); winner=""; round=0; } TicTacToe::~TicTacToe() { cout << endl << "Game Over!" << endl; } void TicTacToe::eraseField() { for (int i=0;i> input; switch (input) { case 'p': case 'P': nextPlayer="Player"; break; case 'c': case 'C': nextPlayer="Computer"; break; default: cout << endl << "Bad selection! Enter new selection: "; } } while (input!='P' && input!='C' && input!='p' && input!='c'); } void TicTacToe::movePlayer() { int draw=0; cout << endl << "Enter your move: "; //print(); cin >> draw; while (testField(draw-1)) { cout << endl << "Irregular move... please enter a new one" << endl; cin >> draw; } field[draw-1]='X'; setNext("Computer"); round++; } int TicTacToe::testField(int f) { if (field[f]==' ') return 0; else return 1; } void TicTacToe::moveComputer() { int move=4; int vertX[3]={0}; int horX[3]={0}; int diagX[2]={0}; int vertO[3]={0}; int horO[3]={0}; int diagO[2]={0}; int n=0, x=0, y=0, d=0; if (testField(move)) { while(testField(n) && n