3 #include "MoveHistoryEntry.h"
4 #include "RandomEnemy.h"
5 #include "MinimaxEnemy.h"
11 /* nome do arquivo de log */
12 #define LOG_FILE "log.txt"
13 /* número máximo de movimentos de uma partida */
14 #define MAX_MOVES 1000
18 assert(sizeof(Board::ImpComp
) == 8);
20 _board
->initial_position();
22 _move_count
= _current_move
= 0;
24 _move_history
= new MoveHistoryEntry
[MAX_MOVES
];
25 _move_history
[_move_count
= _current_move
++] = MoveHistoryEntry(_board
, -1, -1, -1, -1);
26 _out
= fopen(LOG_FILE
, "a");
28 MinimaxEnemy
*t
= new MinimaxEnemy(0, _minimax_depth
);
29 t
->set_weights(((HeuType
[NUM_HEU
]) {0., 0.82723, 0., 0.97915, 0., 0.96032, 0.96950, 0.}));
31 t
= new MinimaxEnemy(1, _minimax_depth
);
32 t
->set_weights(((HeuType
[NUM_HEU
]) {0., 0.82723, 0., 0.97915, 0., 0.96032, 0.96950, 0.}));
34 //_enemy[1] = new MinimaxEnemy(1, _minimax_depth);
35 //_enemy[1] = new RandomEnemy(1, _minimax_depth);
38 char charTime
[100] = {0};
40 strftime(charTime
,sizeof(charTime
)-1,"%c",localtime(&currtime
));
41 fprintf(_out
, "time: %s\n", charTime
);
51 void Game::move(int fromX
, int fromY
, int toX
, int toY
)
53 _board
->move(_player
, Board::Move(INDEX(fromX
, fromY
), INDEX(toX
, toY
)));
56 //fprintf(_out, "back: %i\n", _move_count - _current_move + 1);
57 _move_history
[_move_count
= _current_move
++] = MoveHistoryEntry(_board
, fromX
, fromY
, toX
, toY
);
58 //fprintf(_out, "%i: %i %i %i %i\n", _move_count, fromX, fromY, toX, toY);
64 if(_computer_color
& (1 << _player
)) {
65 //printf("Computer Turn\n");
67 int fromX
, fromY
, toX
, toY
;
68 _enemy
[_player
]->move(_board
, fromX
, fromY
, toX
, toY
);
69 move(fromX
, fromY
, toX
, toY
);
72 //printf("Player Turn\n");
77 void Game::fill_moves(int x
, int y
, bool *to
)
79 Board::MoveList moveList
;
80 _board
->moves(_player
, x
, y
, moveList
);
83 to
[(int) moveList
[i
].second
] = 1;
87 bool Game::can_move(int x
, int y
)
89 return _board
->get(_player
, x
, y
);
92 void Game::fill_pieces(bool *isEmpty
, char *piece
)
96 isEmpty
[INDEX(i
, j
)] = !(_board
->get(0, i
, j
) || _board
->get(1, i
, j
));
100 if(_board
->get(1, i
, j
))
101 piece
[INDEX(i
, j
)] = 1;
102 else piece
[INDEX(i
, j
)] = 0;
105 void Game::set_player(bool player
)
108 fprintf(_out
, "player: %i\n", _player
? 1 : 0);
114 _enemy
[0]->undo(_board
);
115 _enemy
[1]->undo(_board
);
116 set(_move_history
[--_current_move
- 1]);
124 set(_move_history
[_current_move
++]);
129 void Game::set(MoveHistoryEntry entry
) {
131 _board
= entry
.board()->copy();
134 void Game::get_last_move(int& fromX
, int &fromY
, int& toX
, int& toY
)
136 MoveHistoryEntry e
= _move_history
[_current_move
- 1];
143 void Game::load(FILE *in
)
145 int back
, eof
, player
, fromX
, fromY
, toX
, toY
;
147 if(0 != (eof
= fscanf(in
, "%*i: %i %i %i %i", &fromX
, &fromY
, &toX
, &toY
))) {
148 if(eof
== EOF
) break;
149 printf("move: %i %i %i %i\n", fromX
, fromY
, toX
, toY
);
150 move(fromX
, fromY
, toX
, toY
);
151 } else if(0 != (eof
= fscanf(in
, "time: %*[^\n]"))) {
152 if(eof
== EOF
) break;
154 } else if(0 != (eof
= fscanf(in
, "back: %i", &back
))) {
155 if(eof
== EOF
) break;
156 printf("back: %i\n", back
);
157 for(int i
= 0; i
< back
; i
++)
159 } else if(0 != (eof
= fscanf(in
, "player: %i", &player
))) {
160 if(eof
== EOF
) break;
161 printf("player: %i\n", player
);
167 void Game::set_minimax_depth(int minimaxDepth
)
169 _enemy
[0]->set_minimax_depth(minimaxDepth
);
170 _enemy
[1]->set_minimax_depth(minimaxDepth
);
175 bool res
= _board
->is_end();
176 //if(res) ;//fflush(_out);
180 void Game::set_players(Enemy
*a
, Enemy
*b
)
190 _board
->initial_position();
198 if(_board
->get(0, i
, j
)) printf("x");
199 else if(_board
->get(1, i
, j
)) printf("o");