Ejemplo n.º 1
0
  switch (dirs) {
  case DIR_NORTHEAST: return DIR_EAST;
  case DIR_SOUTHEAST: return DIR_SOUTH;
  case DIR_NORTHWEST: return DIR_NORTH;
  case DIR_SOUTHWEST: return DIR_WEST;
  default: return dirs;
  }
}

/** Returns the available directions for a corner */
static gint 
find_tip_directions(Point prev, Point this, Point next)
{
  gint startdirs = find_slope_directions(prev, this);
  gint enddirs = find_slope_directions(this, next);
  gint firstdir = first_direction(startdirs);
  gint lastdir = last_direction(enddirs);
  gint dir, dirs = 0;

  dir = firstdir;
  while (dir != lastdir) {
    dirs |= dir;
    dir = dir * 2;
    if (dir == 16) dir = 1;
  }
  dirs |= dir;

  return dirs;
}

void
Ejemplo n.º 2
0
int
SqAttacked(short square, short side, short *blockable)
{
#ifdef SAVE_NEXTPOS
    short d;
#else
    unsigned char *ppos, *pdir;
#endif

    short u, ptyp;

    if (MatchSignature(threats_signature[side]))
    {
        *blockable = true; /* don't know */
        return Anyattack(side, square);
    }

    /*
     * First check neighbouring squares,
     * then check Knights.
     * then check Bishops,
     * then (last) check Rooks,
     */

    *blockable = false;

    /* try a capture from direct neighboured squares */

    ptyp = ptype[black][king];

#ifdef SAVE_NEXTPOS
    u = first_direction(ptyp, &d, square);
#else
    pdir = (*nextdir[ptyp])[square];
    u = pdir[square];
#endif

    do
    {
        if (color[u] == side) /* can piece reach square in one step ? */
#ifdef CHECK_DISTANCE
        {
            if (piece_distance(side, board[u], u, square) == 1)
                return true;
        }
#else
        {
            short v;
            short ptypv = ptype[side][board[u]];
#ifdef SAVE_NEXTPOS
            short dv;
            v = first_direction(ptypv, &dv, u);
#else
            unsigned char *qdir;
            qdir = (*nextdir[ptypv])[u];
            v = qdir[u];
#endif
            do
            {
                if (v == square)
                    return true;
#ifdef SAVE_NEXTPOS
                v = next_direction(ptypv, &dv, u);
#else
                v = qdir[v];
#endif
            }
            while (v != u);
        }
#endif

#ifdef SAVE_NEXTPOS
        u = next_direction(ptyp, &d, square);
#else
        u = pdir[u];
#endif
    }
    while (u != square);

    /* try a knight capture (using xside's knight moves) */

    ptyp = ptype[side ^ 1][knight];

#ifdef SAVE_NEXTPOS
    u = first_direction(ptyp, &d, square);
#else
    pdir = (*nextdir[ptyp])[square];
    u = pdir[square];
#endif

    do
    {
        if (color[u] == side && board[u] == knight)
            return true;

#ifdef SAVE_NEXTPOS
        u = next_direction(ptyp, &d, square);
#else
        u = pdir[u];
#endif
    }
    while (u != square);

    *blockable = true;

    /* try a (promoted) bishop capture */

    ptyp = ptype[black][bishop];

#ifdef SAVE_NEXTPOS
    u = first_direction(ptyp, &d, square);
#else
    ppos = (*nextpos[ptyp])[square];
    pdir = (*nextdir[ptyp])[square];
    u = ppos[square];
#endif

    do
    {
        if (color[u] == neutral)
#ifdef SAVE_NEXTPOS
            u = next_position(ptyp, &d, square, u);
#else
        u = ppos[u];
#endif
        else
        {
            if (color[u] == side && (unpromoted[board[u]] == bishop))
                return true;

#ifdef SAVE_NEXTPOS
            u = next_direction(ptyp, &d, square);
#else
            u = pdir[u];
#endif
        }
    }