rumo à ia inimiga
[xYpjg3TdSw.git] / migrando / Game.h
blob90f422407f21aaef5a1b877b00c1ca2a401210b3
1 #ifndef __IA_GAME_H__
2 #define __IA_GAME_H__
4 #include "Board.h"
6 /* número máximo de movimentos de uma partida */
7 #define MAX_MOVES 1000
8 //#define NULL 0
10 class Board;
12 class MoveHistoryEntry
14 public:
15 MoveHistoryEntry() {
16 _board = NULL;
17 _from_x = _from_y = _to_x = _to_y = -1;
20 MoveHistoryEntry(Board *board,
21 int fromX, int fromY,
22 int toX, int toY) {
23 _board = board->copy();
24 _from_x = fromX;
25 _from_y = fromY;
26 _to_x = toX;
27 _to_y = toY;
30 const MoveHistoryEntry& operator=(const MoveHistoryEntry& entry) {
31 if(_board) delete _board;
32 _board = entry._board;
33 _from_x = entry._from_x;
34 _from_y = entry._from_y;
35 _to_x = entry._to_x;
36 _to_y = entry._to_y;
37 return *this;
40 Board *board() { return _board; }
41 int from_x() { return _from_x; }
42 int from_y() { return _from_y; }
43 int to_x() { return _to_x; }
44 int to_y() { return _to_y; }
46 private:
47 Board *_board;
48 int _from_x, _from_y, _to_x, _to_y;
52 class Game
54 public:
55 Game();
56 ~Game();
57 void move(int fromX, int fromY, int toX, int toY);
58 bool think(int& fx, int& fy, int& tx, int& ty);
59 void fill_moves(int x, int y, bool *to);
60 bool can_move(int x, int y);
61 void fill_pieces(bool *isEmpty, char *piece);
62 void set_player(bool player);
63 bool can_undo() { return _current_move > 1; }
64 bool can_redo() { return _current_move <= _move_count; }
65 void undo(int& fromX, int &fromY,
66 int& toX, int& toY) {
67 MoveHistoryEntry e;
68 if(can_undo()) {
69 e = _move_history[--_current_move - 1];
70 set(e);
71 _player = !_player;
73 fromX = e.from_x();
74 fromY = e.from_y();
75 toX = e.to_x();
76 toY = e.to_y();
78 void redo(int& fromX, int &fromY,
79 int& toX, int& toY) {
80 MoveHistoryEntry e;
81 if(can_redo()) {
82 e = _move_history[_current_move++];
83 set(e);
84 _player = !_player;
86 fromX = e.from_x();
87 fromY = e.from_y();
88 toX = e.to_x();
89 toY = e.to_y();
91 void load(FILE *in, int& fromX, int &fromY,
92 int& toX, int& toY);
93 void set(MoveHistoryEntry entry) {
94 delete _board;
95 _board = entry.board()->copy();
97 void set_computer_color(int computerColor) { _computer_color = computerColor; }
99 private:
100 Board *_board;
101 bool _player;
102 int _move_count, _current_move, _computer_color;
103 MoveHistoryEntry _move_history[MAX_MOVES];
104 FILE *_out;
108 #endif