3 ### BEGIN CONFIGURATION SECTION ###
5 RESOLUTION
= (1024,768)
7 # which SIZE of the visible area?
10 # how many TRIALS per round (MINimum)
13 # LENGTH of STimulus presentation in seconds
16 # LENGTH of Break between Trials in seconds
19 # which N-back initially?
22 # UPPER ThresHold, above which N is increased
25 # LOWER ThresHold, below which N is decreased
36 IFS
= ['1.png','2.png','3.png','4.png','5.png','6.png','7.png','8.png']
37 SFS
= ['1.ogg','2.ogg','3.ogg','4.ogg','5.ogg','6.ogg','7.ogg','8.ogg']
38 BASE
= IFDIR
+"/"+'base.png'
40 ### END CONFIGURATION SECTION ###
42 TOPLEFT
=((RESOLUTION
[0]-SIZE
[0])/2,(RESOLUTION
[1]-SIZE
[1])/2)
44 for i
in range(0,len(IFS
)):
45 IFS
[i
]=IFDIR
+"/"+IFS
[i
]
46 SFS
[i
]=SFDIR
+"/"+SFS
[i
]
51 from random
import randint
52 from pygame
import display
, image
, key
, Surface
, mixer
, event
, mouse
, font
53 from pygame
import FULLSCREEN
, KEYDOWN
54 from pygame
.transform
import scale
57 print "Running some selftests"
59 # do some preloading to minimize lag blow
60 for f
in IFS
+SFS
+[BASE
]:
65 print >> sys
.stderr
, "FATAL:",die
69 if not len(IFS
) == len(SFS
):
70 print >> sys
.stderr
, "FATAL: amount of stimuli for different modalities do not match!"
72 print "All data present, great!"
76 def __init__(self
,imagefile
,soundfile
,trgtimg
,trgtsnd
):
77 self
.image
= scale(image
.load(imagefile
), SIZE
).convert()
78 self
.fill
= scale(image
.load(BASE
),SIZE
).convert()
79 self
.sound
= mixer
.Sound(soundfile
)
80 self
.trgtimg
= trgtimg
81 self
.trgtsnd
= trgtsnd
82 self
.result
= [not(self
.trgtimg
),not(self
.trgtsnd
)]
85 surface
= display
.get_surface()
86 surface
.fill((255,255,255))
87 surface
.blit(self
.image
,TOPLEFT
)
91 surface
.blit(self
.fill
,TOPLEFT
)
95 for e
in event
.get(KEYDOWN
):
96 keypresses
+= [e
.dict['unicode']]
97 if SPACE
in keypresses
:
99 if unicode(KEYLEFT
) in keypresses
:
101 #print "user hit key \""+ KEYLEFT +"\" correctly"
102 self
.result
[0] = True
104 #print "user hit key \""+ KEYLEFT +"\" incorrectly"
105 self
.result
[0] = False
106 if unicode(KEYRIGHT
) in keypresses
:
108 #print "user hit key \""+ KEYRIGHT +"\" correctly"
109 self
.result
[1] = True
111 #print "user hit key \""+ KEYRIGHT +"\" incorrectly"
112 self
.result
[1] = False
118 result
.append(l
[randint(0,len(l
)-1)])
119 for i
in range(0,MINTRIALS
):
121 result
.append(result
[-N
])
123 # be strict about probabilities
126 result
.append(myl
[randint(0,len(myl
)-1)])
131 iis
= myrandom(range(0,len(IFS
)-1))
132 sis
= myrandom(range(0,len(SFS
)-1))
133 for i
,j
,k
in zip(iis
,sis
,range(0,len(iis
))):
135 trials
.append(Trial(IFS
[i
],SFS
[j
],False,False))
138 trials
.append(Trial(IFS
[i
],SFS
[j
],iis
[k
]==iis
[nb
],sis
[k
]==sis
[nb
]))
143 spam
= raw_input(" [Yes/No]? ")
144 if re
.match("y(es)?", spam
, re
.I
):
146 elif re
.match("n(o)?", spam
, re
.I
):
151 print "### Welcome to TrainBwister ###"
152 print "####### Version 0.1beta #######"
153 print """Have a look at the sourcecode!
154 Change stuff to suit your needs!
155 The program will hopefully be
156 self explaining. Hafe fun!"""
161 print "(Hint: while training, you can hit SPACE to abort)"
162 print "Hit '"+KEYLEFT
+"' if the",str(N
)+". previous image is identical to the one shown"
163 print "Hit '"+KEYRIGHT
+"' if the",str(N
)+". previous sound is identical to the one heard"
165 print "Ready to train with N=%i?" %(N),
169 print "Do you wish to train with N set to a different value? Choosing 'No' exits the program.",
171 n
= int(raw_input("Ok, enter the desired value here: "))
173 print "N must be 1 or higher!"
174 n
= int(raw_input("Enter a value higher than 1: "))
181 display
.set_mode(RESOLUTION
, FULLSCREEN
)
185 mouse
.set_visible(False)
188 if not trial
.runtrial():
198 vp
= (vis
/(MINTRIALS
+N
))*100
199 ap
= (acu
/(MINTRIALS
+N
))*100
200 message
= "percentage in visual modality:%i\npercentage in acoustic modality:%i\n" %(int(vp
),int(ap
))
202 if vp
>= UPPERTH
and ap
>= UPPERTH
:
204 elif (vp
< LOWERTH
or ap
< LOWERTH
) and N
> 1:
207 if __name__
== "__main__":