-
Notifications
You must be signed in to change notification settings - Fork 0
/
solving_error.cc
89 lines (70 loc) · 1.99 KB
/
solving_error.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "tetravex.hh"
#include <tuple>
#include <vector>
int get_error_count(const Tetravex& game)
{
int error_count = 0;
for (int y = 0; y < game.size; y++)
for (int x = 0; x < game.size; x++)
{
Tile& tile = game.get_tile(x, y);
if (x > 0)
{
Tile& left = game.get_tile(x - 1, y);
if (left.value[EAST] != tile.value[WEST])
error_count++;
}
if (y > 0)
{
Tile& top = game.get_tile(x, y - 1);
if (top.value[SOUTH] != tile.value[NORTH])
error_count++;
}
}
return error_count;
}
bool is_well_positioned(int x, int y, enum Direction direction, int size)
{
switch (direction)
{
case NORTH:
return y == 0;
case WEST:
return x == 0;
case EAST:
return x == size - 1;
case SOUTH:
return y == size - 1;
}
return false;
}
int get_impossible_position(const Tetravex& game, const std::vector<std::pair<int, enum Direction>>& unique_values)
{
int impossible_position = 0;
for (auto& v : unique_values)
{
auto position = get_tile_position_with_value(game, v.first);
if (!is_well_positioned(std::get<0>(position), std::get<1>(position), v.second, game.size))
impossible_position++;
}
return impossible_position;
}
float get_bad_place_average(Tetravex& game)
{
float bad_place = 0;
for (int y = 0; y < game.size; y++)
for (int x = 0; x < game.size; x++)
bad_place += get_error_tile(game, x, y);
bad_place /= static_cast<float>(game.size * game.size);
return bad_place;
}
float get_error(const Tetravex& game, const std::vector<std::pair<int, enum Direction>>& unique_values)
{
int error_count = get_error_count(game);
return static_cast<float>(error_count);
// int impossible_position = get_impossible_position(game, unique_values);
// float bad_place = get_bad_place_average(game);
// int error = error_count + impossible_position * 10;
// float ferror = static_cast<float>(error); // + bad_place * 5;
// return ferror;
}