Beispiel #1
0
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;
}
void
Drawer::drawStatus(const Board::ConstStackHandle& s,QGLViewer* v) const
{
  startTexture();
  glPushMatrix();
  translateTo(s.stackCoord(),s->height()*pieceH+pieceH/2.0f);
  glColor3f(1.0f,1.0f,0.0f);
  v->renderText(0.5f*caseD,0.5f*caseD,0.0f,QString("%1").arg(s.stackStatus()));
  glPopMatrix();
  endTexture();
}
void
Drawer::drawTransparentPiece(Color col,
			     const Board::ConstStackHandle& c,float a) const
{
  startTexture();
  glPushMatrix();
  translateTo(c.stackCoord(),c->height()*pieceH);
  glTranslatef(0.5f*caseD,0.5f*caseD,0.0f);
  drawPiece(col,a);
  glPopMatrix();
  endTexture();
}
void
Drawer::drawPieces(const Board::ConstStackHandle& s) const
{
  startTexture();
  glPushMatrix();
  translateTo(s.stackCoord());
  glTranslatef(0.5f*caseD,0.5f*caseD,0.0f);
  for (Stack::const_iterator
	 iter = s->begin(),
	 istop= s->end();
       iter != istop;++iter)
  {
    drawPiece((*iter)->color());
    glTranslatef(0.0f,0.0f,pieceH);
  }
  glPopMatrix();
  endTexture();
}
void
Drawer::highlight(const Board::ConstStackHandle& c) const
{
  glPushAttrib(GL_ENABLE_BIT);
  glDisable(GL_LIGHTING);
  startTexture();
  glPushMatrix();
  translateTo(c.stackCoord(),0.05f*pieceH+pieceH/2.0f);
  glScalef(caseD,caseD,pieceH);
  // glutWireCube(1.0f);
  glPopMatrix();
  endTexture();
  glPopAttrib();
}
void
Drawer::draw(const Board::ConstStackHandle& c) const
{
  glPushMatrix();
  translateTo(c.stackCoord());
  startTexture("case.png");
  glColor3fv(boardColor);
  glNormal3fv(boardUpVector());
  glBegin(GL_QUADS);
  tessAndTexture(0.0f ,0.0f,caseD,caseD);
  glEnd();
  endTexture();
  glPopMatrix();
}
void
Drawer::highlightPieces(const Board::ConstStackHandle& c) const
{
  glPushAttrib(GL_ENABLE_BIT);
  glDisable(GL_LIGHTING);
  startTexture();
  glPushMatrix();
  translateTo(c.stackCoord(),0.01f);
  glTranslatef(0.5f*caseD,0.5f*caseD,0.0f);
  glColor4f(0.0f,0.0f,0.3f,0.3f);
  drawHRing(pieceRMin, 1.2f*pieceRMax, 0.0f);
  glPopMatrix();
  endTexture();
  glPopAttrib();
}
Beispiel #8
0
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;
}
void
Drawer::drawMove(const Board& b,const Game::Move m,float t) const
{
  const float L = caseD*estimateDrawMoveLength(b,m);
  const float t0 = (b.heightMax()+1-b.stackAt(m.src)->height())*pieceH/L;
  const float t1 = 1.0f-(b.heightMax()+1-b.stackAt(m.dst)->height())*pieceH/L;
  Board::ConstStackHandle src = b.stackAt(m.src);
  glPushMatrix();
  startTexture();
  if (t<=t0)
  {
    t /= t0;
    float srcH = src->height()*pieceH;
    float dstH = b.heightMax()*pieceH+pieceH;
    translateTo(m.src);
    glTranslatef(0.5f*caseD,0.5f*caseD,
		 (1-t)*srcH+t*dstH);
    for (Stack::const_iterator
	   iter = src->begin(),
	   istop= src->end();
	 iter != istop;++iter)
    {
      drawPiece((*iter)->color());
      glTranslatef(0.0f,0.0f,pieceH);
    }
  }
  else if (t<=t1)
  {
    t = (t-t0)/(t1-t0);
    static const float shifts[5] = { 1.0f,0.5f,0.0f,-0.5f,-1.0f };
    float srcX = boardB+vLabelW+m.src.x()*caseD+shifts[m.src.y()]*caseD;
    float srcY = boardB+hLabelH+m.src.y()*caseD;
    float dstX = boardB+vLabelW+m.dst.x()*caseD+shifts[m.dst.y()]*caseD;
    float dstY = boardB+hLabelH+m.dst.y()*caseD;
    glTranslatef((1.0f-t)*srcX+t*dstX+0.5f*caseD,
		 (1.0f-t)*srcY+t*dstY+0.5f*caseD,
		 b.heightMax()*pieceH+pieceH);
    for (Stack::const_iterator
	   iter = src->begin(),
	   istop= src->end();
	 iter != istop;++iter)
    {
      drawPiece((*iter)->color());
      glTranslatef(0.0f,0.0f,pieceH);
    }
  }
  else
  {
    t = (t-t1)/(1.0f-t1);
    float srcH = b.heightMax()*pieceH+pieceH;
    float dstH = b.stackAt(m.dst)->height()*pieceH;
    translateTo(m.dst);
    glTranslatef(0.5f*caseD,0.5f*caseD,
		 (1-t)*srcH+t*dstH);
    for (Stack::const_iterator
	   iter = src->begin(),
	   istop= src->end();
	 iter != istop;++iter)
    {
      drawPiece((*iter)->color());
      glTranslatef(0.0f,0.0f,pieceH);
    }
  }
  endTexture();
  glPopMatrix();

}