void Board::insert(int num, int turn) throw(Exceptions){ num--; bool INPUT_INRANGE = num>=0 && num <=size; if( !INPUT_INRANGE ){ throw(Exceptions("Input out of range or already occupied.")); } bool FIELD_EMPTY = ( board[num] != 'X' && board[num] != 'O' ); if ( FIELD_EMPTY ){ board[num] = players[turn].getSymbol(); } else { throw(Exceptions("Input out of range or already occupied.")); } }
bool Repository::addStudent(Student s) { if (find(v.begin(), v.end(), s) == v.end()) { v.push_back(s); writeToFile(); } else { throw(Exceptions("Deja este ba!!")); } return true; }
bool Repository::removeStudent(Student s) { vector<Student>::iterator it = find(v.begin(), v.end(), s); if (it == v.end()) { v.erase(it); writeToFile(); } else { throw(Exceptions("Deja este ba!!")); } return true; }
Stone AI::helpMe(Stone::E_COLOR color) { _color = color; Stone stone(-1, -1, color); initOpenTiles(); try { _playBeginTime = (float)clock(); stone = calc(2); } catch (const Exceptions& e) { } if (stone.x() == -1) throw Exceptions("AI CAN'T PLAY :(");//TODO : catch + haut std::cout << "AI help depth " << 2 << std::endl; return stone; }
Stone AI::plays() { Stone stone(-1, -1, _color); int depth = 1; initOpenTiles(); try { _playBeginTime = (float)clock(); while (true) { stone = calc(depth++); } } catch (const Exceptions& e) { depth -= 1; } if (stone.x() == -1) throw Exceptions("AI CAN'T PLAY :(");//TODO : catch + haut std::cout << "AI depth " << depth-1 << std::endl; return stone; }
inline void AI::checkTime() { if (((float)clock() / CLOCKS_PER_SEC) - (_playBeginTime / CLOCKS_PER_SEC) > _durationSeconds) throw Exceptions("AI timeLimitSec exceeded"); }