How does the code 'know' to do things?


Although the central place for design discussion is ##crawl-dev on freenode, some may find it helpful to discuss requests and suggestions here first.

Halls Hopper

Posts: 60

Joined: Saturday, 2nd September 2017, 16:41

Post Saturday, 25th May 2019, 14:36

How does the code 'know' to do things?

I didn't know where to post this question as I am not technically asking for advice.

How does this game know what items to give to the player as well as know the precise amount of hurdles the player can handle?

I downloaded all the game's code a couple of months ago, yet looking over it, I didn't understand the method. Is there some sort of deep Maths behind it all? I have played this game so often I actually find my self 99% of the time accurately predicting which unidentified items I have in my inventory and what hurdles I will be running into.

Ziggurat Zagger

Posts: 6454

Joined: Tuesday, 30th October 2012, 19:06

Post Saturday, 25th May 2019, 20:14

Re: How does the code 'know' to do things?

HawkI wrote:I didn't know where to post this question as I am not technically asking for advice.

How does this game know what items to give to the player as well as know the precise amount of hurdles the player can handle?

I downloaded all the game's code a couple of months ago, yet looking over it, I didn't understand the method. Is there some sort of deep Maths behind it all? I have played this game so often I actually find my self 99% of the time accurately predicting which unidentified items I have in my inventory and what hurdles I will be running into.

The game doesn't actually dynamically scale itself to the player. It's got a set scale, the monsters and items have certain odds of being generated on certain ranges of dungeon levels.

The reason you're able to reasonably predict what items you encounter, is that it's fairly likely you'll encounter similar numbers of the same types of items at the same ranges of the dungeon, for example, if your on D:7 and have no scrolls and potions identified, your two biggest stacks are probably identify and remove curse, your biggest potion stack is probably curing. That doesn't happen every time, (and if you actually rely on this in possibly deadly situations, it will occasionally backfire spectacularly in unexpected ways)

Similarly It's pretty likely you'll encounter your first orc priest somewhere between D:2 and D:4, because on average that's when that happens. It's *possible* that you won't see an orc priest at all in the dungeon, but it's highly unlikely. The odds remain the same no matter what your character's level is, and whether they can handle it or not.
Spoiler: show
This high quality signature has been hidden for your protection. To unlock it's secret, send 3 easy payments of $9.99 to me, by way of your nearest theta band or ley line. Complete your transmission by midnight tonight for a special free gift!

For this message the author Siegurt has received thanks:
HawkI

Slime Squisher

Posts: 368

Joined: Thursday, 11th April 2013, 21:07

Post Saturday, 25th May 2019, 20:56

Re: How does the code 'know' to do things?

HawkI wrote:How does this game know what items to give to the player

At level generation, after most floor features have been placed, the code calls _builder_items() to generate items for the floor. This calls items(), requesting an OBJ_RANDOM item a randomized amount of times, using the absolute depth of the floor as the item level. Item level affects generation of each item type differently, but often results in fancier items being generated at deeper depths. You can see here the OBJ_RANDOM weightings for each item type, with Gold being common and Staves exceedingly rare. For each item thus generated, the game will then try to place it somewhere on the level, but it can still delete the item before the floor is finalized if an eligible spot isn't found quickly enough.

HawkI wrote:as well as know the precise amount of hurdles the player can handle?

The game doesn't track this. You can follow the level generation call to _builder_monsters() to see exactly what happens there: It generates a randomized amount of monsters for any given floor, with the hells getting extra monsters and pan/crypt slightly fewer. Dungeon depths for monster generation can be found in mon-pick-data.h, with the caveat that out-of-depth monsters will sometimes be placed. Floor generation also typically has areas placed through vault Lua, where the monsters and items are defined in the vault's .des file.


I should mention that you don't need to know any of this to play the game. You can search the git repository with grep or through github if you're curious and want to learn about the code, but if you just want to play Crawl none of this is important.

For this message the author Implojin has received thanks: 2
HawkI, nago

Halls Hopper

Posts: 60

Joined: Saturday, 2nd September 2017, 16:41

Post Sunday, 26th May 2019, 19:21

Re: How does the code 'know' to do things?

The reason I ask is because the philosophy of this game is 'every time you die you know there's something better you could have done' For each of my lost play through s I do believe this philosophy and I just have no idea how it can be SO consistent. After hearing your responses I am even now more confused, in a good way.

Ziggurat Zagger

Posts: 4432

Joined: Friday, 8th May 2015, 17:51

Post Monday, 27th May 2019, 03:48

Re: How does the code 'know' to do things?

HawkI wrote:The reason I ask is because the philosophy of this game is 'every time you die you know there's something better you could have done' For each of my lost play through s I do believe this philosophy and I just have no idea how it can be SO consistent. After hearing your responses I am even now more confused, in a good way.
While you are inexperienced player your tactics/strategy are far from optimal so "there is something you could have done better" applies even to every won game and when you are very experienced player you just stop losing unless playing very hard combo.
Underestimated: cleaving, Deep Elf, Formicid, Vehumet, EV
Overestimated: AC, GDS
Twin account of Sandman25

Halls Hopper

Posts: 60

Joined: Saturday, 2nd September 2017, 16:41

Post Monday, 27th May 2019, 10:11

Re: How does the code 'know' to do things?

:shock: You live up to your name VeryAngryFelid

Ziggurat Zagger

Posts: 4432

Joined: Friday, 8th May 2015, 17:51

