{"id":301352,"date":"2020-04-06T09:00:34","date_gmt":"2020-04-06T09:00:34","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=301352"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=301352","title":{"rendered":"\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 roguelike \u0432 Unity \u0441 \u043d\u0443\u043b\u044f: \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u043e\u0434\u0437\u0435\u043c\u0435\u043b\u0438\u0439"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/495588\/\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/09d\/9af\/aac\/09d9afaace836ef3bde082e3d63c580a.png\" alt=\"image\"><\/div>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043c\u044b \u043f\u043e\u0433\u0440\u0443\u0437\u0438\u043c\u0441\u044f \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u043e\u0434\u0437\u0435\u043c\u0435\u043b\u0438\u0439. \u0412 <a href=\"https:\/\/habr.com\/ru\/post\/490828\/\">\u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043f\u0435\u0440\u0432\u0443\u044e \u043a\u043e\u043c\u043d\u0430\u0442\u0443, \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043f\u043e\u0434\u0437\u0435\u043c\u0435\u043b\u044c\u044f.<\/p>\n<p>  \u041d\u043e \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043c\u044b \u043d\u0430\u0447\u043d\u0451\u043c, \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u0441\u0442\u0430. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043d\u0435\u0434\u0435\u043b\u0438 \u044f \u043d\u0430\u0443\u0447\u0438\u043b\u0441\u044f \u043a\u043e\u0435-\u0447\u0435\u043c\u0443 \u043d\u043e\u0432\u043e\u043c\u0443, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043d\u043d\u043e\u0439 \u043c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0443\u0441\u0442\u0430\u0440\u0435\u043b\u0430, \u0438 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c.<\/p>\n<p>  \u041f\u043e\u043c\u043d\u0438\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441 Position? \u0412\u043e\u043e\u0431\u0449\u0435-\u0442\u043e \u0432 Unity \u0443\u0436\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0439 \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u0438\u0435 \u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0441 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u2014 \u0435\u0433\u043e \u043f\u0440\u043e\u0449\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c. \u042d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Vector2Int. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u043c\u044b \u0443\u0434\u0430\u043b\u0438\u043c \u0438\u0437 MapManager.cs \u043a\u043b\u0430\u0441\u0441 Position \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u043c \u043a\u0430\u0436\u0434\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e Position \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e Vector2Int.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/656\/b7d\/f40\/656b7df4053976af99cbd2d359edd494.png\"><\/div>\n<p>  \u042d\u0442\u043e \u0436\u0435 \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 DungeonGenerator.cs. \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u042d\u0442\u0430\u043f 7 \u2014 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043a\u043e\u043c\u043d\u0430\u0442\u044b\/\u043a\u043e\u0440\u0438\u0434\u043e\u0440\u0430<\/h2>\n<p>  \u041c\u044b \u043d\u0430\u0447\u043d\u0451\u043c \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0439 \u0432 \u043f\u0440\u043e\u0448\u043b\u044b\u0439 \u0440\u0430\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 FirstRoom(). \u0412\u043c\u0435\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u0430\u0440\u0442\u044b \u0438 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u0443\u0447\u0438 \u043a\u043e\u0434\u0430, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0432 \u0435\u0451 \u0432 \u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u0443\u044e GenerateFeature(). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0438\u043c\u044f \u0441 FirstRoom \u043d\u0430 GenerateFeature.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043e\u043d\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u2014 \u043a\u043e\u043c\u043d\u0430\u0442\u0443 \u0438\u043b\u0438 \u043a\u043e\u0440\u0438\u0434\u043e\u0440. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <em>type<\/em>. \u0414\u0430\u043b\u0435\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0442\u043e \u0435\u0441\u0442\u044c \u0438\u0437 \u043a\u0430\u043a\u043e\u0439 \u0441\u0442\u0435\u043d\u044b \u043e\u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u0438\u0442 (\u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u0441\u0442\u0435\u043d\u044b \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0430\u0440\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430), \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 Wall. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u0430\u044f \u043a\u043e\u043c\u043d\u0430\u0442\u0430 \u0438\u043c\u0435\u0435\u0442 \u043e\u0441\u043e\u0431\u044b\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f bool, \u0441\u043e\u043e\u0431\u0449\u0430\u044e\u0449\u0430\u044f, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u043e\u0439. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043d\u0430 \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 false: bool isFirst = false. \u0418\u0442\u0430\u043a \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043c\u0435\u043d\u0438\u0442\u0441\u044f \u0441 \u044d\u0442\u043e\u0433\u043e:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/e5f\/b79\/d17\/e5fb79d178098b3bcde238ff733f9ca9.png\"><\/div>\n<p>  \u043d\u0430 \u044d\u0442\u043e:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/45e\/124\/afc\/45e124afc4b4f60b12ab18deaa060719.png\"><\/div>\n<p>  \u041e\u0442\u043b\u0438\u0447\u043d\u043e. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0448\u0438\u0440\u0438\u043d\u044b \u0438 \u0432\u044b\u0441\u043e\u0442\u044b \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430. \u041f\u043e\u043a\u0430 \u043c\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0438\u0445, \u043f\u043e\u043b\u0443\u0447\u0430\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 min \u0438 max \u0432\u044b\u0441\u043e\u0442\u044b \u0438 \u0448\u0438\u0440\u0438\u043d\u044b \u043a\u043e\u043c\u043d\u0430\u0442 \u2014 \u0434\u043b\u044f \u043a\u043e\u043c\u043d\u0430\u0442 \u044d\u0442\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e, \u043d\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u043b\u044f \u043a\u043e\u0440\u0438\u0434\u043e\u0440\u043e\u0432. \u0418\u0442\u0430\u043a, \u043f\u043e\u043a\u0430 \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/2f5\/c0d\/976\/2f5c0d9765a596c2d2188b56b1f7b7ff.png\"><\/div>\n<p>  \u041d\u043e \u043a\u043e\u0440\u0438\u0434\u043e\u0440\u044b \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 3 \u0432 \u0448\u0438\u0440\u0438\u043d\u0443 \u0438\u043b\u0438 \u0432\u044b\u0441\u043e\u0442\u0443, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043e\u0440\u0438\u0435\u043d\u0442\u0430\u0446\u0438\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u0447\u0435\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u2014 \u043a\u043e\u043c\u043d\u0430\u0442\u043e\u0439 \u0438\u043b\u0438 \u043a\u043e\u0440\u0438\u0434\u043e\u0440\u043e\u043c, \u0430 \u043f\u043e\u0442\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/071\/163\/df8\/071163df82fc248fc92d370672369743.gif\"><\/div>\n<p>  \u0418\u0442\u0430\u043a. \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u043e\u043c\u043d\u0430\u0442\u043e\u0439. \u0415\u0441\u043b\u0438 \u0434\u0430, \u0442\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u0440\u0430\u043d\u044c\u0448\u0435 <br \/>   \u2014 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0432 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0435 \u043c\u0435\u0436\u0434\u0443 min \u0438 max \u0432\u044b\u0441\u043e\u0442\u044b \u0438 \u0448\u0438\u0440\u0438\u043d\u044b. \u041d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0432 <em>else<\/em> \u0442\u043e\u0433\u043e \u0436\u0435 if \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0447\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u043d\u043e\u0435. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043e\u0440\u0438\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043a\u043e\u0440\u0438\u0434\u043e\u0440\u0430. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u043f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u0442\u0435\u043d\u044b \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u0432 \u043a\u0430\u043a\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043e\u043d\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0451 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0440\u0438\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043a\u043e\u0440\u0438\u0434\u043e\u0440\u0430.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/91a\/a84\/328\/91aa84328140d1414b8512843e1cd397.gif\"><\/div>\n<p>  \u041d\u043e \u043c\u044b \u043f\u043e\u043a\u0430 \u043d\u0435 \u043e\u0431\u044a\u044f\u0432\u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e minCorridorLength. \u041d\u0443\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438 \u043e\u0431\u044a\u044f\u0432\u0438\u0442\u044c \u0435\u0451, \u043f\u0440\u044f\u043c\u043e \u043d\u0430\u0434 maxCorridorLength.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f13\/857\/6e1\/f138576e1dc1cb4a9949fd51e8c5fe47.png\"><\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u043d\u0430\u0448\u0438\u043c \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u043c switch. \u0427\u0442\u043e \u043c\u044b \u0437\u0434\u0435\u0441\u044c \u0434\u0435\u043b\u0430\u0435\u043c: \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <em>\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f<\/em> \u0441\u0442\u0435\u043d\u044b, \u0442\u043e \u0435\u0441\u0442\u044c, \u043a\u0443\u0434\u0430 \u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u0441\u0442\u0435\u043d\u0430, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0434\u0442\u0438 \u043a\u043e\u0440\u0438\u0434\u043e\u0440. \u041d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u0447\u0435\u0442\u044b\u0440\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f: South, North, West \u0438 East. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 South \u0438 North \u043a\u043e\u0440\u0438\u0434\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0448\u0438\u0440\u0438\u043d\u0443 3 (\u0434\u0432\u0435 \u0441\u0442\u0435\u043d\u044b \u0438 \u043f\u043e\u043b \u043f\u043e\u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435) \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0432\u044b\u0441\u043e\u0442\u0443 (\u0434\u043b\u0438\u043d\u0443). \u0414\u043b\u044f West \u0438 East \u0432\u0441\u0451 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442: \u0432\u044b\u0441\u043e\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0440\u0430\u0432\u043d\u0430 3, \u0430 \u0448\u0438\u0440\u0438\u043d\u0430 \u0438\u043c\u0435\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0434\u043b\u0438\u043d\u0443. \u0418\u0442\u0430\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/0e2\/175\/8d6\/0e21758d6d2e17406ce516c3fef6ccf5.gif\"><\/div>\n<p>  \u0417\u0434\u043e\u0440\u043e\u0432\u043e. \u0418 \u043d\u0430 \u044d\u0442\u043e\u043c \u043c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043d\u043e\u0432\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c, \u043a\u0443\u0434\u0430 \u0435\u0433\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c. \u041f\u0435\u0440\u0432\u0443\u044e \u043a\u043e\u043c\u043d\u0430\u0442\u0443 \u043c\u044b \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0438\u043b\u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0446\u0435\u043d\u0442\u0440\u0430 \u043a\u0430\u0440\u0442\u044b.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/6fb\/d53\/010\/6fbd5301066f6b0ba77ab90142370a5d.png\"><\/div>\n<p>  \u041d\u043e \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u044d\u0442\u043e \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c\u0441\u044f \u0440\u044f\u0434\u043e\u043c \u0441\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0441\u0442\u0435\u043d\u044b, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u043a\u043e\u0434. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u043e\u0439. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u043a\u043e\u043c\u043d\u0430\u0442\u0430, \u0442\u043e \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u0440\u0430\u043d\u0435\u0435 \u2014 \u043a\u0430\u043a \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0443 \u0448\u0438\u0440\u0438\u043d\u044b \u0438 \u0432\u044b\u0441\u043e\u0442\u044b \u043a\u0430\u0440\u0442\u044b.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ff3\/d29\/44d\/ff3d2944da973a48200a6c9c3066d20d.gif\"><\/div>\n<p>  \u0412 <em>else<\/em> \u0435\u0441\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u043e\u0439, \u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u043d\u0430 \u0441\u0442\u0435\u043d\u0435, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0438\u043c\u0435\u0435\u0442 \u043b\u0438 \u0441\u0442\u0435\u043d\u0430 \u0440\u0430\u0437\u043c\u0435\u0440 3 (\u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c, \u0447\u0442\u043e \u043e\u043d\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u043a\u043e\u0440\u0438\u0434\u043e\u0440\u0430), \u0438 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0442\u0430\u043a, \u0442\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0441\u0440\u0435\u0434\u043d\u044f\u044f \u0442\u043e\u0447\u043a\u0430, \u0442\u043e \u0435\u0441\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 1 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441\u0442\u0435\u043d\u044b (\u043f\u0440\u0438 3 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0445 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u043c\u0435\u0435\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u044b 0, 1, 2). \u041d\u043e \u0435\u0441\u043b\u0438 \u0440\u0430\u0437\u043c\u0435\u0440 \u043d\u0435 \u0440\u0430\u0432\u0435\u043d 3 (\u0441\u0442\u0435\u043d\u0430 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u043a\u043e\u0440\u0438\u0434\u043e\u0440\u0430), \u0442\u043e \u043c\u044b \u0431\u0435\u0440\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u0432 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0435 \u043c\u0435\u0436\u0434\u0443 \u0442\u043e\u0447\u043a\u043e\u0439 1 \u0438 \u0434\u043b\u0438\u043d\u043e\u0439 \u0441\u0442\u0435\u043d\u044b \u043c\u0438\u043d\u0443\u0441 2. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0445\u043e\u0434\u043e\u0432, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0432 \u0443\u0433\u043b\u0443. \u0422\u043e \u0435\u0441\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430 \u0441\u0442\u0435\u043d\u0435 \u0441 \u0434\u043b\u0438\u043d\u043e\u0439 6 \u043c\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u044b 0 \u0438 5 (\u043f\u0435\u0440\u0432\u044b\u0439 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439), \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u0441\u0440\u0435\u0434\u0438 \u0442\u043e\u0447\u0435\u043a 1, 2, 3 \u0438 4.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ee2\/4e1\/703\/ee24e1703c28b4cfa96e98d84a76c790.gif\"><\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0442\u043e\u0447\u043a\u0438 \u043d\u0430 \u0441\u0442\u0435\u043d\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442. \u041d\u043e \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043e\u0442\u0442\u0443\u0434\u0430, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0430\u043a \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d \u0443\u0436\u0435 \u0440\u0430\u0437\u043c\u0435\u0449\u0451\u043d\u043d\u044b\u043c\u0438 \u0441\u0442\u0435\u043d\u0430\u043c\u0438. \u0422\u0430\u043a\u0436\u0435 \u0432\u0430\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441 \u0435\u0433\u043e \u043b\u0435\u0432\u043e\u0433\u043e \u043d\u0438\u0436\u043d\u0435\u0433\u043e \u0443\u0433\u043b\u0430, \u0430 \u0437\u0430\u0442\u0435\u043c \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0432\u043f\u0440\u0430\u0432\u043e \u0438 \u0432\u0432\u0435\u0440\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u0441\u0442\u0435\u043d\u0430. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u0435\u0440\u0432\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 x \u0438 \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 y \u0431\u0443\u0434\u0443\u0442 \u0441\u0442\u0435\u043d\u0430\u043c\u0438, \u0438 \u0435\u0441\u043b\u0438 \u043d\u0430\u0447\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u0440\u044f\u043c\u043e \u0440\u044f\u0434\u043e\u043c \u0441 \u0442\u043e\u0447\u043a\u043e\u0439 \u043d\u0430 \u0441\u0442\u0435\u043d\u0435, \u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043e\u0440\u0438\u0434\u043e\u0440, \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u0432 \u0443\u0433\u043b\u0443 \u043a\u043e\u043c\u043d\u0430\u0442\u044b, \u0430 \u043d\u0435 \u0432 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u043c \u043c\u0435\u0441\u0442\u0435 \u043d\u0430 \u0441\u0442\u0435\u043d\u0435.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0435\u0441\u043b\u0438 \u0441\u0442\u0435\u043d\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0430 \u0441\u0435\u0432\u0435\u0440, \u0442\u043e \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0430\u0447\u0438\u043d\u0430\u043b\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043d\u0430 \u0441\u0435\u0432\u0435\u0440 \u043f\u043e \u043e\u0441\u0438 y, \u043d\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0439 \u043a \u0437\u0430\u043f\u0430\u0434\u0443 \u043f\u043e \u043e\u0441\u0438 x, \u0432 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0435 \u043e\u0442 1 \u0434\u043e \u0448\u0438\u0440\u0438\u043d\u044b \u043a\u043e\u043c\u043d\u0430\u0442\u044b-2. \u0412 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u044e\u0433\u0430 \u043e\u0441\u044c x \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0430\u043a \u0436\u0435, \u043d\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u043f\u043e \u043e\u0441\u0438 y \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0442\u043e\u0447\u043a\u0438 \u043d\u0430 \u0441\u0442\u0435\u043d\u0435 \u043c\u0438\u043d\u0443\u0441 \u0432\u044b\u0441\u043e\u0442\u0430 \u043a\u043e\u043c\u043d\u0430\u0442\u044b. \u0417\u0430\u043f\u0430\u0434\u043d\u0430\u044f \u0438 \u0432\u043e\u0441\u0442\u043e\u0447\u043d\u0430\u044f \u0441\u0442\u0435\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0442 \u0442\u043e\u0439 \u0436\u0435 \u043b\u043e\u0433\u0438\u043a\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043f\u0435\u0440\u0435\u0432\u0451\u0440\u043d\u0443\u0442\u044b\u043c\u0438 \u043e\u0441\u044f\u043c\u0438.<\/p>\n<p>  \u041d\u043e \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0432\u0441\u0451 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0442\u043e\u0447\u043a\u0438 \u0441\u0442\u0435\u043d\u044b \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e Vector2Int, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u0437\u0436\u0435 \u0435\u044e \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/374\/129\/41a\/37412941a3a58f32fd2dd38c1fc2c252.png\"><\/div>\n<p>  \u0417\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/140\/2c7\/ec0\/1402c7ec0596d77f9a9b70b5eac076a9.gif\"><\/div>\n<p>  \u0418\u0442\u0430\u043a, \u043c\u044b \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0438 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439, \u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u044d\u0442\u0430\u043f\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0430 \u043a\u0430\u0440\u0442\u0435. \u041d\u043e \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c, \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0438 \u043d\u0430 \u043a\u0430\u0440\u0442\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u044d\u0442\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438. \u041f\u043e\u043a\u0430 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u043e\u0432\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e CheckIfHasSpace(). \u041e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u0447\u0451\u0440\u043a\u043d\u0443\u0442\u0430 \u043a\u0440\u0430\u0441\u043d\u044b\u043c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043a\u0430 \u0435\u0451 \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438. \u041c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043c \u0442\u043e, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0434\u0435\u0441\u044c, \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 GenerateFeature(). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u043e\u0431\u0440\u0430\u0449\u0430\u0439\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043d\u0430 \u043a\u0440\u0430\u0441\u043d\u043e\u0435 \u043f\u043e\u0434\u0447\u0451\u0440\u043a\u0438\u0432\u0430\u043d\u0438\u0435, \u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0439\u0442\u0435.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b20\/805\/942\/b2080594237c23cae023cabb20b2d20e.png\"><\/div>\n<p>  \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0441\u0442\u0435\u043d\u044b. \u041f\u043e\u043a\u0430 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0435\u0451 \u0442\u0440\u043e\u0433\u0430\u0442\u044c, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0446\u0438\u043a\u043b\u0435 <em>for<\/em>.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/227\/d7f\/e2b\/227d7fe2bf3c2eef41f423e36b4afc79.png\"><\/div>\n<p>  \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u044f \u0437\u0430\u043c\u0435\u0442\u0438\u043b, \u0447\u0442\u043e \u044d\u0442\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 if-else \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0435\u0432\u0435\u0440\u043d\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u0435\u043d\u044b \u0432 \u043d\u0438\u0445 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u043b\u0438\u043d\u0443 1. \u0422\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u0438\u0431\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043a \u0441\u0435\u0432\u0435\u0440\u043d\u043e\u0439 \u0441\u0442\u0435\u043d\u0435, \u0442\u043e \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0431\u044b\u043b\u0430 \u043d\u0430 \u0443\u0433\u043b\u0443 \u0441 \u0432\u043e\u0441\u0442\u043e\u0447\u043d\u043e\u0439 \u0441\u0442\u0435\u043d\u043e\u0439, \u043e\u043d\u0430 \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0441\u044f \u043a \u0432\u043e\u0441\u0442\u043e\u0447\u043d\u043e\u0439 \u0441\u0442\u0435\u043d\u0435, \u043a\u0430\u043a \u0438 \u0434\u043e\u043b\u0436\u043d\u0430. \u042d\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u043e \u0440\u0430\u0437\u0434\u0440\u0430\u0436\u0430\u044e\u0449\u0438\u0435 \u0431\u0430\u0433\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0445 \u0443\u0441\u0442\u0440\u0430\u043d\u0438\u043c.<\/p>\n<p>  \u0418\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0438\u0445 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e. \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0432\u0441\u0435 <em>else<\/em>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b\u0430 \u0447\u0435\u0440\u0435\u0437 \u0432\u0441\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <em>if<\/em>, \u0430 \u043d\u0435 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u043b\u0430\u0441\u044c \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u0439, \u0435\u0441\u043b\u0438 \u0442\u0430 \u0432\u0435\u0440\u043d\u0443\u043b\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <em>true<\/em>. \u0417\u0430\u0442\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e <em>else<\/em> (\u0442\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435 <em>else if<\/em>) \u043c\u044b \u043c\u0435\u043d\u044f\u0435\u043c \u043d\u0430 <em>if<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0447\u0442\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0443\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u043a\u0430\u043a Wall, \u0438 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0435\u0451 \u043a\u0430\u043a Floor.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/65c\/784\/834\/65c784834461a2d8b05d1d39dd9ee44c.png\"><\/div>\n<p>  \u041f\u043e\u0442\u0440\u044f\u0441\u0430\u044e\u0449\u0435, \u043c\u044b \u043f\u043e\u0447\u0442\u0438 \u0437\u0434\u0435\u0441\u044c \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438. \u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0439 \u043d\u0430 \u043d\u0443\u0436\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u043d\u043e \u043e\u043d \u0442\u0430\u043a\u043e\u0439 \u0436\u0435, \u043a\u0430\u043a \u0438 \u0438\u043c\u0435\u044e\u0449\u0430\u044f\u0441\u044f \u0443 \u043d\u0430\u0441 \u043f\u0435\u0440\u0432\u0430\u044f \u043a\u043e\u043c\u043d\u0430\u0442\u0430: \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0430\u043c\u043a\u043d\u0443\u0442 \u0441\u0442\u0435\u043d\u0430\u043c\u0438. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0438\u0433\u0440\u043e\u043a \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u0432 \u044d\u0442\u043e \u043d\u043e\u0432\u043e\u0435 \u043c\u0435\u0441\u0442\u043e. \u0422\u043e \u0435\u0441\u0442\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u0447\u043a\u0443 \u043d\u0430 \u0441\u0442\u0435\u043d\u0435 (\u043a\u043e\u0442\u043e\u0440\u0430\u044f, \u043a\u0430\u043a \u043c\u044b \u043f\u043e\u043c\u043d\u0438\u043c, \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0442\u0438\u043f\u0430 Vector2Int) \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u043d\u0430 \u0441\u0442\u0435\u043d\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432\u043e Floor. \u041d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u043e\u0439.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/350\/67f\/5ac\/35067f5ac7db26fd304578b8dd53326c.png\"><\/div>\n<p>  \u042d\u0442\u043e\u0442 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u043e\u0439. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u043e\u043d \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0441\u0442\u0435\u043d\u044b \u0432 \u043f\u043e\u043b, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u0441\u0442\u0435\u043d\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u0442\u0430\u0439\u043b \u043d\u043e\u0432\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u043b.<\/p>\n<p>  \u041c\u044b \u0434\u043e\u0441\u0442\u0438\u0433\u043b\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 GenerateFeature(). \u0412 \u043d\u0435\u0439 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/4fe\/165\/626\/4fe165626aca42951f86568a4d6649c7.png\"><\/div>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043a\u043e\u0435-\u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0442\u0438\u043f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0432\u0435\u043d Room. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043a\u0430\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043d\u0443\u0436\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0441\u0442\u0440\u043e\u043a\u0430 type. \u0422\u0430\u043a \u0447\u0442\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u043c \u0437\u0434\u0435\u0441\u044c \u00abRoom\u00bb \u043d\u0430 type.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b57\/d12\/f17\/b57d12f17802ec40e0c609d26803f661.png\"><\/div>\n<p>  \u0425\u043e\u0440\u043e\u0448\u043e. \u0422\u0435\u043f\u0435\u0440\u044c, \u0447\u0442\u043e\u0431\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0433\u0440\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u044e\u0434\u0430 \u043d\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0410 \u0438\u043c\u0435\u043d\u043d\u043e int, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432. \u041f\u043e\u0434\u043d\u0438\u043c\u0435\u043c\u0441\u044f \u043a \u043c\u0435\u0441\u0442\u0443, \u0433\u0434\u0435 \u043c\u044b \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0438 \u043e\u0431\u044a\u044f\u0432\u0438\u043c int \u0441 \u0438\u043c\u0435\u043d\u0435\u043c countFeatures, \u0430 \u0442\u0430\u043a\u0436\u0435 List \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c allFeatures. \u0421\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u043c, \u0430 \u0441\u0447\u0451\u0442\u0447\u0438\u043a int \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/bcb\/ebf\/8dd\/bcbebf8ddbc768864ba70331317cc72c.png\"><\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 GenerateFeature() \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043a\u043e\u043d\u0435\u0446 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a: \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 countFeatures \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a allFeatures.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/5e6\/8a8\/496\/5e68a8496d7047c87650a609acb912cf.png\"><\/div>\n<p>  \u0418\u0442\u0430\u043a, \u043d\u0430\u0448\u0430 GenerateFeature() \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430. \u041f\u043e\u0437\u0436\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043a \u043d\u0435\u0439 \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0443\u0441\u0442\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e CheckIfHasSpace, \u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0434\u043e \u0435\u0451 \u0441\u043e\u0437\u0434\u0430\u0442\u044c. \u0418\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u0438\u043c \u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u0438 \u0437\u0430\u0439\u043c\u0451\u043c\u0441\u044f.<\/p>\n<h2>\u042d\u0442\u0430\u043f 8 \u2014 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0435\u0441\u0442\u044c \u043b\u0438 \u043c\u0435\u0441\u0442\u043e<\/h2>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 GenerateFeature(). \u0415\u0439 \u043d\u0443\u0436\u043d\u044b \u0434\u0432\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430: \u043f\u043e\u0437\u0438\u0446\u0438\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0438 \u043f\u043e\u0437\u0438\u0446\u0438\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u043d \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 Vector2Int. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 bool, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 <em>if<\/em> \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u043c\u0435\u0441\u0442\u0430.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/998\/f03\/cad\/998f03cad9a6bd8a05bd7d8b9658bad6.png\"><\/div>\n<p>  \u041e\u043d\u0430 \u043f\u043e\u0434\u0447\u0451\u0440\u043a\u043d\u0443\u0442\u0430 \u043a\u0440\u0430\u0441\u043d\u044b\u043c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u043e\u043a\u0430 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442. \u0421\u043a\u043e\u0440\u043e \u043c\u044b \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043c, \u0430 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f. \u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0446\u0438\u043a\u043b\u0435 \u0432\u0441\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u0438 \u043a\u043e\u043d\u0446\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u0440\u0430\u0432\u043d\u0430 \u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0432 MapManager.map \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e null \u0438\u043b\u0438 \u0442\u0430\u043c \u0443\u0436\u0435 \u0447\u0442\u043e-\u0442\u043e \u0435\u0441\u0442\u044c. \u0415\u0441\u043b\u0438 \u0442\u0430\u043c \u0447\u0442\u043e-\u0442\u043e \u0435\u0441\u0442\u044c, \u0442\u043e \u043c\u044b \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0430\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c false. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c. \u0415\u0441\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043e\u0445\u043e\u0434\u0438\u0442 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0446\u0438\u043a\u043b\u0430, \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0432 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0445 \u043c\u0435\u0441\u0442, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c true.<\/p>\n<p>  \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u0435\u0440\u0435\u0434 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u043d\u0430 null \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043b\u0438 \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043a\u0430\u0440\u0442\u044b. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438 \u0441\u0431\u043e\u0439 \u0438\u0433\u0440\u044b.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/473\/582\/a5b\/473582a5b560d6738de08b2f6190cf6b.png\"><\/div>\n<p>  \u041e\u0442\u043b\u0438\u0447\u043d\u043e. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u0442\u043e\u043c\u0443 \u043c\u0435\u0441\u0442\u0443, \u0433\u0434\u0435 \u043c\u044b \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432\u043d\u0443\u0442\u0440\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 GenerateFeature(). \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0432\u044b\u0437\u043e\u0432, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u043d\u0443\u0436\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <em>if<\/em> \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430. \u0415\u0441\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0432\u0435\u043d false, \u0442\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u043c\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043d\u0435 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u044f \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432 MapManager.map.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/068\/661\/e53\/068661e533ef21536a51f17ae3de570b.png\"><\/div>\n<p>  \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 Vector2Int. \u0421 \u043f\u0435\u0440\u0432\u043e\u0439 \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e, \u044d\u0442\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0441 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u043c\u0438 x \u0438 y \u0442\u043e\u0447\u043a\u0438 \u043d\u0430\u0447\u0430\u043b\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/0c1\/869\/26d\/0c186926d741d2423c791500adbed2cd.png\"><\/div>\n<p>  \u0421\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0432\u0441\u0451 \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u043d\u043e \u043d\u0435 \u043d\u0430\u043c\u043d\u043e\u0433\u043e. \u042d\u0442\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u043f\u043b\u044e\u0441 \u0432\u044b\u0441\u043e\u0442\u0430 \u0434\u043b\u044f y \u0438 \u0448\u0438\u0440\u0438\u043d\u0430 \u0434\u043b\u044f x, \u0441 \u0432\u044b\u0447\u0438\u0442\u0430\u043d\u0438\u0435\u043c \u0438\u0437 \u043e\u0431\u043e\u0438\u0445 1 (\u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0430\u0447\u0430\u043b\u043e \u0443\u0436\u0435 \u0443\u0447\u0442\u0435\u043d\u043e).<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/a18\/f85\/4a9\/a18f854a9e0a0bbe5883012bf2e313ff.png\"><\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u044d\u0442\u0430\u043f\u0443 \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 GenerateFeature().<\/p>\n<h2>\u042d\u0442\u0430\u043f 9 \u2014 \u0432\u044b\u0437\u043e\u0432 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432<\/h2>\n<p>  \u0412\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 GenerateDungeon(), \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0439 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438. \u0421\u0435\u0439\u0447\u0430\u0441 \u043e\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/3e9\/57c\/5e3\/3e957c5e316f5329e935353e961df47b.png\"><\/div>\n<p>  \u0412\u044b\u0437\u043e\u0432 FirstRoom() \u043f\u043e\u0434\u0447\u0451\u0440\u043a\u043d\u0443\u0442 \u043a\u0440\u0430\u0441\u043d\u044b\u043c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438 \u0438\u043c\u044f \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u043e\u0432\u0435\u043c \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u044b.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/8d6\/926\/908\/8d692690826997750f3bc860ae9216f0.png\"><\/div>\n<p>  \u041c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b: \u00abRoom\u00bb \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 type, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u043a\u043e\u043c\u043d\u0430\u0442\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 Room, new Wall(), \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u043a\u043e\u043c\u043d\u0430\u0442\u0430 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u043d\u0438 \u0438\u0437 \u043a\u0430\u043a\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 null, \u0438 \u044d\u0442\u043e \u0432\u043f\u043e\u043b\u043d\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e. \u0412\u043c\u0435\u0441\u0442\u043e new Wall() \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c <em>null<\/em>, \u044d\u0442\u043e \u0432\u043e\u043f\u0440\u043e\u0441 \u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u0439. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u0435\u0440\u0432\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u043e\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c <em>true<\/em>.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u043c \u043a \u0433\u043b\u0430\u0432\u043d\u043e\u043c\u0443. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0446\u0438\u043a\u043b for, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f 500 \u0440\u0430\u0437 \u2014 \u0434\u0430, \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b 500 \u0440\u0430\u0437. \u041d\u043e \u0435\u0441\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 (\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f countFeatures) \u0440\u0430\u0432\u043d\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 (\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f maxFeatures), \u0442\u043e \u043c\u044b \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u0435\u043c \u044d\u0442\u043e\u0442 \u0446\u0438\u043a\u043b.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/9e6\/410\/ded\/9e6410ded47210776fcda40ae2492229.png\"><\/div>\n<p>  \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u0432 \u044d\u0442\u043e\u043c \u0446\u0438\u043a\u043b\u0435 \u043c\u044b \u043e\u0431\u044a\u044f\u0432\u0438\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442. \u0415\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0441\u043e\u0437\u0434\u0430\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442 (\u043f\u0435\u0440\u0432\u0430\u044f \u043a\u043e\u043c\u043d\u0430\u0442\u0430), \u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043e\u0434\u0438\u043d \u0438\u0437 \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ddb\/e84\/f92\/ddbe84f92cbb06f56e3ccce561dde991.png\"><\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0432\u044b\u0431\u0435\u0440\u0435\u043c, \u043a\u0430\u043a\u0430\u044f \u0441\u0442\u0435\u043d\u0430 \u044d\u0442\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/7ad\/e7c\/0e4\/7ade7c0e438985098eed6f5dbdd42e6d.png\"><\/div>\n<p>  \u0423\u0447\u0442\u0438\u0442\u0435, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043f\u043e\u043a\u0430 \u043d\u0435\u0442 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 ChoseWall(). \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0431\u044b\u0441\u0442\u0440\u0435\u043d\u044c\u043a\u043e \u0435\u0451 \u043d\u0430\u043f\u0438\u0448\u0435\u043c. \u0421\u043f\u0443\u0441\u0442\u0438\u043c\u0441\u044f \u0432\u043d\u0438\u0437, \u043a \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0435\u0451. \u041e\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0441\u0442\u0435\u043d\u0443, \u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0447\u0442\u043e\u0431\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043c\u043e\u0433\u043b\u0430 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0441\u0442\u0435\u043d\u0443 \u044d\u0442\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/aeb\/631\/9f1\/aeb6319f1ee6f601474d0aa0e32e2c77.png\"><\/div>\n<p>  \u042f \u0441\u043e\u0437\u0434\u0430\u043b \u0435\u0451 \u043c\u0435\u0436\u0434\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 CheckIfHasSpace() \u0438 DrawMap(). \u0423\u0447\u0442\u0438\u0442\u0435, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435 \u0432 Visual Studio, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 Unity, \u0442\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044f -\/+ \u0441\u043b\u0435\u0432\u0430 \u0434\u043b\u044f \u0441\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f\/\u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u0435\u0439 \u043a\u043e\u0434\u0430, \u0447\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443.<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0441\u0442\u0435\u043d\u0443, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442. \u0418\u043d\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c\u0441\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043a \u043e\u0434\u043d\u043e\u0439 \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0441\u0442\u0435\u043d\u0430\u043c \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u0436\u0435 \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u044b \u0434\u0440\u0443\u0433\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043d\u043e\u0432\u0430 \u0438 \u0441\u043d\u043e\u0432\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0430 \u043b\u0438 \u043a\u0430\u043a\u0430\u044f-\u043d\u0438\u0431\u0443\u0434\u044c \u0438\u0437 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0441\u0442\u0435\u043d. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0446\u0438\u043a\u043b for, \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u043c\u044b\u0439 \u0434\u0435\u0441\u044f\u0442\u044c \u0440\u0430\u0437 \u2014 \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u0438\u0445 \u0434\u0435\u0441\u044f\u0442\u0438 \u0440\u0430\u0437 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0430\u044f \u0441\u0442\u0435\u043d\u0430 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u0430, \u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 null.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b10\/44a\/028\/b1044a028bf9ab566a0120690311396d.png\"><\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 GenerateDungeon() \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043a\u0430\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 ChoseWall().<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/0a3\/281\/8aa\/0a32818aafc77ddd87f1ffac21b6981e.png\"><\/div>\n<p>  \u0421\u0442\u0440\u043e\u043a\u0430 <code>if (wall == null) continue;<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0441\u0442\u0435\u043d\u044b \u0432\u0435\u0440\u043d\u0443\u043b\u0430 false, \u0442\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0440\u043e\u0434\u0438\u0442\u044c \u0438\u0437 \u0441\u0435\u0431\u044f \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 (<em>continue<\/em>) \u0446\u0438\u043a\u043b, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0435 \u043e\u043d\u0430 \u043d\u0435 \u0441\u043c\u043e\u0433\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0446\u0438\u043a\u043b\u0430.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0442\u0438\u043f \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430. \u0415\u0441\u043b\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043d\u0430\u0442\u043e\u0439, \u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043a\u043e\u0440\u0438\u0434\u043e\u0440\u043e\u043c (\u043c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043c\u043d\u0430\u0442\u0430 \u043f\u0440\u044f\u043c\u0438\u043a\u043e\u043c \u0432\u0435\u043b\u0430 \u0432 \u0434\u0440\u0443\u0433\u0443\u044e \u043a\u043e\u043c\u043d\u0430\u0442\u0443 \u0431\u0435\u0437 \u043a\u043e\u0440\u0438\u0434\u043e\u0440\u0430 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438). \u041d\u043e \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043a\u043e\u0440\u0438\u0434\u043e\u0440, \u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0431\u0443\u0434\u0435\u0442 \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043a\u043e\u0440\u0438\u0434\u043e\u0440 \u0438\u043b\u0438 \u043a\u043e\u043c\u043d\u0430\u0442\u0430.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b22\/df0\/954\/b22df0954bbe21d82506d42e5118a70f.png\"><\/div>\n<p>  \u041e\u0442\u043b\u0438\u0447\u043d\u043e. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e GenerateFeature(), \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0435\u0439 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0441\u0442\u0435\u043d\u0443 \u0438 \u0442\u0438\u043f.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/a07\/90b\/834\/a0790b83479f46dc17c57fbb981aef81.png\"><\/div>\n<p>  \u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u2014 \u043f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u0432 \u0438\u043d\u0441\u043f\u0435\u043a\u0442\u043e\u0440 Unity, \u0432\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 GameManager \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/9cc\/09c\/786\/9cc09c786641bf85a89674cc33042ebf.png\"><\/div>\n<p>  \u0415\u0441\u043b\u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0436\u0430\u0442\u044c \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 play, \u0442\u043e \u0432\u044b \u0443\u0436\u0435 \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b!<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/09d\/9af\/aac\/09d9afaace836ef3bde082e3d63c580a.png\"><\/div>\n<p>  \u041a\u0430\u043a \u044f \u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u043b, \u044d\u0442\u043e \u043d\u0435 \u0441\u0430\u043c\u043e\u0435 \u043b\u0443\u0447\u0448\u0435\u0435 \u043f\u043e\u0434\u0437\u0435\u043c\u0435\u043b\u044c\u0435. \u0423 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043c\u043d\u043e\u0433\u043e \u0442\u0443\u043f\u0438\u043a\u043e\u0432. \u041d\u043e \u043e\u043d\u043e \u0432\u043f\u043e\u043b\u043d\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e, \u0438 \u043e\u043d\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043c\u043d\u0430\u0442\u044b, \u043d\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0451\u043d\u043d\u043e\u0439 \u043d\u0438 \u0441 \u043a\u0430\u043a\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439.<\/p>\n<p>  \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u0430\u043c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u043e\u0441\u044c! \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u043e\u0441\u0442\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438\u0433\u0440\u043e\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u043f\u043e\u0434\u0437\u0435\u043c\u0435\u043b\u044c\u044e, \u0430 \u043f\u043e\u0442\u043e\u043c \u043c\u044b \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u043c \u043a\u0430\u0440\u0442\u0443 \u0438\u0437 ASCII \u0432 \u0441\u043f\u0440\u0430\u0439\u0442\u043e\u0432\u0443\u044e.<\/p>\n<pre><code class=\"cs\">using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;  public class Post3 : MonoBehaviour {     public int mapWidth;     public int mapHeight;      public int widthMinRoom;     public int widthMaxRoom;     public int heightMinRoom;     public int heightMaxRoom;      public int minCorridorLength;     public int maxCorridorLength;     public int maxFeatures;     int countFeatures;      public bool isASCII;      public List&lt;Feature&gt; allFeatures;      public void InitializeDungeon() {         MapManager.map = new Tile[mapWidth, mapHeight];     }      public void GenerateDungeon() {         GenerateFeature(&quot;Room&quot;, new Wall(), true);          for (int i = 0; i &lt; 500; i++) {             Feature originFeature;              if (allFeatures.Count == 1) {                 originFeature = allFeatures[0];             }             else {                 originFeature = allFeatures[Random.Range(0, allFeatures.Count - 1)];             }              Wall wall = ChoseWall(originFeature);             if (wall == null) continue;              string type;              if (originFeature.type == &quot;Room&quot;) {                 type = &quot;Corridor&quot;;             }             else {                 if (Random.Range(0, 100) &lt; 90) {                     type = &quot;Room&quot;;                 }                 else {                     type = &quot;Corridor&quot;;                 }             }              GenerateFeature(type, wall);              if (countFeatures &gt;= maxFeatures) break;         }          DrawMap(isASCII);     }      void GenerateFeature(string type, Wall wall, bool isFirst = false) {         Feature room = new Feature();         room.positions = new List&lt;Vector2Int&gt;();          int roomWidth = 0;         int roomHeight = 0;          if (type == &quot;Room&quot;) {             roomWidth = Random.Range(widthMinRoom, widthMaxRoom);             roomHeight = Random.Range(heightMinRoom, heightMaxRoom);         }         else {             switch (wall.direction) {                 case &quot;South&quot;:                     roomWidth = 3;                     roomHeight = Random.Range(minCorridorLength, maxCorridorLength);                     break;                 case &quot;North&quot;:                     roomWidth = 3;                     roomHeight = Random.Range(minCorridorLength, maxCorridorLength);                     break;                 case &quot;West&quot;:                     roomWidth = Random.Range(minCorridorLength, maxCorridorLength);                     roomHeight = 3;                     break;                 case &quot;East&quot;:                     roomWidth = Random.Range(minCorridorLength, maxCorridorLength);                     roomHeight = 3;                     break;              }         }          int xStartingPoint;         int yStartingPoint;          if (isFirst) {             xStartingPoint = mapWidth \/ 2;             yStartingPoint = mapHeight \/ 2;         }         else {             int id;             if (wall.positions.Count == 3) id = 1;             else id = Random.Range(1, wall.positions.Count - 2);              xStartingPoint = wall.positions[id].x;             yStartingPoint = wall.positions[id].y;         }          Vector2Int lastWallPosition = new Vector2Int(xStartingPoint, yStartingPoint);          if (isFirst) {             xStartingPoint -= Random.Range(1, roomWidth);             yStartingPoint -= Random.Range(1, roomHeight);         }         else {             switch (wall.direction) {                 case &quot;South&quot;:                     if (type == &quot;Room&quot;) xStartingPoint -= Random.Range(1, roomWidth - 2);                     else xStartingPoint--;                     yStartingPoint -= Random.Range(1, roomHeight - 2);                     break;                 case &quot;North&quot;:                     if (type == &quot;Room&quot;) xStartingPoint -= Random.Range(1, roomWidth - 2);                     else xStartingPoint--;                     yStartingPoint ++;                     break;                 case &quot;West&quot;:                     xStartingPoint -= roomWidth;                     if (type == &quot;Room&quot;) yStartingPoint -= Random.Range(1, roomHeight - 2);                     else yStartingPoint--;                     break;                 case &quot;East&quot;:                     xStartingPoint++;                     if (type == &quot;Room&quot;) yStartingPoint -= Random.Range(1, roomHeight - 2);                     else yStartingPoint--;                     break;             }         }           if (!CheckIfHasSpace(new Vector2Int(xStartingPoint, yStartingPoint), new Vector2Int(xStartingPoint + roomWidth - 1, yStartingPoint + roomHeight - 1))) {             return;         }          room.walls = new Wall[4];          for (int i = 0; i &lt; room.walls.Length; i++) {             room.walls[i] = new Wall();             room.walls[i].positions = new List&lt;Vector2Int&gt;();             room.walls[i].length = 0;              switch (i) {                 case 0:                     room.walls[i].direction = &quot;South&quot;;                     break;                 case 1:                     room.walls[i].direction = &quot;North&quot;;                     break;                 case 2:                     room.walls[i].direction = &quot;West&quot;;                     break;                 case 3:                     room.walls[i].direction = &quot;East&quot;;                     break;             }         }          for (int y = 0; y &lt; roomHeight; y++) {             for (int x = 0; x &lt; roomWidth; x++) {                 Vector2Int position = new Vector2Int();                 position.x = xStartingPoint + x;                 position.y = yStartingPoint + y;                  room.positions.Add(position);                  MapManager.map[position.x, position.y] = new Tile();                 MapManager.map[position.x, position.y].xPosition = position.x;                 MapManager.map[position.x, position.y].yPosition = position.y;                  if (y == 0) {                     room.walls[0].positions.Add(position);                     room.walls[0].length++;                     MapManager.map[position.x, position.y].type = &quot;Wall&quot;;                 }                 if (y == (roomHeight - 1)) {                     room.walls[1].positions.Add(position);                     room.walls[1].length++;                     MapManager.map[position.x, position.y].type = &quot;Wall&quot;;                 }                 if (x == 0) {                     room.walls[2].positions.Add(position);                     room.walls[2].length++;                     MapManager.map[position.x, position.y].type = &quot;Wall&quot;;                 }                 if (x == (roomWidth - 1)) {                     room.walls[3].positions.Add(position);                     room.walls[3].length++;                     MapManager.map[position.x, position.y].type = &quot;Wall&quot;;                 }                 if (MapManager.map[position.x, position.y].type != &quot;Wall&quot;) {                     MapManager.map[position.x, position.y].type = &quot;Floor&quot;;                 }             }         }          if (!isFirst) {             MapManager.map[lastWallPosition.x, lastWallPosition.y].type = &quot;Floor&quot;;             switch (wall.direction) {                 case &quot;South&quot;:                     MapManager.map[lastWallPosition.x, lastWallPosition.y - 1].type = &quot;Floor&quot;;                     break;                 case &quot;North&quot;:                     MapManager.map[lastWallPosition.x, lastWallPosition.y + 1].type = &quot;Floor&quot;;                     break;                 case &quot;West&quot;:                     MapManager.map[lastWallPosition.x - 1, lastWallPosition.y].type = &quot;Floor&quot;;                     break;                 case &quot;East&quot;:                     MapManager.map[lastWallPosition.x + 1, lastWallPosition.y].type = &quot;Floor&quot;;                     break;             }         }          room.width = roomWidth;         room.height = roomHeight;         room.type = type;         allFeatures.Add(room);         countFeatures++;     }      bool CheckIfHasSpace(Vector2Int start, Vector2Int end) {         for (int y = start.y; y &lt;= end.y; y++) {             for (int x = start.x; x &lt;= end.x; x++) {                 if (x &lt; 0 || y &lt; 0 || x &gt;= mapWidth || y &gt;= mapHeight) return false;                 if (MapManager.map != null) return false;             }         }          return true;     }      Wall ChoseWall(Feature feature) {         for (int i = 0; i &lt; 10; i++) {             int id = Random.Range(0, 100) \/ 25;             if (!feature.walls[id].hasFeature) {                 return feature.walls[id];             }         }         return null;     }      void DrawMap(bool isASCII) {         if (isASCII) {             Text screen = GameObject.Find(&quot;ASCIITest&quot;).GetComponent&lt;Text&gt;();              string asciiMap = &quot;&quot;;              for (int y = (mapHeight - 1); y &gt;= 0; y--) {                 for (int x = 0; x &lt; mapWidth; x++) {                     if (MapManager.map[x, y] != null) {                         switch (MapManager.map[x, y].type) {                             case &quot;Wall&quot;:                                 asciiMap += &quot;#&quot;;                                 break;                             case &quot;Floor&quot;:                                 asciiMap += &quot;.&quot;;                                 break;                         }                     }                     else {                         asciiMap += &quot; &quot;;                     }                      if (x == (mapWidth - 1)) {                         asciiMap += &quot;\\n&quot;;                     }                 }             }              screen.text = asciiMap;         }     } }<\/code><\/pre>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/495588\/\"> https:\/\/habr.com\/ru\/post\/495588\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/495588\/\">\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/09d\/9af\/aac\/09d9afaace836ef3bde082e3d63c580a.png\" alt=\"image\"><\/div>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043c\u044b \u043f\u043e\u0433\u0440\u0443\u0437\u0438\u043c\u0441\u044f \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u043e\u0434\u0437\u0435\u043c\u0435\u043b\u0438\u0439. \u0412 <a href=\"https:\/\/habr.com\/ru\/post\/490828\/\">\u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043f\u0435\u0440\u0432\u0443\u044e \u043a\u043e\u043c\u043d\u0430\u0442\u0443, \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043f\u043e\u0434\u0437\u0435\u043c\u0435\u043b\u044c\u044f.<\/p>\n<p>  \u041d\u043e \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043c\u044b \u043d\u0430\u0447\u043d\u0451\u043c, \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u0441\u0442\u0430. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043d\u0435\u0434\u0435\u043b\u0438 \u044f \u043d\u0430\u0443\u0447\u0438\u043b\u0441\u044f \u043a\u043e\u0435-\u0447\u0435\u043c\u0443 \u043d\u043e\u0432\u043e\u043c\u0443, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043d\u043d\u043e\u0439 \u043c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0443\u0441\u0442\u0430\u0440\u0435\u043b\u0430, \u0438 \u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c.<\/p>\n<p>  \u041f\u043e\u043c\u043d\u0438\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441 Position? \u0412\u043e\u043e\u0431\u0449\u0435-\u0442\u043e \u0432 Unity \u0443\u0436\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0439 \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u0438\u0435 \u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0441 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u2014 \u0435\u0433\u043e \u043f\u0440\u043e\u0449\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c. \u042d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Vector2Int. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u043c\u044b \u0443\u0434\u0430\u043b\u0438\u043c \u0438\u0437 MapManager.cs \u043a\u043b\u0430\u0441\u0441 Position \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u043c \u043a\u0430\u0436\u0434\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e Position \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e Vector2Int.<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/656\/b7d\/f40\/656b7df4053976af99cbd2d359edd494.png\"><\/div>\n<p>  \u042d\u0442\u043e \u0436\u0435 \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 DungeonGenerator.cs. \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-301352","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/301352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=301352"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/301352\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=301352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=301352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=301352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}