blob: 433252ce5653a75fedd2d8f153fc21263a41abc1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#include <iostream>
#include "AutomaticNumberGuesser.h"
#include "NumberGuessGame.h"
AutomaticNumberGuesser::AutomaticNumberGuesser() { }
AutomaticNumberGuesser::~AutomaticNumberGuesser() { }
void AutomaticNumberGuesser::process(NumberGuessGame &game) {
unsigned low = game.getLowerBound();
unsigned high = game.getUpperBound();
bool found = false;
while (!found) {
unsigned guess = (low + high) / 2;
enum NumberGuessGame::RESULT r = game.guess(guess);
if (r == NumberGuessGame::TOOLOW) low = guess;
else if (r == NumberGuessGame::TOOHIGH) high = guess;
else found = true;
}
}
|