-
Notifications
You must be signed in to change notification settings - Fork 0
/
easydifficulty.cc
45 lines (40 loc) · 1.34 KB
/
easydifficulty.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "easydifficulty.h"
LevelOne::LevelOne() : DifficultyLevel{TrivialEvaluator{}, RandomMoveOrderer{}} {}
LevelTwo::LevelTwo() : DifficultyLevel{TrivialEvaluator{}, RandomMoveOrderer{}} {}
Move LevelOne::getMove(Board& board) {
//Pick a random move:
moveOrderers[0]->seedMoveOrderer(board, false);
Move move = moveOrderers[0]->pickNextMove(false);
do {
bool legal = board.applyMove(move);
if(legal) {
board.revertMostRecent();
return move;
}
move = moveOrderers[0]->pickNextMove(false);
} while(!move.isMoveNone());
return Move{};
}
Move LevelTwo::getMove(Board& board) {
//Pick a random move that preferably is a check or a noisy capture:
moveOrderers[0]->seedMoveOrderer(board, true);
Move move = moveOrderers[0]->pickNextMove(true);
do {
bool legal = board.applyMove(move);
if(legal) {
board.revertMostRecent();
return move;
}
move = moveOrderers[0]->pickNextMove(true);
} while(!move.isMoveNone());
moveOrderers[0]->seedMoveOrderer(board, false);
do {
bool legal = board.applyMove(move);
if(legal) {
board.revertMostRecent();
return move;
}
move = moveOrderers[0]->pickNextMove(false);
} while(!move.isMoveNone());
return Move{};
}