The mind flayer, h, and master mind flayer, h, are especially perilous monsters in NetHack. They are depicted with a humanoid body, an octopus-like head, and four tentacles around a lamprey-like mouth. Mind flayers possess flight and telepathy, as well as both see invisible and infravision. Mind flayers are capable of using the same weapons, armor and wands as the player, and are always generated hostile. They share a colored glyph with the dwarf king, h.
Mind flayers can use their tentacles to eat your brain, decreasing your intelligence; this may result in developing amnesia and, in the worst cases, perishing as your last thoughts fade away from fatal intelligence drain. You can sense the presence of mind flayers remotely via "a faint wave of psychic energy"; if you have telepathy, they can sense yours. Occasionally, they will concentrate and release a blast of psychic energy—if they are hostile or under the effects of conflict, and can either see you or sense you via telepathy, it will "lock on" to your mind or telepathy for d15 damage (which is halved with half spell damage). If they are peaceful and not under the effects of conflict, it will "feel quite soothing" and no harm will be done.
Mind flayers are notorious for generating upon entering some floors of the Gnomish Mines, where they are normally far too high difficulty to appear. This is because the Mines levels specify that one random h monster should be generated at normal level creation; this is almost always a dwarf, hobbit, or bugbear. On occasion, however, the function that chooses which h monster should be generated totally ignores the difficulty of the monster it produces; flayers that generate like this are sometimes called minesflayers.
Mind flayers and master mind flayers are considered a consistent, high-level threat throughout the entirety of the game. Brainlessness is an instadeath that ignores not only your current HP, but lifesaving as well—you will be brought back, only to immediately die again since your brain is still gone. If you die from intelligence drain while polymorphed, you will permanently die instead of reverting to your normal form.
Polymorphing into a headless monster will protect you from the special attacks, mitigating the worst of their threat and leaving the matter of reducing the damage from each 'flay', along with the psychic blasts. Being polymorphed into a normally mindless form won't protect you; a comment in the relevant code says this is because players aren't mindless.
Detection and combat
If you are outside of Gehennom and start sensing waves of psychic energy, that is your cue to farlook and check whether any h you see is a dwarf—a common YASD is to mistake the mind flayer for an easy kill, then march in and have your brain promptly eaten, especially if you are burdened and/or have low intelligence. Keep in mind that you will not see the psychic wave message every turn.
When fighting mind flayers, avoid melee if at all possible and remain at a distance. Their high monster magic resistance will often stop all but the most powerful spells (e.g. finger of death), and cancellation will not affect their brainsucking attacks even if it successfully hits; this leaves projectiles such as daggers or arrows as your best bet to deal damage. Alternately, if your ranged attack options are limited and melee is your only out, consider stoning them or taking other measures to prevent or minimize stat loss (discussed further below); beware the master mind flayer's base AC of 0!
Mind flayers respect Elbereth if encountered outside of Gehennom, and can be deterred by standing on a scroll of scare monster; however, this does not prevent them locking on to your mind or telepathy. You can also scare them using methods such as an expensive camera or tooled horn— while not as secure as Elbereth and possibly subject to their high monster MR, these methods can also scare away other monsters that would not respect Elbereth. Beware that a fleeing mind flayer may still attack you, although it is much less likely to; additionally, a blinded one will not respect Elbereth.
Preventing intelligence drain
Wearing any greased helm prevents the mind flayer's tentacles from reaching your brain, but the grease has a 1⁄2 chance to wear off with each attack; a non-greased helm has a 7⁄8 chance of preventing each of the mind flayer's tentacle attacks. Mind flayers get multiple attacks per turn, so you should not rely solely on a greased helm, especially if you are unable to kill them quickly.
You may alternately want to wear a dunce cap or ring of sustain ability; both items will fix your intelligence stat (either at 6 or its current value), preventing stat loss and thus brainlessness, on top of the dunce cap's chance to block the tentacles. However, none of these methods will prevent amnesia from a successful brainsucking, and you're likely to come out of the fight very forgetful—have a means of re-identifying items on hand if possible. You can use #name to label one of a particular type of item(s) that you consider vital and/or does not auto-identify as a precaution; having an ideally blessed unicorn horn can also reverse the stat loss fairly quickly.
The amnesia and instadeath from brain-eating are enough to make both forms of mind flayer a popular target for blessed genocide—but do not do this if you are a dwarf! Using a blessed scroll of genocide will remove all h from the current game - dwarves included - and serves as a particularly aggravating YASD for forgetful dwarven players; those unable to use blessed genocide for this reason should instead use two different uncursed scrolls of genocide. If doing this, or else genociding from a throne, the master mind flayer should ideally be targeted first; regular mind flayers cannot be generated via summon nasties unless they randomly replace an extinct/genocided nasty.
Do not use scrolls of genocide with unidentified beatitude - that one scroll you just found and read without checking may be cursed, and the summoned horde of mind flayers will often result in a quick death; even if you can scare them away, their psychic blasts may still overwhelm you. Also, be sure to mind your spelling, especially if you are a monk - misspelling it as "master mindfalyer" will only parse the word "Master", one of the Monk's rank titles, and wipe out all monks.
While highly desirable as pets, taming a mind flayer is extremely hard and dangerous due to their monster magic resistance; you may be much better off using a polymorph trap on your current pet. Tame mind flayers make quick work of shopkeepers, and their telepathic outreach only locks onto hostile monsters, otherwise printing a harmless message (which can be hidden with MSGTYPE). However, remember that only peaceful mind flayers will produces soothing waves - if you see different messages related to psychic waves and are taking damage from them, a hostile mind flayer may be on the level.
Be especially careful if your tame mind flayer becomes confused—they will turn those psychic waves on you! The same danger is present if you have a means to instigate conflict; however, with their high monster magic resistance, once a mind flayer reaches level 15 it will become immune (and no longer a threat to you or your brain matter) during conflict.
Jellies are a serious threat to mind flayers, whose multiple tentacle attacks can and likely will trigger several passive attacks that can run up enough damage to easily kill them. Shapeshifters and green slimes are similarly dangerous: the former may go down quickly, but will polymorph the mind flayer when its corpse is eaten, while the latter is extremely likely to turn it into another slime. Ochre jellies are a common sight in the late game, especially as a summonable nasty—consider giving your mind flayer any yellow dragon scales (or dragon scale mail) that you happen upon to provide them with valuable acid resistance.
Mind flayers also have a tendency to attract covetous monsters with their psychic blasts. If you are approaching, for example, the Wizard of Yendor's Tower, and you do not wish to leave them on another floor temporarily, be prepared to deal with your prematurely awakened foes and the host of problems that may follow.
As a polyform
The master mind flayer is a very sought-after polyform: on top of flight, multiple attacks per turn, a base AC of 0 and no changes to armor or encumbrance, its brain-eating attack is deadly to nearly anything. Non-mindless monsters take an additional d10 points of damage per brainsucking attack to simulate brain loss; additionally, you will gain d30 nutrition per suck message without risk of choking, and if your intelligence score is below the maximum (i.e. your own brain was sucked), it will be increased by d4. The intelligence increase is subject to the normal polymorphed attributes rules, and will be reset when you revert to your normal form; your max HP may also drop significantly in this form, especially if polymorphing at a high level.
Naturally, players in mind flayer form face the same dangers as pet mind flayers, including potential death from triggering too many passive attacks. Furthermore, brainsucking a green slime causes delayed sliming, and eating a cockatrice's brain causes both immediate stoning and delayed stoning if the immediate stoning was life-saved. Sucking the brains of your race or other mind flayers will count as cannibalism as well; for Monks and vegan or vegetarians players, eating brains will also break those conducts. While you cannot choke directly from eating brains, you will not receive a warning when oversatiated, and thus run a significant risk of choking from eating anything afterward.
In NetHack 3.4.3 and previous versions, the game would not recognize the alternate spelling "mindflayer" when selecting a monster for genocide. A Monk that attempted to genocide "master mindflayer" would instead genocide "master", thus wiping out all Monks and ending the game. This is because "master" is one of the rank titles for Monks, and NetHack ignores the extra word "mindflayer". Both NetHack 3.6.0 and SLASH'EM recognize the "mindflayer" spelling, so it is okay to genocide "master mindflayer" in those games, but a typo like "master mindfalyer" can still wipe out all Monks and end the game.
Mind flayers are slightly different in SLASH'EM. First, the master mind flayer has three brain-eating attacks, while the normal mind flayer has five—an unusual reverse of the situation in vanilla NetHack. More importantly, though, the ring of free action provides luck-based protection against their brain-eating attacks, starting at a 50% of blocking each individual flay and increasing to a 90% chance at maxed-out luck. This, in combination with a greased helm, renders them much less of a threat.
Also, SLASH'EM introduces more sources of amnesia (such as potions of amnesia and migo queen attacks), making a preventative genocide of mind flayers much less of a surefire protection against amnesia.
Lastly, if you polymorph into an intelligent monster in SLASH'EM, generally you need not worry about petrifying monsters. This is true of mind flayers—instead of eating the cockatrice's brain and being stoned, you will instead simply not use your tentacle attack against it at all. Your weapon attack will still go forward, though, and it is still possible to get stoned by other methods (e.g. attacking it bare-handed).
Mind flayers first appear in Dungeons & Dragons as Illithids; D&D's creator, Gary Gygax, was reportedly inspired to create the monster after seeing cover art for a book by Brian Lumley.
This creature has a humanoid body, tentacles around its
covered mouth, and three long fingers on each hand. Mind
flayers are telepathic, and love to devour intelligent beings,
especially humans. If they hit their victim with a tentacle,
the mind flayer will slowly drain it of all intelligence,
eventually killing its victim.