Initial state of images are not getting recognized

Hello! I’m trying to create an experiment which is similar to puzzle. There will be an images grid(attached below) with images already present in the grid, the task is to rearrange the images to make it into a correct order. I’m able to do it but the problem is when the user doesn’t click/press an image then it’s not getting recognized. Example in the image all the images are in correct order in this case the user simple press continue to evaluate the order but it is predicting as Incorrect even though the order is correct. What could be the ideal way to tackle this?

Begin Exp:
def drawPicked(picked):
for each in picked:

def movePicked(picked, mouse, grabbed):
if grabbed is not None and mouse.isPressedIn(grabbed):
grabbed.pos = mouse.getPos()
return grabbed
for piece in picked:
if mouse.isPressedIn(piece) and grabbed is None:
return piece

def createGrid(rows, cols, size, pos, names):
rinc = (size/rows)
cinc = (size/cols)
rowStart = pos[0] - size/2
colStart = pos[1] + size/2
row, col = rowStart + rinc/2, colStart - cinc/2
counter = 0
grid =
for i in range(rows):
for j in range(cols):
grid.append(visual.Rect(win, name=names[counter], units=‘norm’, size = [size/rows, size/cols], pos= [row,col], lineColor= ‘white’))
row += rinc
counter += 1
col -= cinc
row = rowStart + rinc/2
return grid

def drawGrid(grid):
for i in grid:

def checkAnswer(grid, pieces):
picNames = [pic.image for pic in pieces]
correctPieces =
for cell in grid:
if in picNames:
for name in range(0, len(picNames)):
if == picNames[name]:
if cell.contains(pieces[name].pos):
return False
return len(correctPieces) == len(grid)

Begin Routine:
pieces = [img1, img2, img3, img4,img5, img6, img7, img8,img9, img10, img11, img12, img13, img14, img15, img16]
answers = [a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16]
picked =
newPiece = None
movingPiece = None
grid = createGrid(nRows1,nCols1, size, polygon.pos, answers)

Each Frame:
for piece in pieces:
if mouse.isPressedIn(piece) and newPiece == None:
newPiece = piece

if newPiece is not None and mouse.getPressed()[0] == 0:
newPiece = None

movingPiece = movePicked(picked, mouse, movingPiece)

End Routine:
correctA = checkAnswer(grid, picked)

Any leads will be appreciated!

I guess this is because your picked list is initialized as empty. This list is also passed to the checkAnswer function in the End routine. The logic of the checkAnswer function assumes that there are elements in the picked list to make a proper validation.

Maybe the fastest way is to build in a special clause in the validation function when the picked list is empty. Personally, I would go for an approach where I have two lists: currentOrder and correctOrder. If a piece is moved I would update the currentOrder list so that the only thing the validation functions needs to do is compare if these two lists are equal.


Thank you for the suggestion. I updated the picked list to the initial images. It worked!