-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnakemove.hpp
More file actions
executable file
·71 lines (57 loc) · 1.78 KB
/
snakemove.hpp
File metadata and controls
executable file
·71 lines (57 loc) · 1.78 KB
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
69
70
71
//
// snakemove.hpp
// polymersim
//
// Created by Bin Xu on 11/18/15.
// Copyright © 2015 Bin Xu. All rights reserved.
//
#ifndef snakemove_hpp
#define snakemove_hpp
#include <tuple>
#include <vector>
using std::tuple;
using std::vector;
using std::make_tuple;
template <class S, class P>
class SnakeMove
{
private:
S& space;
public:
SnakeMove(S& thespace): space(thespace) {}
void UpdatePolymer(Polymer<P>& poly, int pointid, P& newpoint)
{
if (pointid != 0) // move towards head
{
poly.locs.pop_back();
poly.locs.insert(poly.locs.begin(), newpoint);
}
else
{
poly.locs.erase(poly.locs.begin());
poly.locs.push_back(newpoint);
}
}
void UpdateReverseCheckingSpace(P& oldpoint, P& newpoint, Polymer<P>& poly)
{
assert(space.GetRspacePoint(newpoint)[0] == NOBOND);
int polyid = space.GetRspacePoint(oldpoint)[0];
space.SetRspacePoint(oldpoint, NOBOND, NOBOND);
for (int i = 0; i < poly.locs.size(); i++)
space.SetRspacePoint(poly.locs[i], polyid, i);
}
vector<tuple<int, int, P>> GetPossibleMoves(Polymer<P>& poly)
{
int endloc_head = 0;
int endloc_tail = (int)poly.locs.size() - 1;
vector<tuple<int, int, P>> possible_moves;
for (auto pos : space.Neighbor(poly.locs[endloc_head]))
if (space.EmptyPos(pos))
possible_moves.push_back(make_tuple(endloc_tail, endloc_head, pos));
for (auto pos : space.Neighbor(poly.locs[endloc_tail]))
if (space.EmptyPos(pos))
possible_moves.push_back(make_tuple(endloc_head, endloc_tail, pos));
return possible_moves;
}
};
#endif /* snakemove_hpp */