<?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>Josep Valls &#187; Python</title>
	<atom:link href="http://josep.valls.name/wordpress/categories/codi/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://josep.valls.name/wordpress</link>
	<description>Software and information engineering from a personal point of view</description>
	<lastBuildDate>Wed, 04 Aug 2010 12:03:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Floyd–Warshall</title>
		<link>http://josep.valls.name/wordpress/floyd%e2%80%93warshall/</link>
		<comments>http://josep.valls.name/wordpress/floyd%e2%80%93warshall/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 00:48:53 +0000</pubDate>
		<dc:creator>Josep Valls</dc:creator>
				<category><![CDATA[Mates]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://josep.valls.name/wordpress/?p=410</guid>
		<description><![CDATA[It was 2am and I had an exercice where I had to do a Floyd–Warshall algorithm over a graph to get the maximum cost among the minimum paths. The numbers on the paper began to blur and I found it way easier to copy the pseudocode from Wikipedia and translate into Python than to actually [...]]]></description>
			<content:encoded><![CDATA[<p>It was 2am and I had an exercice where I had to do a Floyd–Warshall algorithm over a graph to get the maximum cost among the minimum paths. The numbers on the paper began to blur and I found it way easier to copy the pseudocode from Wikipedia and translate into Python than to actually do it. Am I awesome? Is there something wrong with me?</p>
<p>Here you are.</p>
<pre>#n = num of vertices
n = 7
#this is my little aproximation to infinity... didn't want to get into the docs
m = 1e1000
#this is the matrix that describes de graph
path = [[0,4,3,m,m,m,m],[4,0,4,6,m,6,m],[3,4,0,6,m,m,m],[m,6,6,0,4,4,6],[m,m,m,4,0,6,10],[m,6,m,4,6,0,2],[m,m,m,6,10,2,0]]
for k in xrange(n):
	for i in xrange(n):
		for j in xrange(n):
			path[i][j] = min ( path[i][j], path[i][k]+path[k][j] )
			print path</pre>
]]></content:encoded>
			<wfw:commentRss>http://josep.valls.name/wordpress/floyd%e2%80%93warshall/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>El laberint del Minotaure</title>
		<link>http://josep.valls.name/wordpress/el-laberinto-del-minotauro/</link>
		<comments>http://josep.valls.name/wordpress/el-laberinto-del-minotauro/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 14:02:32 +0000</pubDate>
		<dc:creator>Josep Valls</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://josep.valls.name/wordpress/el-laberinto-del-minotauro/</guid>
		<description><![CDATA[El laberint del Minotaure en Python.



Requieres Python 2.6 with TK.
For windows you can just grab the default python installation packages and do a full install. Then doubleclick the game py file.
To write bots to play in the game:
class AI0(AI):
	def __init__(self):
		self.name = "Bot Sample code"
		self.lastgoal = 10000
		self.option = 0
		self.options = [1,3,2,4]
		self.optionsrev = [2,4,1,3]
	def move(self,options,sensors):
		if sensors[1] &#60; [...]]]></description>
			<content:encoded><![CDATA[<p>El laberint del Minotaure en Python.<br />
<a href="http://josep.valls.name/wordpress/wp-content/uploads/2010/02/minotaure.png"></a></p>
<p style="text-align: center;"><a href="http://josep.valls.name/wordpress/wp-content/uploads/2010/02/minotaure.png"><img class="size-medium wp-image-388 aligncenter" title="Minotaure" src="http://josep.valls.name/wordpress/wp-content/uploads/2010/02/minotaure-300x198.png" alt="Minotaure" width="300" height="198" /></a></p>
<p><span id="more-389"></span></p>
<p>Requieres Python 2.6 with TK.</p>
<p>For windows you can just grab the default python installation packages and do a full install. Then doubleclick the game py file.</p>
<pre>To write bots to play in the game:
class AI0(AI):
	def __init__(self):
		self.name = "Bot Sample code"
		self.lastgoal = 10000
		self.option = 0
		self.options = [1,3,2,4]
		self.optionsrev = [2,4,1,3]
	def move(self,options,sensors):
		if sensors[1] &lt; self.lastgoal:
			while 1:
				m = self.options[self.option % 4]
				if m in options: break
				self.option = self.option + 1
		else:
			m = self.optionsrev[self.option % 4]
			self.option = self.option + 1
		self.lastgoal = sensors[1]
		return m

To create a new game:
g1 = Grid(260,Point(20,20),8)
p.drawtiles(g1)
x = GameController(g1,1,0,0)
while 1:
	p.canvas.delete("player")
	p.canvas.delete("goal")
	x.update()
	p.canvas.update()
	p.canvas.after(10)</pre>
<p>I&#8217;ll be glad in you sent me your bots!</p>
<p>Download:</p>
<p><a href="http://josep.valls.name/wordpress/wp-content/uploads/2010/02/bot_ai.py.txt">bot_ai.py</a></p>
<p><a href="http://josep.valls.name/wordpress/wp-content/uploads/2010/02/bot_game3.py.txt">bot_game3.py</a></p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">class AI8(AI):<br />
def __init__(self):<br />
self.name = &#8220;Midas2&#8243;<br />
self.lastgoal = 10000<br />
self.option = 0<br />
self.options = [1,3,2,4]<br />
self.optionsrev = [2,4,1,3]<br />
def move(self,options,sensors):<br />
if sensors[1] &lt; self.lastgoal:<br />
while 1:<br />
m = self.options[self.option % 4]<br />
if m in options: break<br />
self.option = self.option + 1<br />
else:<br />
m = self.optionsrev[self.option % 4]<br />
self.option = self.option + 1<br />
self.lastgoal = sensors[1]<br />
return m</div>
]]></content:encoded>
			<wfw:commentRss>http://josep.valls.name/wordpress/el-laberinto-del-minotauro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
