relatorio
[xYpjg3TdSw.git] / Board.cpp
blob790ed0325a542cf366e40218d59a02f423869209
1 #include "Board.h"
2 #include "common.h"
4 #include <cstdlib>
5 #include <cstdio>
6 #include <cstring>
7 #include <ctime>
9 #include <vector>
10 #include <string>
11 #include <bitset>
12 #include <iostream>
13 #include <map>
14 #include <set>
16 //direções de movimento: vertical, horizontal e duas diagonais
17 char dx[] = {0, 1, 1, 1}, dy[] = {1, 0, 1, -1};
18 char horiz[8], vert[8], diag[2][15];
19 Board::Imp both, adj;
20 bool g_player;
22 Board::Board()
26 #define SQU(x) ((x) * (x))
27 #define MAX(x, y) ((x) > (y) ? (x) : (y))
29 void Board::initial_position()
31 t[0].reset();
32 t[1].reset();
34 rep(i, 2)
35 repbe(j, 1, 6) {
36 set(0, i * 7, j);
37 set(1, j, i * 7);
40 centro[0] = centro[1] = 15.16;
41 cmx[0] = cmx[1] = cmy[0] = cmy[1] = 3.5;
42 concentration[0] = concentration[1] = 22.0;
43 centralisation[0] = centralisation[1] = -21.66;
44 masscenter[0] = masscenter[1] = 24.5;
45 quads[0] = quads[1] = 0.0;
46 connectedness[0] = connectedness[1] = 1.67;
47 uniformity[0] = uniformity[1] = 48;
52 void Board::moves(bool player, int fromX, int fromY, MoveList &to)
54 rep(i, 8)
55 horiz[i] = vert[i] = 0;
56 rep(i, 15)
57 diag[0][i] = diag[1][i] = 0;
59 both = t[0] | t[1];
61 rep(i, 8)
62 rep(j, 8)
63 if(both.test(INDEX(i, j))) {
64 horiz[i]++;
65 vert[j]++;
66 diag[0][DIAG0(i, j)]++;
67 diag[1][DIAG1(i, j)]++;
70 int k, x, y;
71 bool valid_move;
73 int i = fromX,
74 j = fromY;
75 if(get(player, i, j)) {
76 rep(d, 4) {
77 k = count(d, i, j);
78 for(int m = -1; m <= 1; m += 2) {
79 valid_move = true;
81 x = i + k * dx[d] * m;
82 y = j + k * dy[d] * m;
83 if(x > 7 || x < 0 ||
84 y > 7 || y < 0) { // fora do tabuleiro
85 continue;
88 repb(z, 1, k) {
89 x = i + z * dx[d] * m;
90 y = j + z * dy[d] * m;
91 if(get(!player, x, y)) { // barrado por inimigo
92 valid_move = false;
93 break;
97 if(valid_move) {
98 x = i + k * dx[d] * m;
99 y = j + k * dy[d] * m;
100 if(!get(player, x, y)) { // não é sobre um amigo
101 to.push_back(Move(INDEX(i, j), INDEX(x, y)));
109 bool board_compare(const Board::Comp& l, const Board::Comp& r) {
110 return l.first < r.first || (l.first == r.first && l.second < r.second);