<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>coffeescript &#8211; 天地一沙鸥</title>
	<atom:link href="https://haoluobo.com/tag/coffeescript/feed/" rel="self" type="application/rss+xml" />
	<link>https://haoluobo.com</link>
	<description>to be continue....</description>
	<lastBuildDate>Thu, 16 Dec 2021 03:35:41 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
	<item>
		<title>随机迷宫生成算法</title>
		<link>https://haoluobo.com/2013/01/random-maze-gen/</link>
		
		<dc:creator><![CDATA[vicalloy]]></dc:creator>
		<pubDate>Wed, 30 Jan 2013 03:23:39 +0000</pubDate>
				<category><![CDATA[编程]]></category>
		<category><![CDATA[coffeescript]]></category>
		<category><![CDATA[迷宫]]></category>
		<guid isPermaLink="false">/?p=10927</guid>

					<description><![CDATA[在线迷宫游戏地址： lbmaze@sae项目地址： lbmaze@github最近研究了下迷宫的生成算法，然后 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>在线迷宫游戏地址： <a href="http://lbmaze.sinaapp.com">lbmaze@sae</a><br>项目地址： <a href="https://github.com/vicalloy/lb-maze">lbmaze@github</a><br>最近研究了下迷宫的生成算法，然后做了个简单的在线迷宫游戏。游戏地址和对应的开源项目地址可以通过上面的链接找到。开源项目中没有包含服务端的代码，因为服务端的代码实在太简单了。下面将简单的介绍下随机迷宫的生成算法。一旦理解后你会发现这个算法到底有多简单。</p>



<ul class="wp-block-list"><li>将迷宫地图分成多个房间，每个房间都有四面墙。</li><li>让“人”从地图任意一点A出发，开始在迷宫里游荡。从A房间的1/2/3/4个方向中的任选一个方向前进。在从A房间走到B房间的过程中，推倒A/B房间之间的墙。</li><li>如果方向x对面的房间已经走过，则选择其他方向。如果所有方向的房间都已经走过，则退回上一个房间看是否还有可选道路。</li><li>走到真正无路可走时，说明已经走过了所有房间，迷宫也生成好了。</li></ul>



<p>下面是该算法的python实现（核心部分）</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: python; title: ; notranslate">
def gen_map(self, max_x=10, max_y=10):
    &quot;&quot;&quot; 生成迷宫 &quot;&quot;&quot;
    self.max_x, self.max_y = max_x, max_y  # 设置地图大小
    self.mmap = &#x5B;&#x5B;None for j in range(self.max_y)] for i in range(self.max_x)]  # 生成原始地图
    self.solution = &#x5B;]  # 迷宫解法
    block_stack = &#x5B;Block(self, 0, 0)]  # 从0,0开始生成迷宫（同时将这点作为起点），将起点放到栈里
    while block_stack:
        block = block_stack.pop()  #取出当前所在的房间
        next_block = block.get_next_block()  # 获取下一个要去的房间
        if next_block:  # 如果成功获取下一走发，将走过的房间放回到栈里
            block_stack.append(block)
            block_stack.append(next_block)
            if next_block.x == self.max_x - 1 and next_block.y == self.max_y - 1:  # 走到终点了，栈里的路径就是解法
                for o in block_stack:
                    self.solution.append((o.x, o.y))
def get_next_block_pos(self, direction):
   &quot;&quot;&quot; 获取指定方向的房间号 &quot;&quot;&quot;
    x = self.x
    y = self.y
    if direction == 0:  # Top
        y -= 1
    elif direction == 1:  # Right
        x += 1
    if direction == 2:  # Bottom
        y += 1
    if direction == 3:  # Left
        x -= 1
    return x, y
def get_next_block(self):
    &quot;&quot;&quot; 获取下一要去的房间 &quot;&quot;&quot;
    directions = list(range(4))
    random.shuffle(directions)  # 随机获取一个要去的方向
    for direction in directions:
        x, y = self.get_next_block_pos(direction)
        if x &gt;= self.mmap.max_x or x &lt; 0 or y &gt;= self.mmap.max_y or y &lt; 0:  # 房间号在许可范围内
            continue
        if self.mmap.mmap&#x5B;x]&#x5B;y]:  # 如果已经走过
            continue
        self.walls&#x5B;direction] = False
        return Block(self.mmap, x, y, direction)
    return None  # 没找到有可用的房间
</pre></div>


<p>注： 由于采用该方法生成的迷宫道路的分支数量并不是太多，coffeescript版在生成迷宫的过程中增加了随机处理，对应算法也稍微复杂一点点。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>django的js/css压缩组件Django Compressor</title>
		<link>https://haoluobo.com/2012/06/django-compressor/</link>
					<comments>https://haoluobo.com/2012/06/django-compressor/#comments</comments>
		
		<dc:creator><![CDATA[vicalloy]]></dc:creator>
		<pubDate>Tue, 26 Jun 2012 13:03:44 +0000</pubDate>
				<category><![CDATA[编程]]></category>
		<category><![CDATA[coffeescript]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[Django Compressor]]></category>
		<guid isPermaLink="false">/?p=10564</guid>

					<description><![CDATA[为了加快网站的加载速度，我们通常要多js和css进行压缩处理。这些js和css的压缩工作如果都手动处理，费时费 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>为了加快网站的加载速度，我们通常要多js和css进行压缩处理。这些js和css的压缩工作如果都手动处理，费时费力。<br><a href="http://django_compressor.readthedocs.org/en/latest/index.html">Django Compressor</a> 可以实现js/css的自动压缩。Django Compressor在易用性方面做的非常好，按照 <a href="http://django_compressor.readthedocs.org/en/latest/quickstart/">文档</a> 做简单的设置后就可以正常工作。强烈建议大家去将文档完整的看一遍（文档很短）。<br>使用的时候，只需要将css/js放到 <strong>compress</strong> 标签中 Django Compressor 即可自动进行处理。在debug模式时， Django Compressor 不会对做任何处理。在非debug模式时，Django Compressor会自动对js/css进行压缩，并将压缩后的问题输出到django的 <strong>STATIC_ROOT</strong> 目录。所以请务必保证 <strong>STATIC_ROOT</strong> 目录进行了正确的设置。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
{% load compress %}
{% compress  &#x5B; &#x5B;block_name]] %}

{% endcompress %}
{% compress css %}

{% endcompress %}

</pre></div>


<h3 class="wp-block-heading">coffeescript、less 支持</h3>



<p>在开发阶段coffeescript和less可以直接使用js来处理，在正式发布时处于加载速度的考虑需要预先编译成js和css。 Django Compressor 提供 <strong>COMPRESS_PRECOMPILERS</strong> 设置，根据type类型进行预处理。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: python; title: ; notranslate">
COMPRESS_PRECOMPILERS = (
    (&#039;text/coffeescript&#039;, &#039;coffee --compile --stdio&#039;),
    (&#039;text/less&#039;, &#039;lessc {infile} {outfile}&#039;),
    (&#039;text/x-sass&#039;, &#039;sass {infile} {outfile}&#039;),
    (&#039;text/x-scss&#039;, &#039;sass --scss {infile} {outfile}&#039;),
)
</pre></div>]]></content:encoded>
					
					<wfw:commentRss>https://haoluobo.com/2012/06/django-compressor/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
