-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSave.cpp
55 lines (42 loc) · 1.04 KB
/
Save.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
/*
* Save.cpp
*
* Created on: Aug 23, 2012
* Author: msinclair94
*/
#include "Save.hpp"
#include <algorithm>
Save::Save() :
turn(true), mustJump(0), WP(Bit::Masks::WP_INIT), BP(Bit::Masks::BP_INIT), K(0) {
}
void swap(Save& first, Save& second) {
using std::swap;
swap(first.turn, second.turn);
swap(first.mustJump, second.mustJump);
swap(first.WP, second.WP);
swap(first.BP, second.BP);
swap(first.K, second.K);
}
Save::~Save() {
}
bool operator==(const Save& lhs, const Save& rhs) {
return lhs.mustJump == rhs.mustJump && lhs.turn == rhs.turn && lhs.WP == rhs.WP
&& lhs.BP == rhs.BP && lhs.K == rhs.K;
}
void Save::write(std::string fname) const {
using std::endl;
using std::ofstream;
ofstream saveFile(fname.c_str());
saveFile << turn << " " << mustJump << endl;
saveFile << WP << endl;
saveFile << BP << endl;
saveFile << K << endl;
}
void Save::read(std::string fname) {
using std::ifstream;
ifstream saveFile(fname.c_str());
saveFile >> turn >> mustJump;
saveFile >> WP;
saveFile >> BP;
saveFile >> K;
}