python - Connect 4 error in logic -


am trying implement connect4 game in python.

for game logic start checking each point in possible directions if there 4 dots in row. logic checks until 3 dots in row. can please explain doing wrong?

i think doing wrong in recursion.

the code have developed until follows:

#function ckeck if game on def checkwin(row,col):     r = row     c = col     #print r,c     return checkwinfromcell(r,c)  #function ckeck if game on current cell def checkwinfromcell(row, col):         directions = [[0,1], [1,0], [1,1], [1,-1], [0,-1], [-1,0], [-1,-1], [-1,1]]         d in directions:             canvas.data.temp = [(row,col)]             n=1             finalcheck(row,col,d,n)             #print canvas.data.temp             if (len(canvas.data.temp) == 4):                 return true  #function ckeck if game on current cell in #all possible directions def finalcheck(row, col, direction,n):         drow, dcol = direction[0], direction[1]         ddrow = row+drow #next row check         ddcol = col+dcol #next col check         #boundary checks         if row < 0 or row>=canvas.data.rows or col < 0 or col >=canvas.data.cols:             return false         #boundary checks         if ddrow < 0 or ddrow>=canvas.data.rows or ddcol < 0 or ddcol >=canvas.data.cols:             return false         #if same color add list         #print canvas.data.board[row][col]         #print canvas.data.board[ddrow][ddcol]         if(canvas.data.board[row][col] ==  canvas.data.board[ddrow][ddcol]):             canvas.data.temp.append((ddrow,ddcol))         else:             return false         #call 3 more times recursively check if 4 connected         while(n<3):             n += 1             #print str(n)+" "+str(ddrow)+" "+str(ddcol)             #print direction             finalcheck(ddrow,ddcol,direction,n) 

ps : delete checkwin function nothing.

pps : tried asking same question, think not clear in question. think have tried in better way time.

        while(n<3):         n += 1         #print str(n)+" "+str(ddrow)+" "+str(ddcol)         #print direction         finalcheck(ddrow,ddcol,direction,n) 

you want n <= 3 or n < 4


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -