deque<Board::ConstStackHandle> Game::possibleDestinations(const Board::ConstStackHandle& ha) const { deque<Board::ConstStackHandle> r; if (ha->hasPieces()) { unsigned int h = ha->height(); Board::Coord s = ha.stackCoord(); Board::Coord d[6] = { Board::Coord(s.x()-h,s.y()), Board::Coord(s.x()+h,s.y()), Board::Coord(s.x() ,s.y()-h), Board::Coord(s.x() ,s.y()+h), Board::Coord(s.x()-h,s.y()-h), Board::Coord(s.x()+h,s.y()+h) }; for (unsigned int i=0;i<6;++i) { if (Board::isValid(d[i]) && board_.stackAt(d[i])->hasPieces()) { r.push_back(board_.stackAt(d[i])); } } } return r; }
bool Game::isLegalMove(const Move m) const { if (Board::isValid(m.src) && Board::isValid(m.dst)) { Board::ConstStackHandle srcH = board_.stackAt(m.src); Board::ConstStackHandle dstH = board_.stackAt(m.dst); // Test the src is free return srcH->onTop()->color() == colorOf(theOnePlaying()) && board_.isFree(srcH) && srcH->hasPieces() && dstH->hasPieces() && Board::areAligned(m.src,m.dst) && Board::distance(m.src,m.dst) == srcH->height(); } return false; }