PyCon 2014

Técnicas para crear con Python mazamorras aleatorias para videojuegos

James King  · 

Presentación

Vídeo

Transcripción

Extracto de la transcripción automática del vídeo realizada por YouTube.

do you want any help with QA or can you handle it oh wait well i was i was hoping to it actually sorry I'm getting talked to it I was hoping to stay dark from gloomy in here because james king is going to be talking to us about dungeon generation techniques

for roguelikes in python so let's give a big round of applause all right thank you first I'd like to thank the pike on organizers for putting on such a great event it's my third year running coming to the event and it's just been really well

it's been bigger and better every year and also like to thank the volunteers for making it run smoothly a bit about me I've been a Python programmer since about two thousand six professionally but some of my earlier experiences go back all the way

to about 2000 for my day job is mostly about development operations web applications distributed systems and storage things like that but at night I run a weekly DD group every Sunday and I like to design dungeons i also have poured my heart and soul in a

thousands of hours of roguelikes who here is played any sort of roguelike games good crowd so also you know like rogue nethack Moria angband and one of my personal favorites dungeon crawl stone soup and in order to become a better player eventually maybe if

you're also a programmer you start digging into the source code and figuring how it's making the levels where it's placing enemies and things like that so today's talk is primarily about designing procedurally generated content for games I

say designing because when people think maybe random generated levels they did they don't think of like carefully crafted gameplay experiences and they don't think they think maybe like it's just going to look the same after a while it's always

going to be aqua here but in my adventures in exploring the roguelike space and Roebuck development I've come across some neat ideas that I think are cool anyway that I hope you share with you today so the first step baby step is how do we represent a

dungeon in a computer and for our purposes today we're just talking about roguelikes which are two-dimensional top down so tiles and I think grid paper you might think of good old D&D tiles one common way of representing them in Python is these little

nested iterators to construct a list of lists this is sort of a very naive way of approaching it and we get our list of lists and then when you use two indices to index into our dungeon and look at the different tiles that are there one approach that i like

is packing everything to a multi-dimensional array into a single list sort how C lays out it's a raise in memory and let you treat a multi-dimensional array as a single a two array so you get just a list of numbers and you can index into it as if it was

a multi-dimensional array by using something called row major ordinary which looks kind of like this and if you can imagine each row of the grid being laid out one after the other in a straight linear array that's basically what this index will let you

get into each part by giving it an X into y I which is what I do as the library I wrote a while ago to get help me out right some demos and things like that called Horton it gives you a little grid object and then you could just index into the grid using a

familiar X wipe sort of pattern in the thing so first steps with random level generation or mazes I think it's a good start for anybody who's interested in getting into this topic the reason being that they're very very easy to lint that there

are lots of them and it's you can get resulted very very quickly under the screen the first kind here is an example of a depth-first search like a backtracking depth-first search algorithm what you do is you just start off at a random point somewhere in

your grid and you start searching as far as you can until you hit an end and then you backtrack and start going as deep as you can again that's sort of where it gets its name so you can see like there's a little bit of helper code in the background

that I haven't explained here just for this is just where it's the core of the algorithm there so you start off with a staff and a current cell that you choose randomly from your starting grid the cells by the way are the elements inside your array

there I just make them like little dictionaries with little objects that have four walls I guess and basically we're going to tunnel through each cell as weak as we come across so we start off with a full stack and while they're still elements in the

stack we just get the N visited neighbors for our current cell if there are some great we take a random choice from those neighbors we removable all between the current cell and that that random neighbor that we selected so on and so forth and we just appended

the current cell to the stack and choosing you one so and so forth what it can end up happening is that you'll get to the place where there are no new neighbors in that case that's where we start popping things off the stack and backtracking a bit

until it again without getting into too much details the proof or anything like that this album is guaranteed to touch every single cell in your grid and then you end up with a maze like this was long windy twisty corridors a different example just contrast

the different methods available is called prims algorithm the Wikipedia definition is kind of dense but it forms it says it says it forms like a minimum spanning tree of connected undirected weighted graph and it finds all the subset of edges that connect

[ ... ]

Nota: se han omitido las otras 2.837 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.