<?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>blog.nanomuelle.com</title>
	<atom:link href="http://blog.nanomuelle.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nanomuelle.com</link>
	<description>nanomuelle</description>
	<lastBuildDate>Sat, 10 Mar 2012 01:20:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Tron 3.0</title>
		<link>http://blog.nanomuelle.com/2012/03/08/tron-3-0/</link>
		<comments>http://blog.nanomuelle.com/2012/03/08/tron-3-0/#comments</comments>
		<pubDate>Thu, 08 Mar 2012 20:24:10 +0000</pubDate>
		<dc:creator>nanomuelle</dc:creator>
				<category><![CDATA[8 bits]]></category>
		<category><![CDATA[cbm basic]]></category>
		<category><![CDATA[commodore]]></category>
		<category><![CDATA[vic-20]]></category>

		<guid isPermaLink="false">http://blog.nanomuelle.com/?p=461</guid>
		<description><![CDATA[I have been spending a little more of time in CBM-Basic, so I am ready to present&#8230; Tron 3.0. &#8211; Improved Graphics and speed up to the limits of CBM-Basic of unexpanded Vic-20. The code is not as &#8220;academic&#8221; as before due to memory optimizations, but it is still fully commented. Download source code and [...]]]></description>
			<content:encoded><![CDATA[<p>I have been spending a little more of time in CBM-Basic, so I am ready to present&#8230; <strong>Tron 3.0</strong>.<br />
 &#8211; Improved Graphics and speed up to the limits of CBM-Basic of unexpanded Vic-20.</p>
<p>The code is not as &#8220;academic&#8221; as before due to memory optimizations, but it is still fully commented.</p>
<p>Download source code and d64 image disc: <a href='http://blog.nanomuelle.com/wp-content/uploads/2012/03/tron3.rar'>Tron 3.0</a></p>
<p><a href="http://blog.nanomuelle.com/wp-content/uploads/2012/03/tron3-in-game-screen.png"><img src="http://blog.nanomuelle.com/wp-content/uploads/2012/03/tron3-in-game-screen-300x187.png" alt="" title="tron3-in-game-screen" width="300" height="187" class="alignnone size-medium wp-image-464" /></a></p>
<p>Source code.</p>

<div class="wp_syntax"><div class="code"><pre class="bas" style="font-family:monospace;">::::::::::::::::::::::
:rem tron 3.0      :::
:rem by f.g.huerta :::
::::::::::::::::::::::
&nbsp;
:rem ms-&gt;screen memory (normally 7680)
:rem mc-&gt;color memory (normally 38400)
:rem cm-&gt;character memory (normally 32768) 
1 ms=peek(648):mc=37888+256*(ms and 2):ms=ms*256:cm=32768:poke36879,16
&nbsp;
::::::::::::::::::::::
:rem music :::::::::::
:rem m1,m2,m3 music chanels
:rem n%(8) -&gt; melodie
:rem max volumen
3 dim n%(8):m1=36874:m2=36875:m3=36876:ni=0:poke 36878,15
&nbsp;
::::::::::::::::::::::
:rem players :::::::::
:rem p%(i, data) -&gt; data player array
:rem i -&gt; player id
:rem p%(i, 0)-&gt; x pos
:rem p%(i, 1)-&gt; y pos
:rem p%(i, 2)-&gt; ix
:rem p%(i, 3)-&gt; iy
:rem p%(i, 4)-&gt; color
:rem p%(i, 5)-&gt; status: 0-&gt;ok, 1-&gt;crashed
:rem p%(i, 6)-&gt; current q
:rem p%(i, 7)-&gt; last q 
:rem p%(i, 8)-&gt; last ix
:rem p%(i, 9)-&gt; last iy
:rem p%(i,10)-&gt; num crashes
:rem v -&gt;velocity
:rem b -&gt;background sprite 46
:rem nc -&gt; num cols
:rem nr -&gt; num rows
4 dim p%(1,10):v=1:nc=22:nr=22:b=102
&nbsp;
:rem sprites
:rem s(0) -&gt; up down 93
:rem s(1) -&gt; up right 112
:rem s(2) -&gt; up left 110
:rem s(3) -&gt; left right 64
:rem s(4) -&gt; down right 109
:rem s(5) -&gt; down left 125
5 s0=93:s1=112:s2=110:s3=64:s4=109:s5=125
:rem 52 s$=chr$(93)+chr$(112)+chr$(110)+chr$(64)+chr$(109)+chr$(125)
:rem chr$(158) -&gt; yellow
:rem chr$(30)  -&gt; green
:rem chr$(31)  -&gt; blue
&nbsp;
::::::::::::::::::::::
:rem new game entry point
::::::::::::::::::::::
:rem reset scores
10 p%(0,10)=0:p%(1,10)=0
&nbsp;
::::::::::::::::::::::
:rem new match entry point
::::::::::::::::::::::
:rem init melodie
11 for i=0 to 8:read n%(i):next
:rem init players 
12 for i=0 to 1: for d=0 to 9: read p%(i,d): next:next
:rem clear screen cyan chr$(159): white 5: black 144
13 k$=&quot;&quot;:for i=1 to nc:k$=k$+chr$(166):next i
14 ?chr$(147)chr$(28):for i=0 to nr-1:?k$;:next
:rem paint scores
15 gosub 140
&nbsp;
::::::::::::::::::::::
:::rem begin main loop
::::::::::::::::::::::
: rem debug - print main loop miliseconds
rem 20 ?chr$(19)+str$(timer-t)+&quot;    &quot;;:t=timer
&nbsp;
: rem match finished?
20 if p%(0,5) or p%(1,5) then 100
&nbsp;
: rem game finished?
22 if p%(0,10)=9 or p%(1,10)=9 then 120
&nbsp;
: rem store old velocities
23 p%(0,8)=p%(0,2):p%(0,9)=p%(0,3):p%(1,8)=p%(1,2):p%(1,9)=p%(1,3)
&nbsp;
: rem read keyboard in any key
24 if peek(198)=0 then 30
&nbsp;
:::::::::::: rem exit? 'x'
25 get k$:if k$=&quot;x&quot; then 120
&nbsp;
:::::::::rem player ia
26 if k$=&quot;a&quot; then p%(0,2)=-v:p%(0,3)=0:goto 30
27 if k$=&quot;d&quot; then p%(0,2)=v:p%(0,3)=0:goto 30
28 if k$=&quot;w&quot; then p%(0,3)=-v:p%(0,2)=0:goto 30
29 if k$=&quot;s&quot; then p%(0,3)=v:p%(0,2)=0:goto 30
&nbsp;
:::::::::::rem computer ia
: rem inminent crash? and little random factor
rem 30 q=(p%(1,1)+p%(1,3))*nc+p%(1,0)+p%(1,2):i=rnd(1)
30 d1=p%(1,1):d3=p%(1,3):d0=p%(1,0):d2=p%(1,2)
31 q=(d1+d3)*nc+d0+d2:i=rnd(1)
32 if peek(ms+q)=b and i&lt;.95 then 40
: rem  change direction
33 d=v: if i&lt;.5 then d=-d
34 if d2&lt;&gt;0 then q=(d1+d)*nc+d0:goto 36
35 q=d1*22+d0+d
: rem direction blocked? change direction again
36 if peek(ms+q)&lt;&gt;b then d=-d
: rem final decision
37 if d2&lt;&gt;0 then p%(1,2)=0:p%(1,3)=d: goto 40
38 p%(1,2)=d:p%(1,3)=0
&nbsp;
:::::::::: rem phisics
40 for i=0to1
rem 40 i=0
 :::::::::::: rem move - memory optimized
rem 41 d0=p%(i,0):d2=p%(i,2):p%(i,0)=d0+d2+22*((d0=21andd2=1)-(d0=0andd2=-1))
rem 42 d1=p%(i,1):d3=p%(i,3):p%(i,1)=d1+d3+22*((d1=21andd3=1)-(d1=0andd3=-1))
&nbsp;
::::::::: rem move - speed optimized
41  d0=p%(i,0)+p%(i,2):d1=p%(i,1)+p%(i,3):p%(i,0)=d0:p%(i,1)=d1
42  if d0&lt;0  then p%(i,0)=21
43  if d0&gt;21 then p%(i,0)=0
44  if d1&lt;0  then p%(i,1)=21
45  if d1&gt;21 then p%(i,1)=0
46 next
rem 46 if i=0 then i=1:goto 41
&nbsp;
:::::rem check crashes
:rem draw?
50 if p%(0,0)=p%(1,0) and p%(0,1)=p%(1,1) then p%(0,5)=1:p%(1,5)=1:goto 100
&nbsp;
:rem crash?
51 for i=0 to 1
 :rem if crashes -&gt;
 :rem  - update status
 :rem  - increment crashes
52  p%(i,7)=p%(i,6):p%(i,6)=p%(i,1)*nc+p%(i,0)
53  if peek(ms+p%(i,6))&lt;&gt;b then p%(i,5)=1: p%(i,10)=p%(i,10)+1
54 next
&nbsp;
:::::::::::::rem paint
60 for i=0 to 1
 :::::::::::::rem tail
 :: rem get tail char
 61 d2=p%(i,2):if d2 and d2=p%(i,8) then d=s3:goto 67
 62 d3=p%(i,3):if d3 and d3=p%(i,9) then d=s0:goto 67
&nbsp;
 63 if (p%(i,9)=-v and p%(i,2)=-v) or (p%(i,8)= v and p%(i,3)= v) then d=s2:goto 67
 64 if (p%(i,9)=-v and p%(i,2)= v) or (p%(i,8)=-v and p%(i,3)= v) then d=s1:goto 67
 65 if (p%(i,9)= v and p%(i,2)=-v) or (p%(i,8)= v and p%(i,3)=-v) then d=s5:goto 67
 66 if (p%(i,9)= v and p%(i,2)= v) or (p%(i,8)=-v and p%(i,3)=-v) then d=s4:goto 67
&nbsp;
 :: rem poke tail &amp; head
 67 d7=p%(i,7):poke ms+d7,d:poke mc+d7,p%(i,4):d6=p%(i,6):poke ms+d6,90:poke mc+d6,0
68 next
&nbsp;
: rem play music
69 gosub 85
&nbsp;
:::::rem end main loop
70 goto 20
&nbsp;
::::::::::::::::::::::
:rem music :::::::::::
:rem prepare next note
85 ni=ni+1:if ni&gt;8 then ni=0:poke m1,0
:rem play a note :::::
86 poke m1,n%(ni):poke m2,n%(ni):poke m3,n%(ni)
87 return
&nbsp;
:::::::: rem music off
88 poke m1,0:poke m2,0:poke m3,0:ni=0
89 return
&nbsp;
::::::::::::::::::::::
:::::::::rem end match
::::::::::::::::::::::
::::::::rem select msg
100 if p%(0,5)=1 then msg$=&quot;human crash!&quot;:q=p%(0,1)*nc+p%(0,0):poke mc+q,2
101 if p%(1,5)=1 then msg$=&quot;computer crash!&quot;:q=p%(1,1)*nc+p%(1,0):poke mc+q,2
102 if p%(0,5)+p%(1,5)=2 then msg$=&quot;draw!&quot;
:::::::::rem music off
103 gosub 88
&nbsp;
::::::::rem earthquake
104 for n=1 to 10:for m=10 to 14
105  poke 36864,m:poke 36877,240-m
106 next m: next n
107 poke 36877,0
&nbsp;
:::::::::rem show info
110 k$=chr$(17):?chr$(19)k$k$k$k$k$k$k$k$k$k$k$k$
111 ?chr$(28)&quot;  &quot;msg$:?&quot;  any key continue   &quot;;
::rem flush key buffer
112 get k$: if k$&lt;&gt;&quot;&quot; then 112
::::::::::::::rem wait
113 for i=1 to 1000: next
:rem read keyboard
115 get k$: if k$=&quot;&quot; then 115
:::::::::::::rem exit?
116 if k$=&quot;x&quot; then 120
::rem start new match
117 restore
118 goto 11
&nbsp;
::::::::::::::::::::::
:::::: rem exit ::::::
::::::::::::::::::::::
: rem music off
120 gosub 88
: rem score screen
121 ?chr$(144)chr$(147):
122 ?&quot;final score&quot;
123 ?&quot;----------------------&quot;
124 ?&quot;human    : &quot;;p%(1,10)
125 ?&quot;computer : &quot;;p%(0,10)
126 if p%(0,10)=p%(1,10) then msg$=&quot;draw!&quot;:goto 129
127 if p%(0,10)&lt;p%(1,10) then msg$=&quot;human wins!&quot;:goto 129
128 msg$=&quot;computer wins!&quot;
129 ?msg$
&nbsp;
:::::: new game? :::::
130 ?:?&quot;play again (y/n)?&quot;
: rem flush key buffer
131 get k$: if k$&lt;&gt;&quot;&quot; then 131
::::::::::::: rem wait
132 for i=1 to 1000: next
133 get k$: if k$=&quot;&quot; then 133
134 if k$=&quot;y&quot; then restore:goto 10
135 ?&quot;bye.&quot;:end
&nbsp;
:::::::rem paint score
140 ?chr$(19);:for i=1 to nc:?chr$(17);:next:d0=p%(0,10):d1=p%(1,10)
141 ?chr$(31)&quot; human:&quot;chr$(158)str$(d1)chr$(31)&quot; computer:&quot;chr$(30)str$(d0);
::::::: rem background score
142 for i=0 to 1
143 for ir=0 to 7:d=peek(cm+(48+p%(1-i,10))*8+ir)
144 for ic=7 to 0 step -1
145 d=d/2:d0=0:if d=int(d) then d0=p%(i,4)
146 d=int(d):poke mc+(ir+1)*nc+ic+2+10*i,d0
147 next:next:next
148 return
&nbsp;
::::::::::::::::::::::
::::: rem data :::::::
::::::::::::::::::::::
: rem melody
200 data 215,201,187, 215,201,195, 215,201,187
: rem initial players values
210 data 5,10,1,0,7,0,225,224,0,1
220 data 16,10,-1,0,5,0,236,237,0,1</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.nanomuelle.com/2012/03/08/tron-3-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TRON 2.0</title>
		<link>http://blog.nanomuelle.com/2012/02/22/tron-2-0/</link>
		<comments>http://blog.nanomuelle.com/2012/02/22/tron-2-0/#comments</comments>
		<pubDate>Wed, 22 Feb 2012 13:24:41 +0000</pubDate>
		<dc:creator>nanomuelle</dc:creator>
				<category><![CDATA[8 bits]]></category>
		<category><![CDATA[cbm basic]]></category>
		<category><![CDATA[commodore]]></category>
		<category><![CDATA[vic-20]]></category>
		<category><![CDATA[basic]]></category>

		<guid isPermaLink="false">http://blog.nanomuelle.com/?p=429</guid>
		<description><![CDATA[My first quick version of tron was extremely simple. Here it is another more user friendly version, with improved computer I.A. and sound effects. In game screen. Download source code and d64 image disc: tron.rar Source code. :::::::::::::::::::::: :rem tron 2.0 ::: :rem by f.g.huerta ::: :::::::::::::::::::::: &#160; :: rem configure music ::::::::::: volume max [...]]]></description>
			<content:encoded><![CDATA[<p>My first quick version of tron was extremely simple.</p>
<p>Here it is another more user friendly version, with improved computer I.A. and sound effects.</p>
<p>In game screen.<br />
<a href="http://blog.nanomuelle.com/wp-content/uploads/2012/02/in-game-screen.png"><img class="alignnone size-medium wp-image-434" title="in-game-screen" src="http://blog.nanomuelle.com/wp-content/uploads/2012/02/in-game-screen-300x259.png" alt="" width="300" height="259" /></a></p>
<p>Download source code and d64 image disc: <a href="http://blog.nanomuelle.com/2012/02/22/tron-2-0/tron/" rel="attachment wp-att-458">tron.rar</a></p>
<p>Source code.</p>

<div class="wp_syntax"><div class="code"><pre class="bas" style="font-family:monospace;">::::::::::::::::::::::
:rem tron 2.0      :::
:rem by f.g.huerta :::
::::::::::::::::::::::
&nbsp;
:: rem configure music
::::::::::: volume max
10 poke 36878,15
&nbsp;
::::::::::::::::::::::
:rem music :::::::::::
:rem mm(2) -&gt; instruments
:rem n%(3) -&gt; melodie
20 dim mm(2):dim n%(3)
:rem init instruments
22 mm(0)=36874:mm(1)=36875:mm(2)=36876
:rem music pointers
24 mi=0:ni=0
&nbsp;
::::::::::::::::::::::
:rem players :::::::::
:rem p(pn, data) -&gt; data player array
:rem pn -&gt; player id
:rem p(pn, 0)-&gt; x pos
:rem p(pn, 1)-&gt; y pos
:rem p(pn, 2)-&gt; ix
:rem p(pn, 3)-&gt; iy
:rem p(pn, 4)-&gt; color
:rem p(pn, 5)-&gt; status: 0-&gt;ok, 1-&gt;crashed
:rem p(pn, 6)-&gt; num crashes
:rem p(pn, 7)-&gt; last x pos
:rem p(pn, 8)-&gt; last y pos
30 dim p(1,8)
&nbsp;
:rem ms-&gt;screen memory
:rem mc-&gt;color memory
40 ms=7680: mc=38400
&nbsp;
:rem v -&gt;velocity
:rem s -&gt;character sprite
:rem hc-&gt;head color
50 v=1:s=asc(&quot;*&quot;): hc=0
&nbsp;
::::::::::::::::::::::
:rem new game entry point
::::::::::::::::::::::
:rem reset scores
60 p(0,6)=0:p(1,6)=0
&nbsp;
::::::::::::::::::::::
:rem new match entry point
::::::::::::::::::::::
:rem init melodie
70 for i=0 to 3:read n%(i):next i
:rem init players 
75 for pn=0 to 1: for i=0 to 5
80  read p(pn,i)
90 next i: next pn
&nbsp;
:rem clear screen
100 print chr$(147)
&nbsp;
::::::::::::::::::::::
:::rem begin main loop
::::::::::::::::::::::
&nbsp;
: rem match finished?
110 if p(0,5)+p(1,5) &gt; 0 then 1510
&nbsp;
: rem game finished?
120 if p(0,6)=9 or p(1,6)=9 then 1810
&nbsp;
: rem read keyboard
130 get k$
&nbsp;
: rem exit?
140 if k$=&quot;x&quot; then goto 1810
&nbsp;
:::::::::rem player ia
210 if k$=&quot;a&quot; then p(0,2)=-v:p(0,3)=0
220 if k$=&quot;d&quot; then p(0,2)=v :p(0,3)=0
230 if k$=&quot;w&quot; then p(0,3)=-v:p(0,2)=0
240 if k$=&quot;s&quot; then p(0,3)=v :p(0,2)=0
&nbsp;
:::::::::::rem computer ia
: inminent crash? and little random factor
310 q=(p(1,1)+p(1,3))*22+p(1,0)+p(1,2)
320 if peek(ms+q)&lt;&gt;s and rnd(1)&lt;.95 then goto 410
: change direction
330 d=v: if rnd(1)&lt;.5 then d=-d
340 if p(1,2)&lt;&gt;0 then q=(p(1,1)+d)*22+p(1,0):goto 360
350 q=p(1,1)*22+p(1,0)+d
: direction blocked? change direction again
360 if peek(ms+q)=s then d=-d
: final decision
370 if p(1,2)&lt;&gt;0 then p(1,2)=0:p(1,3)=d: goto 410
380 p(1,2)=d:p(1,3)=0
&nbsp;
:::::::::: rem phisics
410 for pn=0 to 1
 :::: rem save old pos
420  p(pn,7)=p(pn,0):p(pn,8)=p(pn,1)
 :::::::::::: rem move
430  p(pn,0)=p(pn,0)+p(pn,2): p(pn,1)=p(pn,1)+p(pn,3)
 ::::::::: rem fix pos
440  if p(pn,0)&lt;0  then p(pn,0)=21
450  if p(pn,0)&gt;21 then p(pn,0)=0
460  if p(pn,1)&lt;0  then p(pn,1)=22
470  if p(pn,1)&gt;22 then p(pn,1)=0
480 next pn
&nbsp;
:::::rem check crashes
:rem draw?
510 if p(0,0)=p(1,0) and p(0,1)=p(1,1) then p(0,5)=1:p(1,5)=1:goto 1510
&nbsp;
:rem player crashes?
520 for pn=0 to 1
 :rem if crashes -&gt;
 :rem  - update status
 :rem  - increment crashes
530  q=p(pn,1)*22+p(pn,0)
540  if peek(ms+q)=s then p(pn,5)=1: p(pn,6)=p(pn,6)+1
550 next
&nbsp;
:::::::::::::rem paint
610 for pn=0 to 1
 :::::::::::::rem tail
630  q=p(pn,8)*22+p(pn,7)
640  poke mc+q,p(pn,4)
 :::::::::::::rem head
660  q=p(pn,1)*22+p(pn,0)
670  poke ms+q,s
680  poke mc+q,hc
690 next
&nbsp;
:::::::rem paint score
720 q=2*22+2
730 poke mc+q,p(0,4)
740 poke ms+q,48+p(1,6)
750 q=2*22+19
760 poke mc+q,p(1,4)
770 poke ms+q,48+p(0,6)
&nbsp;
: play music
780 gosub 1110
&nbsp;
:::::rem end main loop
790 goto 110
&nbsp;
::::::::::::::::::::::
::::: music ::::::::::
:rem prepare next note
1110 ni=ni+1:if ni&gt;3 then ni=0:poke mm(mi),0:mi=mi+1
1120 if mi&gt;2 then mi=0
:rem play a note :::::
1130 poke mm(mi),n%(ni)
1140 return
&nbsp;
:::::::::::: music off
1210 poke mm(0),0
1220 poke mm(1),0
1230 poke mm(2),0
: reset music pointers
1240 mi=0:ni=0
1250 return
&nbsp;
::::::::::::::::::::::
:::::::::rem end match
::::::::::::::::::::::
::::::::rem select msg
1510 if p(0,5)=1 then msg$=&quot;human crash!&quot;:q=p(0,1)*22+p(0,0):poke mc+q,2
1520 if p(1,5)=1 then msg$=&quot;computer crash!&quot;:q=p(1,1)*22+p(1,0):poke mc+q,2
1530 if p(0,5)+p(1,5)=2 then msg$=&quot;draw!&quot;
&nbsp;
:::::::::rem music off
1540 gosub 1210
&nbsp;
::::::::rem earthquake
1550 for n=1 to 10:for m=10 to 14
1560  poke 36864,m:poke 36877,240-m
1570 next m: next n
1580 poke36877,0
&nbsp;
:::::::::rem show info
1610 print msg$
1620 print &quot;any key continue&quot;
::rem flush key buffer
1630 get k$: if k$&lt;&gt;&quot;&quot; then 1630
::::::::::::::rem wait
1640 for i=1 to 1000: next
:rem read keyboard
1650 get k$: if k$=&quot;&quot; then 1650
:::::::::::::rem exit?
1660 if k$=&quot;x&quot; then 1810
::rem start new match
1670 restore
1680 goto 70
&nbsp;
::::::::::::::::::::::
:::::: rem exit ::::::
::::::::::::::::::::::
: rem music off
1810 gosub 1210
: rem score screen
1815 print chr$(147)
1820 print &quot;final score&quot;
1830 print &quot;----------------------&quot;
1840 print &quot;human    : &quot;;p(1,6)
1850 print &quot;computer : &quot;;p(0,6)
1860 if p(0,6)=p(1,6) then msg$=&quot;draw!&quot;:goto 1890
1870 if p(0,6)&lt;p(1,6) then msg$=&quot;human wins!&quot;: goto 1890
1880 msg$=&quot;computer wins!&quot;
1890 print:print msg$
&nbsp;
:::::: new game? :::::
1900 print:print&quot;play again (y/n)?&quot;
: rem flush key buffer
1910 get k$: if k$&lt;&gt;&quot;&quot; then 1890
::::::::::::: rem wait
1920 for i=1 to 1000: next
1930 get k$: if k$=&quot;&quot; then 1930
1940 if k$=&quot;y&quot; then restore:goto 60
1950 print &quot;bye.&quot;
1960 end
&nbsp;
::::::::::::::::::::::
::::: rem data :::::::
::::::::::::::::::::::
: melody
2010 data 195,201,207,209
: initial players values
2020 data 9, 11, 0, -1, 7, 0
2030 data 11, 11, 0, -1, 5, 0</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.nanomuelle.com/2012/02/22/tron-2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TRON &#8211; Remembering old Commodore days</title>
		<link>http://blog.nanomuelle.com/2012/02/22/tron-remembering-old-commodore-days/</link>
		<comments>http://blog.nanomuelle.com/2012/02/22/tron-remembering-old-commodore-days/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 23:24:45 +0000</pubDate>
		<dc:creator>nanomuelle</dc:creator>
				<category><![CDATA[8 bits]]></category>
		<category><![CDATA[cbm basic]]></category>
		<category><![CDATA[commodore]]></category>
		<category><![CDATA[vic-20]]></category>
		<category><![CDATA[basic]]></category>

		<guid isPermaLink="false">http://blog.nanomuelle.com/?p=419</guid>
		<description><![CDATA[A couple of days ago, I found in Amazon the book &#8220;A commodore 64 Walkabout by Robinson Mason&#8221;, so I had no choice but buy it. As many other nowadays developers, in the eighties I was the owner of a fantastic Commodore Vic-20, a real cool computer, the real programmer teacher for many of us. [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago, I found in Amazon the book &#8220;A commodore 64 Walkabout by Robinson Mason&#8221;, so I had no choice but buy it.</p>
<p>As many other nowadays developers, in the eighties I was the owner of a fantastic Commodore Vic-20, a real cool computer, the real programmer teacher for many of us.</p>
<p>After reading no more than twenty pages, I had to download the VICE emulator and as if it was an old ritual, I began to type the game of TRON, a clasic game that I have developed in every computer platform that I have owned, and in every programming language that I have learned.</p>
<p>Here is the code I have been able to develop in a couple of hours of remembering CBM Basic. The code works ok in the Commodore Vic-20 emulation of VICE. Enjoy it.</p>

<div class="wp_syntax"><div class="code"><pre class="bas" style="font-family:monospace;">10 : rem TRON   :::::
12 : rem by     :::::
14 : rem F.G.Huerta :
&nbsp;
20 rem ::::::init vars
25 rem n =&gt; (x, y, ix, iy, color)
30 dim p%(1,4)
40 for pn=0 to 1
50  for i=0 to 4
60   read a: p%(pn,i)=a
70  next i
80 next pn
&nbsp;
90 :::::::rem velocity
100 v=1
&nbsp;
110 rem ::::::::sprite
120 s=asc(&quot;*&quot;)
&nbsp;
130 rem screen &amp; color
140 ms=7680: mc=38400
&nbsp;
150 :::rem init screen
160 print chr$(147)
&nbsp;
170 :::::rem main loop
180 get k$
190 if k$=&quot;x&quot; then msg$=&quot;bye&quot;:goto 1600: rem salir
&nbsp;
200 :::::rem player ia
210 if k$=&quot;a&quot; then p%(0,2)=-v:p%(0,3)=0
220 if k$=&quot;d&quot; then p%(0,2)=v :p%(0,3)=0
230 if k$=&quot;w&quot; then p%(0,3)=-v:p%(0,2)=0
240 if k$=&quot;s&quot; then p%(0,3)=v :p%(0,2)=0
&nbsp;
300 :::::::rem comp ia
310 x=p%(1,0)+p%(1,2):y=p%(1,1)+p%(1,3)
320 gosub 1000: rem get char
330 if z&lt;&gt;s then goto 400
340 if p%(1,2)&lt;&gt;0 then p%(1,2)=0:p%(1,3)=1: goto 400
350 p%(1,2)=1:p%(1,3)=0
&nbsp;
400 :::::::rem phisics
410 for pn=0 to 1
420   gosub 1100: rem p to vars
430   gosub 1200: rem move
440   gosub 1300: rem vars to p
450 next pn
&nbsp;
500 :::::::rem chk fin
510 if p%(0,0)=p%(1,0) and p%(0,1)=p%(1,1) then 1400: rem empate
520 for pn=0 to 1
530   gosub 1100: rem p to vars
540   gosub 1000: rem get char
550   if z=s then 1500: rem winner
560 next
&nbsp;
600 ::::::::rem pintar
610 for pn=0 to 1
620   q=p%(pn,1)*22+p%(pn,0)
630   poke mc+q,p%(pn,4)
640   poke ms+q,s
650 next
&nbsp;
700 ::::::rem end loop
710 goto 170
&nbsp;
1000 ::::::rem get char
1010 q=y*22+x
1020 z=peek(ms+q)
1030 return
&nbsp;
1100 :::::rem p to vars
1110 x = p%(pn,0): y = p%(pn,1)
1120 ix= p%(pn,2): iy= p%(pn,3)
1130 return
&nbsp;
1200 ::::::::: rem move
1210 x=x+ix: y=y+iy
1220 if x&lt;1  then x=21
1230 if x&gt;21 then x=0
1240 if y&lt;1  then y=21
1250 if y&gt;21 then y=0
1260 return
&nbsp;
1300 :::::rem vars to p
1310 p%(pn,0)=x
1320 p%(pn,1)=y
1330 return
&nbsp;
1400 ::::::: rem empate
1410 msg$=&quot;draw&quot;
1420 gosub 1700: rem efectos especiales
1420 goto 1600: rem salir
&nbsp;
1500 :::::::rem winner
1510 msg$=&quot;human win&quot;
1520 if pn=0 then msg$=&quot;computer win&quot;
1530 gosub 1700: rem efectos especiales
&nbsp;
1600 ::::::::rem salir
1610 print msg$
1620 end
&nbsp;
1700 :::rem efecto fin
1710 for n=1 to 10
1720  for m=10 to 14
1730   poke36864,m
1740  next m
1750 next n
1760 return 
&nbsp;
2000 :::::::::rem data
2010 data 9, 11, 0, 1, 7
2020 data 11, 11, 0, 1, 2</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.nanomuelle.com/2012/02/22/tron-remembering-old-commodore-days/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony2 &#8211; Get action name from twig templates</title>
		<link>http://blog.nanomuelle.com/2012/01/27/symfony2-get-action-name-from-twig-templates/</link>
		<comments>http://blog.nanomuelle.com/2012/01/27/symfony2-get-action-name-from-twig-templates/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 12:49:09 +0000</pubDate>
		<dc:creator>nanomuelle</dc:creator>
				<category><![CDATA[snippet]]></category>
		<category><![CDATA[Symfony2]]></category>
		<category><![CDATA[twig]]></category>

		<guid isPermaLink="false">http://blog.nanomuelle.com/?p=400</guid>
		<description><![CDATA[This is the easyest way that I have found to get the action name from a twig template: &#160; {{ app.request.attributes.get('_template').get('name') }} &#8230;and the controller object: &#160; {{ app.request.attributes.get('_template').get('controller') }}]]></description>
			<content:encoded><![CDATA[<p>This is the easyest way that I have found to get the action name from a twig template:</p>

<div class="wp_syntax"><div class="code"><pre class="twig" style="font-family:monospace;">&nbsp;
{{ app.request.attributes.get('_template').get('name') }}</pre></div></div>

<p>&#8230;and the controller object:</p>

<div class="wp_syntax"><div class="code"><pre class="twig" style="font-family:monospace;">&nbsp;
{{ app.request.attributes.get('_template').get('controller') }}</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.nanomuelle.com/2012/01/27/symfony2-get-action-name-from-twig-templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unity first impressions</title>
		<link>http://blog.nanomuelle.com/2011/04/12/unity-first-impressions/</link>
		<comments>http://blog.nanomuelle.com/2011/04/12/unity-first-impressions/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 19:54:49 +0000</pubDate>
		<dc:creator>nanomuelle</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[Unity3d]]></category>

		<guid isPermaLink="false">http://blog.nanomuelle.com/?p=395</guid>
		<description><![CDATA[I am developping a simple mini-game with Unity. My first impression is that Unity is as powered as easy to use. I am really impresed. I only I had better 3D Studio skills! Woodman progress: http://nanomuelle.com/woodman Unity home page: http://unity3d.com/]]></description>
			<content:encoded><![CDATA[<p>I am developping a simple mini-game with Unity.</p>
<p>My first impression is that Unity is as powered as easy to use. I am really impresed.<br />
I only I had better 3D Studio skills!</p>
<p>Woodman progress: http://nanomuelle.com/woodman<br />
Unity home page: http://unity3d.com/</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nanomuelle.com/2011/04/12/unity-first-impressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Owner Credential &amp; Propel Admin Generator</title>
		<link>http://blog.nanomuelle.com/2010/12/03/owner-credential-propel-admin-generator/</link>
		<comments>http://blog.nanomuelle.com/2010/12/03/owner-credential-propel-admin-generator/#comments</comments>
		<pubDate>Fri, 03 Dec 2010 12:11:37 +0000</pubDate>
		<dc:creator>nanomuelle</dc:creator>
				<category><![CDATA[admin-generator]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://blog.nanomuelle.com/?p=366</guid>
		<description><![CDATA[It would be great to be able to specify in generator.yml a per object owner credential, so the generator only showed that actions to the owner of each object. Lets see how we can achieve this behavior easily. Setting up the project. Install and Configure Symfony Follow the instructions of the great jobeet tutorial to [...]]]></description>
			<content:encoded><![CDATA[<p>It would be great to be able to specify in generator.yml a per object owner credential, so the generator only showed that actions to the owner of each object. Lets see how we can achieve this behavior easily.</p>
<h2>Setting up the project.</h2>
<h3>Install and Configure Symfony</h3>
<p>Follow the instructions of the great jobeet tutorial to <a href="http://www.symfony-project.org/jobeet/1_4/Propel/en/01">install symfony and create the frontend application</a>. We will use the propel ORM.
    </p>
<h3>Instaling sfGuardPlugin</h3>
<p>Following the symfony philosophy, we do not need to reinvent the wheel.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ symfony plugin:<span style="color: #c20cb9; font-weight: bold;">install</span> sfGuardPlugin</pre></div></div>

<h3>Preparing schema and some sample data</h3>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;"># config/schema.yml
propel:
  post:
    id:
    title:    { type: varchar(255), required: true }
    content:  { type: longvarchar, required: false }
    owner_id: 
      type: integer
      foreignTable: sf_guard_user
      foreignReference: id
      required: true</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;"># data/fixtures/fixtures.yml
sfGuardUser:
  andrew:
    username: andrew
    password: andrew
  valentine:
    username: valentine
    password: valentine
&nbsp;
Post:
  -
    title: Andrew's Post
    content: This is the content of the first Andrew's post.
    owner_id: andrew
  -
    title: Valentine's Post
    content: This is the content of the first Valentine's post.
    owner_id: valentine</pre></div></div>

<h3>Build models, load data and create the post module</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ symfony generate:app frontend
$ symfony propel:build <span style="color: #660033;">--all</span> <span style="color: #660033;">--and-load</span>
$ symfony propel:generate-admin frontend Post
$ symfony plugin:publish-assets
$ symfony <span style="color: #c20cb9; font-weight: bold;">clear</span> cache</pre></div></div>

<h2>The funny work</h2>
<p>At this point, if you go to the url <strong>ocag.localhost/post</strong>, we can see the list of posts, with two actions attached to each post: edit and delete.</p>
<p><img src="http://blog.nanomuelle.com/wp-content/uploads/2010/post_list_before.png"/></p>
<p>What we want is that the admin-generator only shows the actions edit and/or delete to the owner of each post.</p>
<h3>Enabling login module and securing post module</h3>
<p>Add the following to settings.yml</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;"># apps/frontend/settings.yml
# ...
all:
  .settings:
    # ...
    # Modules
    enabled_modules: [default, sfGuardAuth]
&nbsp;
  .actions:
    # ...
    login_module:   sfGuardAuth
    login_action:   signin
    secure_module:  sfGuardAuth
    secure_action:  secure</pre></div></div>

<p>Secure the post module</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;"># apps/frontend/modules/post/config/security.yml
default:
  is_secure: true</pre></div></div>

<h3>Edit the generator.yml</h3>
<p>First, we set the <em>owner</em> credential to an object action.</p>
<p>What we woult like the admin generator to do with this, is to hide that action to everybody but the creator of the object being procesed.</p>
<p>Saddly this is not way the default admin generator works, but we will soon see how to build our own customized admin theme with this behavior.</p>
<p>Don&#8217;t be afraid! It&#8217;s easyer than it appears.</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;"># apps/modules/post/config/generator.yml
generator:
  class: sfPropelGenerator
  param:
    model_class:           Post
    theme:                 admin
    non_verbose_templates: true
    with_show:             false
    singular:              Post
    plural:                Posts
    route_prefix:          post
    with_propel_route:     1
    actions_base_class:    sfActions
&nbsp;
    config:
      actions: ~
      fields:  ~
      list:
        #
        # setting owner credential
        #
        object_actions:
          _edit:
            credentials: owner
          _delete:
            credentials: owner
      filter:  ~
      form:    ~
      edit:    ~
      new:     ~</pre></div></div>

<h3>Creating myadmin theme</h3>
<p>Create the folder data/generator/sfPropelModule/myadmin and copy the admin theme files in order to customize them:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> data<span style="color: #000000; font-weight: bold;">/</span>generator<span style="color: #000000; font-weight: bold;">/</span>sfPropelModule<span style="color: #000000; font-weight: bold;">/</span>myadmin
$ <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-r</span> lib<span style="color: #000000; font-weight: bold;">/</span>vendor<span style="color: #000000; font-weight: bold;">/</span>symfony<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>plugins<span style="color: #000000; font-weight: bold;">/</span>sfPropelPlugin<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>generator<span style="color: #000000; font-weight: bold;">/</span>sfPropelModule<span style="color: #000000; font-weight: bold;">/</span>admin<span style="color: #000000; font-weight: bold;">/*</span> \
data<span style="color: #000000; font-weight: bold;">/</span>generator<span style="color: #000000; font-weight: bold;">/</span>sfPropelModule<span style="color: #000000; font-weight: bold;">/</span>myadmin</pre></div></div>

<p>Configure the generator.yml to use myadmin theme</p>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;"># apps/modules/post/config/generator.yml
generator:
  #...
  param:
    #...
    theme:                 myadmin</pre></div></div>

<p>The partial-generator responsible of the object_actions is <strong>data/generator/sfPropelModule/myadmin/template/templates/_list_td_actions.php</strong>.  We are going to add a line that calls a user function that dinamically adds or  revoques the owner credential depending on the object being processed.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;?php $sf_user-&gt;addOwnerCredentials($'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSingularName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">') ?&gt;'</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;td&gt;
  &lt;ul class=&quot;sf_admin_td_actions&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">configuration</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'list.object_actions'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_delete'</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCredentialCondition</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'[?php echo $helper-&gt;linkToDelete($'</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSingularName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">', '</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asPhp</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">') ?]'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_edit'</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCredentialCondition</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'[?php echo $helper-&gt;linkToEdit($'</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSingularName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">', '</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">asPhp</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">') ?]'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;li class=&quot;sf_admin_action_<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'class_suffix'</span><span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
      <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCredentialCondition</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLinkToAction</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
    &lt;/li&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;/ul&gt;
&lt;/td&gt;</pre></div></div>

<p>Now edit myUser.class.php to code the addOwnerCredentials method</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// apps/frontend/lib/myUser.class.php</span>
<span style="color: #000000; font-weight: bold;">class</span> myUser <span style="color: #000000; font-weight: bold;">extends</span> sfGuardSecurityUser
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">protected</span> static <span style="color: #000088;">$OWNER_CREDENTIAL</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'owner'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * If the user is the owner of the $object adds owner credentials,
   * otherwise remvoques it.
   */</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addOwnerCredentials<span style="color: #009900;">&#40;</span><span style="color: #000088;">$object</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isAuthenticated</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$object</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$object</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'sfOutputEscaperObjectDecorator'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$object</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRawValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">method_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$object</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'isOwner'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isOwner</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getGuardUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCredential</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$OWNER_CREDENTIAL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">removeCredential</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$OWNER_CREDENTIAL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Tunning Post model</h3>
<p>The only thing we have to do now is to add the <em>isOnwer</em> method to each model that we want to be checked against owner credential, Post model in our case. So lets edit lib/model/Post.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// lib/model/Post.php</span>
<span style="color: #000000; font-weight: bold;">class</span> Post <span style="color: #000000; font-weight: bold;">extends</span> BasePost <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> isOwner<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sf_guard_user</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">owner_id</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$sf_guard_user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Try it</h3>
<p>And thats all. Clear caches, login as Andrew or Alice and see how the admin generator only shows the action links to the owner of each post. See the post list logged as Andrew:</p>
<p><img src="http://blog.nanomuelle.com/wp-content/uploads/2010/post_list_after.png"/></p>
<h3>Very immportant final comment</h3>
<p>Remember that the only thing that we have done with this is to <strong>automatize  the view layer</strong> generated by the admin generator. You still <strong>must securize the edit and delete actions</strong> of each module in order to avoid undeserable people to be able to execute them.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nanomuelle.com/2010/12/03/owner-credential-propel-admin-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How I beat Bejeweled Blitz</title>
		<link>http://blog.nanomuelle.com/2010/10/21/how-i-beat-bejeweled-blitz/</link>
		<comments>http://blog.nanomuelle.com/2010/10/21/how-i-beat-bejeweled-blitz/#comments</comments>
		<pubDate>Thu, 21 Oct 2010 17:36:27 +0000</pubDate>
		<dc:creator>nanomuelle</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blog.nanomuelle.com/?p=317</guid>
		<description><![CDATA[Tired of being beated week after week by my facebook friends, I decided to investigate the most hidden secrets of Bewejeled Blitz. After one or two thousands games, I finally realize that the only secret was to be the fastest. As I was not the fastest, there was only one thing I could do to [...]]]></description>
			<content:encoded><![CDATA[<p>Tired  of being beated week after week by my facebook friends, I decided to  investigate the most hidden secrets of Bewejeled Blitz. After one or two  thousands games, I finally realize that the only secret was to be the fastest. As I was not the fastest, there was only one thing I could do to  beat my friends&#8230; I would program a script that beat them for me.</p>
<p>Of course, it was an incredible opportunity to learn a little more about python also.</p>
<h3>How the script works</h3>
<p>Basically, the script do what a human do while playing:</p>
<ol>
<li>Look at the board. The script captures the Bejeweled Blitz board, and  analyzes where the jewels are. To do so, I used the PIL library to capture the screen. After that, I posterize the image reducing the number of colors, making it easy to distinguish the jewels between each other.</li>
<li>Find a goal. The script simulates a jeweled move in memory, and looks up for a goal (three-in-a-row). If there is a goal, the script moves the mouse  (PyWin32 API) and actually makes the move.</li>
<li>Repeat everything again and again until game-time ends.</li>
</ol>
<h3>How to use it</h3>
<p>The first thing that you need is to find out the (x, y) coordinates of the  Bejeweled Blitz Board. To do this, start a Bejewelled Blitz and capture the screen with the &#8211;save option of the script. The next command makes a capture of the screen and saves it with the name “my_capture.bmp”.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">c:<span style="color: #000000; font-weight: bold;">&gt;</span>python Bwbot.pyw <span style="color: #660033;">--save</span> my_capture.bmp <span style="color: #000000;">0</span> <span style="color: #000000;">0</span></pre></div></div>

<p>Then open the image with a program like GIMP <a href="https://docs.google.com/document/edit?id=1o-1XXWMraXx9QiqYt5LJ-djtSrCmEGnTHZspaD7AN4o&amp;hl=es&amp;pli=1">(http://www.gimp.org/)</a> and look up the upper left coordinates of the Bejewelled Blitz Board.</p>
<p><img src="http://blog.nanomuelle.com/wp-content/uploads/2010/bwbot_coordenadas.png" alt="Bejeweled Blitz Board coordinates" width="390px" height="109px"/></p>
<p>To make the script play, just start a new game, and execute the script passing it the x and y coordinates you has just find out, for example:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">c:<span style="color: #000000; font-weight: bold;">&gt;</span>python Bwbot.pyw <span style="color: #000000;">527</span> <span style="color: #000000;">455</span></pre></div></div>

<h3>The script</h3>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">##</span>
<span style="color: #808080; font-style: italic;">## Bwbot.pyw</span>
<span style="color: #808080; font-style: italic;">##</span>
<span style="color: #808080; font-style: italic;">## A python script to play Bejeweled Blitz</span>
<span style="color: #808080; font-style: italic;">##</span>
<span style="color: #808080; font-style: italic;">## Author:  Fernando García</span>
<span style="color: #808080; font-style: italic;">## Licence: The script is under public domain. You can use, distribute or</span>
<span style="color: #808080; font-style: italic;">##          modify it at your own risk.</span>
<span style="color: #808080; font-style: italic;">##</span>
<span style="color: #ff7700;font-weight:bold;">import</span> win32api, win32con
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">random</span>
<span style="color: #ff7700;font-weight:bold;">import</span> Image
<span style="color: #ff7700;font-weight:bold;">import</span> ImageChops
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">math</span>, <span style="color: #dc143c;">operator</span>
<span style="color: #ff7700;font-weight:bold;">from</span> PIL <span style="color: #ff7700;font-weight:bold;">import</span> ImageGrab
<span style="color: #ff7700;font-weight:bold;">from</span> PIL <span style="color: #ff7700;font-weight:bold;">import</span> ImageOps
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">import</span> argparse
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> saveImage<span style="color: black;">&#40;</span>filename<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;Capture screen and save it to a bmp file&quot;</span>
&nbsp;
    _im = ImageGrab.<span style="color: black;">grab</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    _im.<span style="color: black;">save</span><span style="color: black;">&#40;</span>filename, <span style="color: #483d8b;">&quot;BMP&quot;</span><span style="color: black;">&#41;</span>        
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Bwbot:    
    WIDTH = <span style="color: #ff4500;">320</span>   <span style="color: #808080; font-style: italic;"># width of the board</span>
    HEIGHT = <span style="color: #ff4500;">320</span>  <span style="color: #808080; font-style: italic;"># height of the board</span>
&nbsp;
    COLS = <span style="color: #ff4500;">8</span>      <span style="color: #808080; font-style: italic;"># number of cols of the board</span>
    ROWS = <span style="color: #ff4500;">8</span>      <span style="color: #808080; font-style: italic;"># number of rows of the board</span>
    LAST_ROW_INDEX = <span style="color: #ff4500;">7</span> <span style="color: #808080; font-style: italic;"># index of the last row of the board</span>
    LAST_COL_INDEX = <span style="color: #ff4500;">7</span> <span style="color: #808080; font-style: italic;"># index of the last row of the board</span>
&nbsp;
    SQUARE_WIDTH = WIDTH / COLS   <span style="color: #808080; font-style: italic;"># width of a grid square</span>
    MID_SQUARE_WIDTH = SQUARE_WIDTH / <span style="color: #ff4500;">2</span> <span style="color: #808080; font-style: italic;"># mid width of a grid square</span>
&nbsp;
    SQUARE_HEIGHT = HEIGHT / ROWS   <span style="color: #808080; font-style: italic;"># heigth of a grid square</span>
    MID_SQUARE_HEIGHT = SQUARE_HEIGHT / <span style="color: #ff4500;">2</span> <span style="color: #808080; font-style: italic;"># mid height of a grid square</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, ox, oy<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;Initializes instance variables&quot;</span>
        <span style="color: #808080; font-style: italic;">#</span>
        <span style="color: #808080; font-style: italic;"># play time in secconds</span>
        <span style="color: #808080; font-style: italic;">#</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">playtime</span> = <span style="color: #ff4500;">55</span>  
&nbsp;
        <span style="color: #808080; font-style: italic;">#</span>
        <span style="color: #808080; font-style: italic;"># drag delay in miliseconds</span>
        <span style="color: #808080; font-style: italic;"># 20.-human 15.-optimal 10.-quick</span>
        <span style="color: #808080; font-style: italic;">#</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">drag_delay</span> = <span style="color: #ff4500;">20</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">#</span>
        <span style="color: #808080; font-style: italic;"># screen position of the board in pixels</span>
        <span style="color: #808080; font-style: italic;">#</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">ox</span> = ox        <span style="color: #808080; font-style: italic;"># x screen coordinate of the board</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">oy</span> = oy        <span style="color: #808080; font-style: italic;"># y screen coordinate of the board</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">#</span>
        <span style="color: #808080; font-style: italic;"># rect of screen to capture de board </span>
        <span style="color: #808080; font-style: italic;">#</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">grid</span> = <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">ox</span>, <span style="color: #008000;">self</span>.<span style="color: black;">oy</span>, <span style="color: #008000;">self</span>.<span style="color: black;">ox</span> + Bwbot.<span style="color: black;">WIDTH</span>, <span style="color: #008000;">self</span>.<span style="color: black;">oy</span> + Bwbot.<span style="color: black;">HEIGHT</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">#</span>
        <span style="color: #808080; font-style: italic;"># Inner representation of the board</span>
        <span style="color: #808080; font-style: italic;">#</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">matrix</span> = <span style="color: black;">&#91;</span><span style="color: black;">&#91;</span><span style="color: #008000;">None</span> <span style="color: #ff7700;font-weight:bold;">for</span> _col <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span>Bwbot.<span style="color: black;">COLS</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> \
            <span style="color: #ff7700;font-weight:bold;">for</span> _row <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span>Bwbot.<span style="color: black;">ROWS</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">#</span>
        <span style="color: #808080; font-style: italic;"># Sample size. The size in pixels of the square used to sample colors</span>
        <span style="color: #808080; font-style: italic;"># </span>
        <span style="color: #008000;">self</span>.<span style="color: black;">sample_size</span> = <span style="color: #ff4500;">8</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> toMouseCoordinates<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, pos<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;Translates grid coordinates to mouse coordinates&quot;</span>
&nbsp;
        _x = <span style="color: #008000;">self</span>.<span style="color: black;">ox</span> + pos<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">*</span> Bwbot.<span style="color: black;">SQUARE_WIDTH</span> + Bwbot.<span style="color: black;">MID_SQUARE_WIDTH</span>
        _y = <span style="color: #008000;">self</span>.<span style="color: black;">oy</span> + pos<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">*</span> Bwbot.<span style="color: black;">SQUARE_HEIGHT</span> + Bwbot.<span style="color: black;">MID_SQUARE_HEIGHT</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#40;</span>_x, _y<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> click<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, pos<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;Make a mouse click. Pos especified in grid coordinates&quot;</span>
        _x, _y = <span style="color: #008000;">self</span>.<span style="color: black;">toMouseCoordinates</span><span style="color: black;">&#40;</span>pos<span style="color: black;">&#41;</span>
        win32api.<span style="color: black;">SetCursorPos</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>_x, _y<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        win32api.<span style="color: black;">mouse_event</span><span style="color: black;">&#40;</span>win32con.<span style="color: black;">MOUSEEVENTF_LEFTDOWN</span>, _x, _y, <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
        win32api.<span style="color: black;">mouse_event</span><span style="color: black;">&#40;</span>win32con.<span style="color: black;">MOUSEEVENTF_LEFTUP</span>, _x, _y, <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> dragJewel<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, pos1, pos2<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;Drags a jewel from pos1 to pos2&quot;</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">click</span><span style="color: black;">&#40;</span>pos1<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">click</span><span style="color: black;">&#40;</span>pos2<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">wait</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">drag_delay</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> wait<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, delay<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;Do nothing during delay miliseconds&quot;</span>
&nbsp;
        _delay = delay / <span style="color: #ff4500;">1000.0</span>
        _ref = <span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: black;">&#40;</span><span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> - _ref<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&lt;</span> _delay:
          <span style="color: #ff7700;font-weight:bold;">pass</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> captureBoard<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;Capture and preproceses Bejeweled Blitz board&quot;</span>
&nbsp;
        _im = ImageGrab.<span style="color: black;">grab</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>                           <span style="color: #808080; font-style: italic;"># capture and</span>
        _im = ImageOps.<span style="color: black;">posterize</span><span style="color: black;">&#40;</span>_im.<span style="color: black;">crop</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">grid</span><span style="color: black;">&#41;</span>, <span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># reduce colors</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> _im
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> buildMatrix<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;Build the matrix of colors representing the board&quot;</span>
&nbsp;
        _im = <span style="color: #008000;">self</span>.<span style="color: black;">captureBoard</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> _row <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>Bwbot.<span style="color: black;">ROWS</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">for</span> _col <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>Bwbot.<span style="color: black;">COLS</span><span style="color: black;">&#41;</span>:
                _cx = <span style="color: black;">&#40;</span>_col <span style="color: #66cc66;">*</span> Bwbot.<span style="color: black;">SQUARE_WIDTH</span><span style="color: black;">&#41;</span> + Bwbot.<span style="color: black;">MID_SQUARE_WIDTH</span>
                _cy = <span style="color: black;">&#40;</span>_row <span style="color: #66cc66;">*</span> Bwbot.<span style="color: black;">SQUARE_HEIGHT</span><span style="color: black;">&#41;</span> + Bwbot.<span style="color: black;">MID_SQUARE_HEIGHT</span>
                _rect = <span style="color: black;">&#40;</span>_cx, _cy, _cx + <span style="color: #008000;">self</span>.<span style="color: black;">sample_size</span>, _cy + <span style="color: #008000;">self</span>.<span style="color: black;">sample_size</span><span style="color: black;">&#41;</span>
                _sample_im = _im.<span style="color: black;">crop</span><span style="color: black;">&#40;</span>_rect<span style="color: black;">&#41;</span>
&nbsp;
                <span style="color: #808080; font-style: italic;"># store only de predominant color</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">matrix</span><span style="color: black;">&#91;</span>_col<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>_row<span style="color: black;">&#93;</span> = <span style="color: #008000;">sorted</span><span style="color: black;">&#40;</span>_sample_im.<span style="color: black;">getcolors</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> evaluatePos<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, pos<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;Returns True if matrix contains a goal in the specified pos&quot;</span>
&nbsp;
        _col, _row = pos
        _val = <span style="color: #008000;">self</span>.<span style="color: black;">matrix</span><span style="color: black;">&#91;</span>_col<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>_row<span style="color: black;">&#93;</span>
&nbsp;
        _col_m1 = _col - <span style="color: #ff4500;">1</span> <span style="color: #808080; font-style: italic;"># col minus 1</span>
        _col_m2 = _col - <span style="color: #ff4500;">2</span> <span style="color: #808080; font-style: italic;"># col minus 2</span>
        _col_p1 = _col + <span style="color: #ff4500;">1</span> <span style="color: #808080; font-style: italic;"># col plus 1</span>
        _col_p2 = _col + <span style="color: #ff4500;">2</span> <span style="color: #808080; font-style: italic;"># col plus 2</span>
&nbsp;
        _row_m1 = _row - <span style="color: #ff4500;">1</span> <span style="color: #808080; font-style: italic;"># row minus 1</span>
        _row_m2 = _row - <span style="color: #ff4500;">2</span> <span style="color: #808080; font-style: italic;"># row minus 2</span>
        _row_p1 = _row + <span style="color: #ff4500;">1</span> <span style="color: #808080; font-style: italic;"># row plus 1</span>
        _row_p2 = _row + <span style="color: #ff4500;">2</span> <span style="color: #808080; font-style: italic;"># row plus 2</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># horizontal</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> _col_m1 <span style="color: #66cc66;">&gt;</span>= <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">and</span> _val == <span style="color: #008000;">self</span>.<span style="color: black;">matrix</span><span style="color: black;">&#91;</span>_col_m1<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>_row<span style="color: black;">&#93;</span>:
          <span style="color: #ff7700;font-weight:bold;">if</span> _col_m2 <span style="color: #66cc66;">&gt;</span>= <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">and</span> _val == <span style="color: #008000;">self</span>.<span style="color: black;">matrix</span><span style="color: black;">&#91;</span>_col_m2<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>_row<span style="color: black;">&#93;</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
          <span style="color: #ff7700;font-weight:bold;">elif</span> _col_p1 <span style="color: #66cc66;">&lt;</span> Bwbot.<span style="color: black;">COLS</span> <span style="color: #ff7700;font-weight:bold;">and</span> _val == <span style="color: #008000;">self</span>.<span style="color: black;">matrix</span><span style="color: black;">&#91;</span>_col_p1<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>_row<span style="color: black;">&#93;</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> _col_p2 <span style="color: #66cc66;">&lt;</span> Bwbot.<span style="color: black;">COLS</span> <span style="color: #ff7700;font-weight:bold;">and</span> _val == <span style="color: #008000;">self</span>.<span style="color: black;">matrix</span><span style="color: black;">&#91;</span>_col_p1<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>_row<span style="color: black;">&#93;</span> \
            <span style="color: #ff7700;font-weight:bold;">and</span> _val == <span style="color: #008000;">self</span>.<span style="color: black;">matrix</span><span style="color: black;">&#91;</span>_col_p2<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>_row<span style="color: black;">&#93;</span>:
          <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># vertical</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> _row_m1 <span style="color: #66cc66;">&gt;</span>=<span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">and</span> _val == <span style="color: #008000;">self</span>.<span style="color: black;">matrix</span><span style="color: black;">&#91;</span>_col<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>_row_m1<span style="color: black;">&#93;</span>:
          <span style="color: #ff7700;font-weight:bold;">if</span> _row_m2 <span style="color: #66cc66;">&gt;</span>= <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">and</span> _val == <span style="color: #008000;">self</span>.<span style="color: black;">matrix</span><span style="color: black;">&#91;</span>_col<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>_row_m2<span style="color: black;">&#93;</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
          <span style="color: #ff7700;font-weight:bold;">elif</span> _row_p1 <span style="color: #66cc66;">&lt;</span> Bwbot.<span style="color: black;">ROWS</span> <span style="color: #ff7700;font-weight:bold;">and</span> _val == <span style="color: #008000;">self</span>.<span style="color: black;">matrix</span><span style="color: black;">&#91;</span>_col<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>_row_p1<span style="color: black;">&#93;</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> _row_p2 <span style="color: #66cc66;">&lt;</span> Bwbot.<span style="color: black;">ROWS</span> <span style="color: #ff7700;font-weight:bold;">and</span> _val == <span style="color: #008000;">self</span>.<span style="color: black;">matrix</span><span style="color: black;">&#91;</span>_col<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>_row_p1<span style="color: black;">&#93;</span> \
            <span style="color: #ff7700;font-weight:bold;">and</span> _val == <span style="color: #008000;">self</span>.<span style="color: black;">matrix</span><span style="color: black;">&#91;</span>_col<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>_row_p2<span style="color: black;">&#93;</span>:
          <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># no goal                </span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> swap<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, pos1, pos2<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;Swap the values of pos1 and pos2 in the matrix&quot;</span>
&nbsp;
        _aux = <span style="color: #008000;">self</span>.<span style="color: black;">matrix</span><span style="color: black;">&#91;</span>pos1<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>pos1<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">matrix</span><span style="color: black;">&#91;</span>pos1<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>pos1<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">self</span>.<span style="color: black;">matrix</span><span style="color: black;">&#91;</span>pos2<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>pos2<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">matrix</span><span style="color: black;">&#91;</span>pos2<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>pos2<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> = _aux
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> tryMove<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, pos1, pos2<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;Simulates de move in the matrix and return True if there is a goal&quot;</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">swap</span><span style="color: black;">&#40;</span>pos1, pos2<span style="color: black;">&#41;</span>                                  <span style="color: #808080; font-style: italic;"># swap positions</span>
        _goal = <span style="color: #008000;">self</span>.<span style="color: black;">evaluatePos</span><span style="color: black;">&#40;</span>pos1<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #008000;">self</span>.<span style="color: black;">evaluatePos</span><span style="color: black;">&#40;</span>pos2<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># evaluate and</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">swap</span><span style="color: black;">&#40;</span>pos1, pos2<span style="color: black;">&#41;</span>                                  <span style="color: #808080; font-style: italic;"># restore matrix</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> _goal
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> play<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;plays the game during&quot;</span>
&nbsp;
        _tnow = _tini = <span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">while</span><span style="color: black;">&#40;</span>_tnow - _tini<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #008000;">self</span>.<span style="color: black;">playtime</span>:
            <span style="color: #008000;">self</span>.<span style="color: black;">buildMatrix</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">for</span> _row <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span>Bwbot.<span style="color: black;">ROWS</span><span style="color: black;">&#41;</span>:
                <span style="color: #ff7700;font-weight:bold;">for</span> _col <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span>Bwbot.<span style="color: black;">LAST_COL_INDEX</span><span style="color: black;">&#41;</span>:
                    <span style="color: #808080; font-style: italic;"># evaluating pos</span>
                    _pos1 = <span style="color: black;">&#40;</span>_col, _row<span style="color: black;">&#41;</span>
&nbsp;
                    <span style="color: #808080; font-style: italic;"># try swap right</span>
                    _pos2 = <span style="color: black;">&#40;</span>_col + <span style="color: #ff4500;">1</span>, _row<span style="color: black;">&#41;</span>
                    _goal = <span style="color: #008000;">self</span>.<span style="color: black;">tryMove</span><span style="color: black;">&#40;</span>_pos1, _pos2<span style="color: black;">&#41;</span>
&nbsp;
                    <span style="color: #808080; font-style: italic;"># if not goal, try swap down</span>
                    <span style="color: #ff7700;font-weight:bold;">if</span> _row <span style="color: #66cc66;">&lt;</span> Bwbot.<span style="color: black;">LAST_ROW_INDEX</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #ff7700;font-weight:bold;">not</span> _goal:
                        _pos2 = <span style="color: black;">&#40;</span>_col, _row + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
                        _goal = <span style="color: #008000;">self</span>.<span style="color: black;">tryMove</span><span style="color: black;">&#40;</span>_pos1, _pos2<span style="color: black;">&#41;</span>
&nbsp;
                    <span style="color: #808080; font-style: italic;"># if goal, do the move </span>
                    <span style="color: #ff7700;font-weight:bold;">if</span> _goal:
                        <span style="color: #008000;">self</span>.<span style="color: black;">dragJewel</span><span style="color: black;">&#40;</span>_pos1, _pos2<span style="color: black;">&#41;</span>
&nbsp;
            <span style="color: #808080; font-style: italic;"># time elapsed</span>
            _tnow = <span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
&nbsp;
    <span style="color: #dc143c;">parser</span> = argparse.<span style="color: black;">ArgumentParser</span><span style="color: black;">&#40;</span>description=<span style="color: #483d8b;">&quot;Bejeweled Blitz Bot.&quot;</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">parser</span>.<span style="color: black;">add_argument</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'x'</span>, <span style="color: #008000;">type</span>=<span style="color: #008000;">int</span>, nargs=<span style="color: #ff4500;">1</span>, \
        <span style="color: #008000;">help</span>=<span style="color: #483d8b;">'xpos of the Bejeweled Blitz board'</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">parser</span>.<span style="color: black;">add_argument</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'y'</span>, <span style="color: #008000;">type</span>=<span style="color: #008000;">int</span>, nargs=<span style="color: #ff4500;">1</span>, \
        <span style="color: #008000;">help</span>=<span style="color: #483d8b;">'ypos of the Bejeweled Blitz board'</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">parser</span>.<span style="color: black;">add_argument</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'--save'</span>, nargs=<span style="color: #ff4500;">1</span>, required=<span style="color: #008000;">False</span>, \
        <span style="color: #008000;">help</span>=<span style="color: #483d8b;">'capture de screen and saves it to a file'</span><span style="color: black;">&#41;</span>
    args = <span style="color: #dc143c;">parser</span>.<span style="color: black;">parse_args</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> args.<span style="color: black;">save</span>:        
        saveImage<span style="color: black;">&#40;</span>args.<span style="color: black;">save</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        bwb = Bwbot<span style="color: black;">&#40;</span>args.<span style="color: black;">x</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, args.<span style="color: black;">y</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        bwb.<span style="color: black;">play</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<h3>Requisites and Limitations</h3>
<ul>
<li>Phyton 2.7 (<a href="http://python.org/download/">http://python.org/download/</a>)</li>
<li>Phyton Imaging Library 1.1.7 <a href="https://docs.google.com/document/edit?id=1o-1XXWMraXx9QiqYt5LJ-djtSrCmEGnTHZspaD7AN4o&amp;hl=es&amp;pli=1">(http://effbot.org/downloads/#pil)</a></li>
<li>PyWin32 <a href="https://docs.google.com/document/edit?id=1o-1XXWMraXx9QiqYt5LJ-djtSrCmEGnTHZspaD7AN4o&amp;hl=es&amp;pli=1">(http://sourceforge.net/projects/pywin32/files/)</a></li>
<li>The script only works under Windows and I have only try it with a true color definition screen.</li>
</ul>
<h3>Future improvements and ToDo List</h3>
<p>My only intention was to beat my friends, something that I successfully did. My hi-score is now over 1.000.000 points, much more than any human player could even dream. But the script is far to be perfect. It lacks of a more efficient evaluation routine that selects the best move at each moment, choosing a 5-in-a-row move before the others for example. Another important defect is its inability to detect multipliers and other special jewels.</p>
<p>I am not planning to improve the script, but if you want to improve it, I will appreciate that you email me, just to know how the script evolves.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nanomuelle.com/2010/10/21/how-i-beat-bejeweled-blitz/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Snippet: Recursively Remove .svn Directories in Linux</title>
		<link>http://blog.nanomuelle.com/2010/01/29/snippet-recursively-remove-svn-directories-in-linux/</link>
		<comments>http://blog.nanomuelle.com/2010/01/29/snippet-recursively-remove-svn-directories-in-linux/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 23:24:55 +0000</pubDate>
		<dc:creator>nanomuelle</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://blog.nanomuelle.com/?p=309</guid>
		<description><![CDATA[Just a couple of snippets found in the net to make my life easier. In the first one beware of the grave accent quotes. rm -rf `find . -type d -name .svn` or someone else proposed find ./ -name .svn &#124; xargs rm -fr]]></description>
			<content:encoded><![CDATA[<p>Just a couple of snippets found in the net to make my life easier.<br />
In the first one beware of the grave accent quotes.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> d <span style="color: #660033;">-name</span> .svn<span style="color: #000000; font-weight: bold;">`</span></pre></div></div>

<p>or someone else proposed</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-name</span> .svn <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-fr</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.nanomuelle.com/2010/01/29/snippet-recursively-remove-svn-directories-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Snippet: PHP Calling static class methods</title>
		<link>http://blog.nanomuelle.com/2009/12/01/snippet-php-calling-static-class-methods/</link>
		<comments>http://blog.nanomuelle.com/2009/12/01/snippet-php-calling-static-class-methods/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 10:57:03 +0000</pubDate>
		<dc:creator>nanomuelle</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[static]]></category>

		<guid isPermaLink="false">http://blog.nanomuelle.com/?p=284</guid>
		<description><![CDATA[Given the example class foo: class foo &#123; public static function myFunc&#40;&#41; &#123; return &#34;foo - myFunc&#34;; &#125; &#125; The class name is known in the calling context: echo foo::myFunc&#40;&#41;; The class name is stored in a php var: $class_name = &#34;foo&#34;; &#160; /** PHP 5.2.x */ echo call_user_func&#40;array&#40;$class_name, &#34;myFunc&#34;&#41;&#41;; &#160; /** PHP 5.3.x */ [...]]]></description>
			<content:encoded><![CDATA[<p>Given the example class foo:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> foo <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> myFunc<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;foo - myFunc&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The class name is known in the calling context:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #b1b100;">echo</span> foo<span style="color: #339933;">::</span><span style="color: #004000;">myFunc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The class name is stored in a php var:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000088;">$class_name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;foo&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/** PHP 5.2.x */</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #990000;">call_user_func</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$class_name</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;myFunc&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
&nbsp;
  <span style="color: #009933; font-style: italic;">/** PHP 5.3.x */</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$class_name</span><span style="color: #339933;">::</span><span style="color: #004000;">myFunc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>More info on <strong>call_user_func</strong>: <a href="http://es.php.net/manual/en/function.call-user-func.php">http://es.php.net/manual/en/function.call-user-func.php</a><br />
More info on <strong>static keyword</strong>: <a href="http://es.php.net/manual/en/language.oop5.static.php">http://es.php.net/manual/en/language.oop5.static.php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nanomuelle.com/2009/12/01/snippet-php-calling-static-class-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Snippet: sfWidgetFormJQueryDate for Spanish culture</title>
		<link>http://blog.nanomuelle.com/2009/11/16/snippet-sfwidgetformjquerydate-for-spanish-culture/</link>
		<comments>http://blog.nanomuelle.com/2009/11/16/snippet-sfwidgetformjquerydate-for-spanish-culture/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 10:47:38 +0000</pubDate>
		<dc:creator>nanomuelle</dc:creator>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://blog.nanomuelle.com/?p=257</guid>
		<description><![CDATA[Be sure that sfFormExtraPlugin is installed: $ php symfony plugin:install sfFormExtraPlugin In the template: &#60;?php use_javascript&#40;'ui/i18n/jquery-ui-i18n.js'&#41; ?&#62; In the filter or form: $this-&#62;widgetSchema&#91;'my_date_field'&#93; = new sfWidgetFormJQueryDate&#40;array&#40; 'culture' =&#62; 'es', 'format' =&#62; '%day%/%month%/%year%', 'config' =&#62; '{&#34;showMonthAfterYear&#34;: false, &#34;firstDay&#34;: 1 }' &#41;&#41;; More info on &#8216;config&#8217; option in http://jqueryui.com/demos/datepicker.]]></description>
			<content:encoded><![CDATA[<ol>
<li>
<p>Be sure that sfFormExtraPlugin is installed:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ php symfony plugin:<span style="color: #c20cb9; font-weight: bold;">install</span> sfFormExtraPlugin</pre></div></div>

</li>
<li>
<p>In the template:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> use_javascript<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ui/i18n/jquery-ui-i18n.js'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</li>
<li>
<p>In the filter or form:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'my_date_field'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormJQueryDate<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'culture'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'es'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'format'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'%day%/%month%/%year%'</span><span style="color: #339933;">,</span> 
      <span style="color: #0000ff;">'config'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'{&quot;showMonthAfterYear&quot;: false, &quot;firstDay&quot;: 1 }'</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
</ol>
<p>More info on &#8216;config&#8217; option in <a href="http://jqueryui.com/demos/datepicker" target="blank">http://jqueryui.com/demos/datepicker</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nanomuelle.com/2009/11/16/snippet-sfwidgetformjquerydate-for-spanish-culture/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

