Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Board::traverse (Tile *t, Neighbours neighbours) {
- t->visited = true;
- COO coo = make_pair(t->i, t->j);
- Buddies buddies = neighbours[coo];
- if (t->color != '0' && t->color != '.') {
- for (uint i = 0; i < buddies.size(); i++) {
- Tile *buddy = &this->field[buddies[i]];
- if (buddy->visited && buddy->color == t->color) {
- if (buddy->chain_id == -1) {
- buddy->chain_id = this->chains.size();
- this->chains[buddy->chain_id].push_back(*buddy);
- }
- t->chain_id = buddy->chain_id;
- this->chains[t->chain_id].push_back(*t);
- break;
- }
- }
- if (t->chain_id == -1) {
- t->chain_id = this->chains.size();
- this->chains[t->chain_id].push_back(*t);
- }
- }
- for (uint i = 0; i < buddies.size(); i++) {
- if (!this->field[buddies[i]].visited) {
- this->traverse(&this->field[buddies[i]], neighbours);
- }
- }
- }
- class Board():
- def __init__(self, s):
- self.field = []
- self.chains = {}
- self.heights = None
- self.score = 0
- self.step = 1
- def traverse(self, t=None):
- t.visited = True
- buddies = neighbours[(t.i, t.j)]
- if t.color != '0' and t.color != '.':
- for i, j in buddies:
- if self.field[i][j].visited and self.field[i][j].color == t.color:
- if self.field[i][j].chain_id is None:
- self.field[i][j].chain_id = len(self.chains)
- self.chains[self.field[i][j].chain_id] = [self.field[i][j]]
- t.chain_id = self.field[i][j].chain_id
- self.chains[t.chain_id].append(t)
- break
- if t.chain_id is None:
- t.chain_id = len(self.chains)
- self.chains[t.chain_id] = [t]
- for i, j in buddies:
- if not self.field[i][j].visited:
- self.traverse(self.field[i][j])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement