示例#1
0
文件: Bishops.cpp 项目: mnuck/chess
BitBoard Bishops::getAttacksFrom(Square square, BitBoard targets,
                                 BitBoard friendlies) {
  BitBoard blockers((targets | friendlies) & _moveMask[square]);
  unsigned int index((blockers * _magicNumber[square]) >> _magicShift[square]);
  BitBoard attacks(*(_magicAttacks[square] + index));
  return attacks & ~friendlies;
}
示例#2
0
		// Checks if any queen attacks another
		bool attacks(int n)
		{
			for(int i = 0; i < n; ++i)
				for(int j = i + 1; j < n; ++j)
					if(attacks(i, j))
						return true;
			return false;
					
		}
示例#3
0
			// Search for a solution using backtracking
		void search(int n)
		{	
			if(n != NSIDE)
			{
				for(int i = 0; i < NSIDE; ++i)
				{
					pos[n] = i;
					if(!attacks(n + 1))
						search(n + 1);
				}
			}
			else
			print();
		}
示例#4
0
/* Function used when someone attacks someone else with an artifact
 * weapon.  Only adds the special (artifact) damage, and returns a 1 if it
 * did something special (in which case the caller won't print the normal
 * hit message).  This should be called once upon every artifact attack;
 * dmgval() no longer takes artifact bonuses into account.  Possible
 * extension: change the killer so that when an orc kills you with
 * Stormbringer it's "killed by Stormbringer" instead of "killed by an orc".
 */
boolean artifact_hit(
    struct monst *magr,
    struct monst *mdef,
    struct obj *otmp,
    int *dmgptr,
    int dieroll /* needed for Magicbane and vorpal blades */
    )
{
	boolean youattack = (magr == &youmonst);
	boolean youdefend = (mdef == &youmonst);
	boolean vis = (!youattack && magr && cansee(magr->mx, magr->my))
	    || (!youdefend && cansee(mdef->mx, mdef->my))
	    || (youattack && u.uswallow && mdef == u.ustuck && !Blind);
	boolean realizes_damage;
	char hittee[BUFSZ];

	strcpy(hittee, youdefend ? "you" : mon_nam(mdef));

	/* The following takes care of most of the damage, but not all--
	 * the exception being for level draining, which is specially
	 * handled.  Messages are done in this function, however.
	 */
	*dmgptr += spec_dbon(otmp, mdef, *dmgptr);

	if (youattack && youdefend) {
	    impossible("attacking yourself with weapon?");
	    return FALSE;
	}

	realizes_damage = (youdefend || vis || 
			   /* feel the effect even if not seen */
			   (youattack && mdef == u.ustuck));

	/* the four basic attacks: fire, cold, shock and missiles */
	if (attacks(AD_FIRE, otmp)) {
	    if (realizes_damage)
		pline("The fiery blade %s %s%c",
			!spec_dbon_applies ? "hits" :
			(mdef->data == &mons[PM_WATER_ELEMENTAL]) ?
			"vaporizes part of" : "burns",
			hittee, !spec_dbon_applies ? '.' : '!');
	    if (!rn2(4)) destroy_mitem(mdef, POTION_CLASS, AD_FIRE);
	    if (!rn2(4)) destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE);
	    if (!rn2(7)) destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE);
	    if (youdefend && Slimed) burn_away_slime();
	    return realizes_damage;
	}
	if (attacks(AD_COLD, otmp)) {
	    if (realizes_damage)
		pline("The ice-cold blade %s %s%c",
			!spec_dbon_applies ? "hits" : "freezes",
			hittee, !spec_dbon_applies ? '.' : '!');
	    if (!rn2(4)) destroy_mitem(mdef, POTION_CLASS, AD_COLD);
	    return realizes_damage;
	}
	if (attacks(AD_ELEC, otmp)) {
	    if (realizes_damage)
		pline("The massive hammer hits%s %s%c",
			  !spec_dbon_applies ? "" : "!  Lightning strikes",
			  hittee, !spec_dbon_applies ? '.' : '!');
	    if (!rn2(5)) destroy_mitem(mdef, RING_CLASS, AD_ELEC);
	    if (!rn2(5)) destroy_mitem(mdef, WAND_CLASS, AD_ELEC);
	    return realizes_damage;
	}
	if (attacks(AD_MAGM, otmp)) {
	    if (realizes_damage)
		pline("The imaginary widget hits%s %s%c",
			  !spec_dbon_applies ? "" :
				"!  A hail of magic missiles strikes",
			  hittee, !spec_dbon_applies ? '.' : '!');
	    return realizes_damage;
	}
	
	if (attacks(AD_STUN, otmp) && dieroll <= MB_MAX_DIEROLL) {
	    /* Magicbane's special attacks (possibly modifies hittee[]) */
	    return magicbane_hit(magr, mdef, otmp, dmgptr, dieroll, vis, hittee);
	}
	
	if (!spec_dbon_applies) {
	    /* since damage bonus didn't apply, nothing more to do;  
	       no further attacks have side-effects on inventory */
	    return FALSE;
	}
	
	/* Tsurugi of Muramasa, Vorpal Blade */
	if (spec_ability(otmp, SPFX_BEHEAD))
		return artifact_hit_behead(magr, mdef, otmp, dmgptr, dieroll);
	
	/* Stormbringer */
	if (spec_ability(otmp, SPFX_DRLI))
		return artifact_hit_drainlife(magr, mdef, otmp, dmgptr);
	
	return FALSE;
}