Пример #1
0
bool Board::isBlocked(int pos) const
{
	Neighbors neighbors = getNeighbors(pos);
	for(Neighbors::const_iterator it = neighbors.begin(); it != neighbors.end(); ++it)
		if(chessmen[*it] == 'x')        // try to find an empty neighbor
			return false;
	return true;
}
Пример #2
0
void add_cofaces (const Graph& graph, Simplex& tau, 
		  const Neighbors& neighbors, 
		  Complex& complex, const std::size_t dimension) {
    typedef typename Neighbors::const_iterator Neighbor_iterator;
    complex.insert_open_cell(tau);
    if(tau.dimension() >= dimension) { return; }
    Neighbors lower_neighbors; 
    Neighbors final_neighbors; 
    for(Neighbor_iterator i = neighbors.begin(); i != neighbors.end(); ++i){
      lower_neighbors.clear();
      Simplex sigma( tau);
      sigma.insert( *i);
      get_lower_neighbors(graph, *i, lower_neighbors);
      final_neighbors.clear();
      set_intersection(lower_neighbors.begin(),lower_neighbors.end(),
                       neighbors.begin(),neighbors.end(),
                       back_inserter(final_neighbors));
      add_cofaces(graph, sigma, final_neighbors, complex, dimension); 
    }
} 
Пример #3
0
int Board::countFreedom(QChar color) const
{
	int result = 0;
	for(int i=0; i<23; ++i)
		if(chessmen[i] == color)
		{
			Neighbors neighbors = getNeighbors(i);
			for(Neighbors::const_iterator it = neighbors.begin(); it != neighbors.end(); ++it)
				if(chessmen[*it] == 'x')  // empty
					result ++;
		}
	return result;
}
Пример #4
0
bool Board::closeMorris(int pos) const
{
	Neighbors neighbors = getNeighbors(pos);
	for(Neighbors::const_iterator it = neighbors.begin(); it != neighbors.end(); ++it)
	{
		if(chessmen[*it] == 'x')        // for all it's empty neighbor
		{
			Board temp(*this); 
			temp.move(pos, *it);        // move to this neighbor
			if(temp.closeMill(*it))
				return true;
		}
	}
	return false;
}
Пример #5
0
Moves MoveGenerator::generateMove(const Board& board) const
{
	Moves result;
	for(int from=0; from<23; ++from)
		if(board.getManAt(from) == board.getSelfColor())
		{
			Neighbors neighbors = Board::getNeighbors(from);
			for(Neighbors::iterator it = neighbors.begin(); it != neighbors.end(); ++it)
				if(board.isEmpty(*it))
				{
					Board next = board.makeChild();
					next.move(from, *it);
					if(next.closeMill(*it))
					{
						Moves removeMoves = generateRemove(next, board.getOpponentColor());
						copy(removeMoves.begin(), removeMoves.end(), back_inserter(result));
					}
					else
						result.push_back(next);
				}
		}
		return result;
}
Пример #6
0
bool Board::isNeighbor(int lhs, int rhs)
{
	const Neighbors neighbors = getNeighbors(lhs);
	return find(neighbors.begin(), neighbors.end(), rhs) != neighbors.end();
}