怪物AI研究
nethack吧
全部回复
仅看楼主
level 14
itfrombit 楼主
一楼防透
2017年09月26日 03点09分 1
level 14
itfrombit 楼主
其实很早以前就有这个想法,一直没有实施。鉴于问题本身的复杂性,进展可能很慢。
2017年09月26日 03点09分 2
level 14
itfrombit 楼主
不建议新手浏览此贴,可能会降低游戏乐趣。
以下研究基于安卓汉化版源代码,不过结论应该是通用的。
2017年09月26日 03点09分 3
四楼被吞了[怒]
2017年09月26日 03点09分
level 14
itfrombit 楼主
struct monst {
struct monst *nmon;
struct permonst *data;
unsigned m_id;
short mnum; /* permanent monster index number */
short cham; /* if shapeshifter, orig mons[] idx goes here */
short movement; /* movement points (derived from permonst definition and
added effects */
uchar m_lev; /* adjusted difficulty level of monster */
aligntyp malign; /* alignment of this monster, relative to the
player (positive = good to kill) */
xchar mx, my;
xchar mux, muy; /* where the monster thinks you are */
#define MTSZ 4
coord mtrack[MTSZ]; /* monster track */
int mhp, mhpmax;
unsigned mappearance; /* for undetected mimics and the wiz */
uchar m_ap_type; /* what mappearance is describing: */
#define M_AP_NOTHING \
0 /* mappearance is unused -- monster appears \
as itself */
#define M_AP_FURNITURE 1 /* stairs, a door, an altar, etc. */
#define M_AP_OBJECT 2 /* an object */
#define M_AP_MONSTER 3 /* a monster */
schar mtame; /* level of tameness, implies peaceful */
unsigned short mintrinsics; /* low 8 correspond to mresists */
int mspec_used; /* monster's special ability attack timeout */
Bitfield(female, 1); /* is female */
Bitfield(minvis, 1); /* currently invisible */
Bitfield(invis_blkd, 1); /* invisibility blocked */
Bitfield(perminvis, 1); /* intrinsic minvis value */
Bitfield(mcan, 1); /* has been cancelled */
Bitfield(mburied, 1); /* has been buried */
Bitfield(mundetected, 1); /* not seen in present hiding place */
/* implies one of M1_CONCEAL or M1_HIDE,
* but not mimic (that is, snake, spider,
* trapper, piercer, eel)
*/
2017年09月26日 03点09分 5
level 14
[惊哭][惊哭][惊哭][惊哭]
2017年09月26日 03点09分 6
这个贴我也吓到[喷]
2017年09月26日 04点09分
@小鱼儿行者 [喷]大神就是大神
2017年09月26日 05点09分
level 14
itfrombit 楼主
Bitfield(mcansee, 1); /* cansee 1, temp.blinded 0, blind 0 */
Bitfield(mspeed, 2); /* current speed */
Bitfield(permspeed, 2); /* intrinsic mspeed value */
Bitfield(mrevived, 1); /* has been revived from the dead */
Bitfield(mcloned, 1); /* has been cloned from another */
Bitfield(mavenge, 1); /* did something to deserve retaliation */
Bitfield(mflee, 1); /* fleeing */
Bitfield(mfleetim, 7); /* timeout for mflee */
Bitfield(msleeping, 1); /* asleep until woken */
Bitfield(mblinded, 7); /* cansee 0, temp.blinded n, blind 0 */
Bitfield(mstun, 1); /* stunned (off balance) */
Bitfield(mfrozen, 7);
Bitfield(mcanmove, 1); /* paralysis, similar to mblinded */
Bitfield(mconf, 1); /* confused */
Bitfield(mpeaceful, 1); /* does not attack unprovoked */
Bitfield(mtrapped, 1); /* trapped in a pit, web or bear trap */
Bitfield(mleashed, 1); /* monster is on a leash */
Bitfield(isshk, 1); /* is shopkeeper */
Bitfield(isminion, 1); /* is a minion */
Bitfield(isgd, 1); /* is guard */
Bitfield(ispriest, 1); /* is a priest */
Bitfield(iswiz, 1); /* is the Wizard of Yendor */
Bitfield(wormno, 5); /* at most 31 worms on any level */
/* 2 free bits */
#define MAX_NUM_WORMS 32 /* should be 2^(wormno bitfield size) */
unsigned long mstrategy; /* for monsters with mflag3: current strategy */
#ifdef NHSTDC
#define STRAT_APPEARMSG 0x80000000UL
#else
#define STRAT_APPEARMSG 0x80000000L
#endif
#define STRAT_ARRIVE 0x40000000L /* just arrived on current level */
#define STRAT_WAITFORU 0x20000000L
#define STRAT_CLOSE 0x10000000L
#define STRAT_WAITMASK (STRAT_CLOSE | STRAT_WAITFORU)
#define STRAT_HEAL 0x08000000L
#define STRAT_GROUND 0x04000000L
#define STRAT_MONSTR 0x02000000L
#define STRAT_PLAYER 0x01000000L
#define STRAT_NONE 0x00000000L
#define STRAT_STRATMASK 0x0f000000L
#define STRAT_XMASK 0x00ff0000L
#define STRAT_YMASK 0x0000ff00L
2017年09月26日 03点09分 7
level 14
itfrombit 楼主
#define STRAT_GOAL 0x000000ffL
#define STRAT_GOALX(s) ((xchar)((s & STRAT_XMASK) >> 16))
#define STRAT_GOALY(s) ((xchar)((s & STRAT_YMASK) >> 8))
long mtrapseen; /* bitmap of traps we've been trapped in */
long mlstmv; /* for catching up with lost time */
long mspare1;
struct obj *minvent;
struct obj *mw;
long misc_worn_check;
xchar weapon_check;
int meating; /* monster is eating timeout */
struct mextra *mextra; /* point to mextra struct */
};
#define newmonst() (struct monst *) alloc(sizeof(struct monst))
/* these are in mspeed */
#define MSLOW 1 /* slow monster */
#define MFAST 2 /* speeded monster */
#define MON_WEP(mon) ((mon)->mw)
#define MON_NOWEP(mon) ((mon)->mw = (struct obj *) 0)
#define DEADMONSTER(mon) ((mon)->mhp < 1)
#define is_starting_pet(mon) ((mon)->m_id == context.startingpet_mid)
#define is_vampshifter(mon) \
((mon)->cham == PM_VAMPIRE || (mon)->cham == PM_VAMPIRE_LORD \
|| (mon)->cham == PM_VLAD_THE_IMPALER)
#define is_door_mappear(mon) ((mon)->m_ap_type == M_AP_FURNITURE \
&& ((mon)->mappearance == S_hcdoor || (mon)->mappearance == S_vcdoor))
#define is_obj_mappear(mon,otyp) ((mon)->m_ap_type == M_AP_OBJECT \
&& (mon)->mappearance == (otyp))
#endif /* MONST_H */
2017年09月26日 03点09分 8
level 14
itfrombit 楼主
以上是monst.h,四楼被吞了,不过没什么重要内容。可以看出monst结构体中绝大部分都是怪物的当前状态,似乎只有mtrack涉及到怪物的“记忆”(?)
2017年09月26日 03点09分 10
英语的东西容易被吞。
2017年09月26日 05点09分
@姑射冰尘 似乎是因为wenjian一词[小乖]
2017年09月26日 05点09分
level 14
itfrombit 楼主
do {
monscanmove = movemon();
if (youmonst.movement >= NORMAL_SPEED)
break; /* it's now your turn */
} while (monscanmove);
这是allmain.c中怪物行动部分,调用movemon函数直到玩家有足够行动点数或没有怪物可以行动。
2017年09月26日 04点09分 11
level 14
itfrombit 楼主
找到mon.c中的movemon函数:
int
movemon()
{
register struct monst *mtmp, *nmtmp;
register boolean somebody_can_move = FALSE;
/*
* Some of you may remember the former assertion here that
* because of deaths and other actions, a simple one-pass
* algorithm wasn't possible for movemon. Deaths are no longer
* removed to the separate list fdmon; they are simply left in
* the chain with hit points <= 0, to be cleaned up at the end
* of the pass.
*
* The only other actions which cause monsters to be removed from
* the chain are level migrations and losedogs(). I believe losedogs()
* is a cleanup routine not associated with monster movements, and
* monsters can only affect level migrations on themselves, not others
* (hence the fetching of nmon before moving the monster). Currently,
* monsters can jump into traps, read cursed scrolls of teleportation,
* and drink cursed potions of raise level to change levels. These are
* all reflexive at this point. Should one monster be able to level
* teleport another, this scheme would have problems.
*/
2017年09月26日 04点09分 12
level 14
itfrombit 楼主
for (mtmp = fmon; mtmp; mtmp = nmtmp) {
/* end monster movement early if hero is flagged to leave the level */
if (u.utotype
#ifdef SAFERHANGUP
/* or if the program has lost contact with the user */
|| program_state.done_hup
#endif
) {
somebody_can_move = FALSE;
break;
}
nmtmp = mtmp->nmon;
遍历本层所有怪物,如果玩家将要离开这一层,跳出循环,怪物不会行动。
2017年09月26日 04点09分 13
level 14
itfrombit 楼主
/* one dead monster needs to perform a move after death:
vault guard whose temporary corridor is still on the map */
if (mtmp->isgd && !mtmp->mx && mtmp->mhp <= 0)
(void) gd_move(mtmp);
if (DEADMONSTER(mtmp))
continue;
跳过已死怪物,除了金库守卫。
2017年09月26日 04点09分 14
level 14
itfrombit 楼主
/* Find a monster that we have not treated yet. */
if (mtmp->movement < NORMAL_SPEED)
continue;
跳过行动点数不足的怪物
2017年09月26日 04点09分 15
level 14
itfrombit 楼主
mtmp->movement -= NORMAL_SPEED;
if (mtmp->movement >= NORMAL_SPEED)
somebody_can_move = TRUE;
怪物行动,扣除12行动点数。
2017年09月26日 04点09分 16
level 14
itfrombit 楼主
if (vision_full_recalc)
vision_recalc(0); /* vision! */
如果有vision_full_recalc标记,重新计算视野。
2017年09月26日 05点09分 17
1 2 3 4 5 6 尾页