title: Python Matrix check for diagonals and horizontals correctly to win a game
body: <p>I'm building a game like Connect4 the user can connect any number. I am having a problem checking the horizontal and diagonals lines:</p>
  <pre><code>def WinningSequenceCheck(board,piece,row_count):
      #Horizontal Check
      piecePlayer1=0
      piecePlayer2=0
      win_sequence=board[0][&quot;TamanhoSequência&quot;]
      width=board[0][&quot;CumpGrelha&quot;]
      height=row_count
  
      for c in range(height+1):
          for r in range(width):
              if board[0][&quot;Tabuleiro&quot;][c][r]==1:
                  piecePlayer1+=1
                  if piecePlayer1==win_sequence:
                      return True                    
              if board[0][&quot;Tabuleiro&quot;][c][r]==2:
                  pecasPlayer2+=1
                  if pecasPlayer2==win_sequence:
                      return True
  
  #For diagonals i did this:
      diag1=0
      diag2=0
      a=0
      b=height
      d=0
      for c in range(width):
          for l in range(height+1):
              if board[0][&quot;Tabuleiro&quot;][b-l][l+a]==1:
                  diag1+=1
                  if diag1==win_sequence:
                      return True                    
              if board[0][&quot;Tabuleiro&quot;][b-l][l+a]==2:
                  diag2+=1
                  if diag2==win_sequence:
                      return True
              if (b-l&lt;height):
                  b=height
                  if l&lt;=l-1:
                      a=a
                  elif(a+l&lt;width-1):
                      a+=1 
                  elif(a+l&lt;=width-1):
                      return        
                  else:
                      break 
  </code></pre>
  <p>The problem with diagonals is that it goes from left to right but it's not checking properly if there is a line of a winning sequence of 1s or 2s
  If it finds it should return true because im incrementing each time he finds 1 or 2</p>
  <p>Im i doing the horizontal check properly?
  Is there a better way to check in diagonals ?</p>
  <p>The expected result from the horizontal is that if it finds the number 1 it adds to the variable piecePlayer1 (for the player 1)
  If the piecePlayer1 is equal to Victory sequence ( example victory sequence is 5) the game returns true because in one of the lines he found 5 one's .</p>
  <pre><code>Winning Sequence=5
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  [1, 1, 1, 1, 1, 0, 0, 0, 0, 0] ---&gt; Win
  </code></pre>
  <p>The same is for the diagonal check:</p>
  <pre><code>Winning Sequence =4
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  [0, 0, 0, 1, 0, 0, 0, 0, 0, 0] Diagonal WIN
  [0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
  [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
  [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  </code></pre>