Remove unneeded block place parameters + refactor
This commit is contained in:
parent
74c2eb03e6
commit
f1592d88fa
2 changed files with 44 additions and 35 deletions
|
@ -53,9 +53,9 @@ struct Block {
|
||||||
void undo(deque<int> &prev);
|
void undo(deque<int> &prev);
|
||||||
};
|
};
|
||||||
|
|
||||||
void update(int &time, deque<int> &turn, Block* root, Rectangle &dst);
|
void update(Block* root, int time, deque<int> &turn);
|
||||||
void undo(Block *root, deque<int> &prev, Rectangle &dst, int &time);
|
void undo(Block *root, deque<int> &prev, int time);
|
||||||
bool valid(Block* root, Rectangle &dst, deque<int> &turn);
|
bool valid(Block* root, Rectangle play_area, deque<int> &turn);
|
||||||
|
|
||||||
class Renderer {
|
class Renderer {
|
||||||
array<Texture2D, IMG_COUNT> textures;
|
array<Texture2D, IMG_COUNT> textures;
|
||||||
|
|
|
@ -23,14 +23,14 @@ deque<int> to_deque(Vector2 v, int depth, int size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void save_state(Block* root, int depth, int time, deque<int> &turn) {
|
void save_state(Block* root, int time, deque<int> &turn) {
|
||||||
vector<tile> state = {};
|
vector<tile> state = {};
|
||||||
root->save(&state);
|
root->save(&state);
|
||||||
|
|
||||||
string filename; std::cin >> filename;
|
string filename; std::cin >> filename;
|
||||||
std::ofstream outfile("saves/" + filename);
|
std::ofstream outfile("saves/" + filename);
|
||||||
|
|
||||||
outfile << depth << "\n" << time << "\n" << turn.size() << "\n";
|
outfile << root->depth << "\n" << time << "\n" << turn.size() << "\n";
|
||||||
|
|
||||||
// Save turns
|
// Save turns
|
||||||
for(int play : turn)
|
for(int play : turn)
|
||||||
|
@ -40,48 +40,57 @@ void save_state(Block* root, int depth, int time, deque<int> &turn) {
|
||||||
for(tile t : state)
|
for(tile t : state)
|
||||||
outfile << int(t) << std::endl;
|
outfile << int(t) << std::endl;
|
||||||
}
|
}
|
||||||
void load_state(Block** root, deque<int> &turn, int &depth, int &time, char* argv) {
|
void load_state(Block** root, deque<int> &turn, int &time, char* argv) {
|
||||||
depth = atoi(argv);
|
int depth = atoi(argv);
|
||||||
if(depth)
|
if(depth) {
|
||||||
*root = new Block(depth, {0, 0, SCREEN, SCREEN});
|
*root = new Block(depth, {0, 0, SCREEN, SCREEN});
|
||||||
else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load file
|
||||||
string path = "saves/" + string(argv);
|
string path = "saves/" + string(argv);
|
||||||
std::ifstream infile(path);
|
std::ifstream infile(path);
|
||||||
infile >> depth >> time;
|
infile >> depth >> time;
|
||||||
|
|
||||||
|
// Load turns
|
||||||
int K; infile >> K;
|
int K; infile >> K;
|
||||||
for(int k = 0; k < K; k++) {
|
for(int k = 0; k < K; k++) {
|
||||||
int play; infile >> play;
|
int play; infile >> play;
|
||||||
turn.push_back(play);
|
turn.push_back(play);
|
||||||
cout << play;
|
cout << play;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load board
|
||||||
vector<tile> state = {};
|
vector<tile> state = {};
|
||||||
|
|
||||||
long long pw = 1;
|
long long pw = 1;
|
||||||
for(int i = 0; i < depth; i++) pw *= 9;
|
for(int i = 0; i < depth; i++)
|
||||||
|
pw *= 9;
|
||||||
|
|
||||||
for(int i = 0; i < pw; i++) {
|
for(int i = 0; i < pw; i++) {
|
||||||
int next; infile >> next;
|
int next; infile >> next;
|
||||||
state.push_back((tile)next);
|
state.push_back((tile)next);
|
||||||
}
|
}
|
||||||
|
|
||||||
*root = new Block(depth, {0, 0, SCREEN, SCREEN});
|
*root = new Block(depth, {0, 0, SCREEN, SCREEN});
|
||||||
(*root)->load_state(state, 0);
|
(*root)->load_state(state, 0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(int &time, deque<int> &turn, Block* root, Rectangle &dst) {
|
void update(Block *root, int time, deque<int> &turn) {
|
||||||
time++;
|
time++;
|
||||||
turn.erase(turn.begin());
|
turn.erase(turn.begin());
|
||||||
int rval_2 = root->play(turn, pas(time));
|
int rval_2 = root->play(turn, pas(time));
|
||||||
for(int i = 0; i <= rval_2; i++)
|
for(int i = 0; i <= rval_2; i++)
|
||||||
turn.pop_back();
|
turn.pop_back();
|
||||||
dst = root->getRect(turn);
|
|
||||||
}
|
}
|
||||||
void undo(Block *root, deque<int> &prev, Rectangle &dst, int &time) {
|
void undo(Block *root, deque<int> &prev, int time) {
|
||||||
if(prev.size() == 0) return;
|
if(prev.size() == 0) return;
|
||||||
time--;
|
time--;
|
||||||
root->undo(prev);
|
root->undo(prev);
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
bool valid(Block* root, Rectangle &dst, deque<int> &turn) {
|
bool valid(Block *root, Rectangle play_area, deque<int> &turn) {
|
||||||
return CheckCollisionRecs(root->getRect(turn), dst) && root->playable(turn);
|
return CheckCollisionRecs(root->getRect(turn), play_area) && root->playable(turn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,7 +104,7 @@ int main(int argc, char** argv) {
|
||||||
root = new Block(depth, {0, 0, SCREEN, SCREEN});
|
root = new Block(depth, {0, 0, SCREEN, SCREEN});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
load_state(&root, turn, depth, time, argv[1]);
|
load_state(&root, turn, time, argv[1]);
|
||||||
|
|
||||||
Rectangle play_area = root->getRect(turn);
|
Rectangle play_area = root->getRect(turn);
|
||||||
|
|
||||||
|
@ -124,7 +133,7 @@ int main(int argc, char** argv) {
|
||||||
end = true;
|
end = true;
|
||||||
break;
|
break;
|
||||||
case OKAY:
|
case OKAY:
|
||||||
update(time, turn, root, play_area);
|
update(root, time, turn);
|
||||||
pturn = turn;
|
pturn = turn;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +141,7 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
// Key presses
|
// Key presses
|
||||||
if(IsKeyPressed(KEY_X))
|
if(IsKeyPressed(KEY_X))
|
||||||
save_state(root, depth, time, turn), end = true;
|
save_state(root, time, turn), end = true;
|
||||||
else if(IsKeyPressed(KEY_Z))
|
else if(IsKeyPressed(KEY_Z))
|
||||||
{} // TODO undo
|
{} // TODO undo
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue