-
Notifications
You must be signed in to change notification settings - Fork 4
/
simple_bot.cc
45 lines (40 loc) · 1.18 KB
/
simple_bot.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 "simple_bot.h"
#include "roll.h"
#include <algorithm>
#include <cassert>
#include <iostream>
#include <limits>
using namespace std;
void SimpleBot::prepareTurn(Game const &) {
}
bool SimpleBot::chooseWhetherToRoll(Game const &game, Dice const &taken) {
Tile take = game.stealableTile(this, taken);
if (!take.valid()) {
take = game.bestRemainingTile(taken);
}
if (!take.valid()) {
cout << "\"No tile to take yet.\"\n";
return true;
}
cout << "\"I can take a tile.\"\n";
return false;
}
DieSide const *SimpleBot::chooseSideToTake(Game const &, Dice const &taken, Dice const &roll) {
Score maxScore = 0;
DieSide const *maxSide = nullptr;
for (DieSide const *side : {DieSide::WORM, DieSide::FIVE, DieSide::FOUR, DieSide::THREE, DieSide::TWO, DieSide::ONE}) {
if (roll.contains(side) && !taken.contains(side)) {
if (side == DieSide::WORM && taken.sideCount() >= 2) {
return side;
}
Score score = side->score() * roll[side];
if (score > maxScore) {
maxScore = score;
maxSide = side;
}
}
}
assert(maxSide);
cout << "\"Highest value side is " << maxSide->toString() << ".\"\n";
return maxSide;
}