-
Notifications
You must be signed in to change notification settings - Fork 1
/
SpaceItem.cpp
69 lines (53 loc) · 1.75 KB
/
SpaceItem.cpp
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
/*
* File: SpaceItem.cpp
* Author: Tomáš Čerevka, Adam Činčura
*
* Created on November 8, 2011, 9:40 AM
*/
#include "SpaceItem.h"
SpaceItem::SpaceItem() {
}
SpaceItem::SpaceItem(const Board& _board, const Move& _move) :
board(_board) {
moves.push_back(_move);
}
SpaceItem::SpaceItem(const Board& _board, const vector<Move>& _moves) :
board(_board), moves(_moves) {
}
SpaceItem::SpaceItem(const Board& _board, const vector<Move>& _moves, const Move& _move) :
board(_board), moves(_moves) {
moves.push_back(_move);
}
SpaceItem::~SpaceItem() {
}
void SpaceItem::serialize(char* _buffer, int& _position) const {
// Serializuje se deska.
board.serialize(_buffer, _position);
// Serializuje se historie tahu.
int size = moves.size();
MPI_Pack(&size, 1, MPI_INT, _buffer, BUFFER_SIZE, &_position, MPI_COMM_WORLD);
// Serializuji se tahy v historii.
for (vector<Move>::const_iterator it = moves.begin(); it < moves.end(); ++it) {
it->serialize(_buffer, _position);
}
}
void SpaceItem::deserialize(char* _buffer, int& _position) {
// Deserializuje se deska.
board.deserialize(_buffer, _position);
// Deserializuje se historie tahu.
int size;
MPI_Unpack(_buffer, BUFFER_SIZE, &_position, &size, 1, MPI_INT, MPI_COMM_WORLD);
for (int i = 0; i < size; ++i) {
Move move;
move.deserialize(_buffer, _position);
moves.push_back(move);
}
}
ostream& operator<<(ostream& _ostream, const SpaceItem& _spaceItem) {
_ostream << _spaceItem.board << endl;
_ostream << "History: " << endl;
for (vector<Move>::const_iterator it = _spaceItem.moves.begin(); it < _spaceItem.moves.end(); ++it) {
_ostream << *it << endl;
}
return _ostream;
}