Post Monday, 27th May 2019, 10:41

Re: How does the code 'know' to do things?

HawkI wrote::shock: You live up to your name VeryAngryFelid


Sorry, I didn't mean to offend you. I tried to explain that "every time you die you know there's something better you could have done" has nothing to do with death, it can be replaced with "every time you win or lose you know there's something better you could have done". Unless you are ideal player who always plays ideally, I am not sure if such even exists ;)
Underestimated: cleaving, Deep Elf, Formicid, Vehumet, EV
Overestimated: AC, GDS
Twin account of Sandman25

Abyss Ambulator

Posts: 1131

Joined: Tuesday, 4th January 2011, 15:03

Post Monday, 27th May 2019, 11:00

Re: How does the code 'know' to do things?

While it could be argued that you can always do something better, the interesting question is what is that you could have done better and is *really important*. So there are big differences between improvements: there are always little improvements, but if you die a lot then most likely there are some big improvements for you. Try to find these first!

While it is hard to give advice without looking at specific games, my guess is that it is almost always about bad positioning. Choosing a good position consistently is one of the most important factors in winning.

Blades Runner

Posts: 593

Joined: Tuesday, 11th December 2018, 19:14

Post Tuesday, 28th May 2019, 14:28

Re: How does the code 'know' to do things?

VeryAngryFelid wrote:
HawkI wrote::shock: You live up to your name VeryAngryFelid


Sorry, I didn't mean to offend you. I tried to explain that "every time you die you know there's something better you could have done" has nothing to do with death, it can be replaced with "every time you win or lose you know there's something better you could have done". Unless you are ideal player who always plays ideally, I am not sure if such even exists ;)


It's possible in principle but very unlikely a human will do the > 10,000 choices in a row with incomplete information at the theoretical ideal. Even evaluating what ideal is can be tough in some situations (you have to estimate what gives you the best chances, which is unrealistic for people to do at such granular levels). The game is pretty forgiving compared to "ideal" play, so many optimizations would amount to "win harder", but ideal play still picks the best ones somehow.

If machine learning + computers get good enough and someone bothers with crawl it might be possible to get an AI to near-100% winrate and make its play indistinguishable from "ideal", even if we'd still have no way to verify that.

All that said, there are some mistakes that are much harder on win% than others so while it's helpful to always note that you can play better, paying particular attention to sequences that result in death is still relevant as these tend to be the most impactful mistakes.

Blades Runner

Posts: 616

Joined: Thursday, 25th October 2012, 03:19

Post Thursday, 30th May 2019, 01:36

Re: How does the code 'know' to do things?

TheMeInTeam wrote:
VeryAngryFelid wrote:
HawkI wrote::shock: You live up to your name VeryAngryFelid


Sorry, I didn't mean to offend you. I tried to explain that "every time you die you know there's something better you could have done" has nothing to do with death, it can be replaced with "every time you win or lose you know there's something better you could have done". Unless you are ideal player who always plays ideally, I am not sure if such even exists ;)


It's possible in principle but very unlikely a human will do the > 10,000 choices in a row with incomplete information at the theoretical ideal. Even evaluating what ideal is can be tough in some situations (you have to estimate what gives you the best chances, which is unrealistic for people to do at such granular levels). The game is pretty forgiving compared to "ideal" play, so many optimizations would amount to "win harder", but ideal play still picks the best ones somehow.


^^ someone should notify Yermak
User avatar

Vaults Vanquisher

Posts: 454

Joined: Thursday, 1st November 2018, 02:33

Post Thursday, 30th May 2019, 03:11

Re: How does the code 'know' to do things?

TheMeInTeam wrote:If machine learning + computers get good enough and someone bothers with crawl it might be possible to get an AI to near-100% winrate and make its play indistinguishable from "ideal", even if we'd still have no way to verify that.


In my opinion, crawl bots could be improved a lot by making them do the stupid things people here say are optimal, for example extremely careful manual exploration and luring. The current model for crawl bots, as I understand it, is to win strong combos using naive combat tactics. I haven't looked into this very seriously, but I nevertheless believe it is possible to automate naive luring (in other words hitting some trigger like ` makes you moderately intelligently back away monsters along a reasonably safe route to nearby stairs, breaking line of sight, and so on) and that this would more or less trivialize the game to the point where you can win with three buttons.

A bot that focuses on implementing a few weird tricks like stair dancing, absurd manual exploration/luring/camping, and ally cheez could achieve very high winrates, maybe even with less code than qw. I suspect qw reflects an overly generous reading of how to play crawl. Everyone thinks "optimal" means making genius moves like a computer that beats top chess players, but in fact "optimal" looks like doing really stupid, tedious, and apparently unnecessary things so that you never have to do anything smart.
This is where mechanical excellence and one-thousand four-hundred horsepower pays off.

For this message the author tealizard has received thanks: 2
Implojin, nago

Ziggurat Zagger

Posts: 4432

Joined: Friday, 8th May 2015, 17:51

Post Thursday, 30th May 2019, 05:38

Re: How does the code 'know' to do things?

svendre wrote:^^ someone should notify Yermak
There is another concern. The better player you are the better you are at identifying where your game might be improved so it is practically impossible to be ideal player.
Underestimated: cleaving, Deep Elf, Formicid, Vehumet, EV
Overestimated: AC, GDS
Twin account of Sandman25

Return to Game Design Discussion

Who is online

Users browsing this forum: No registered users and 51 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.