Board game, piece movement
<p>I'm programming a board game where pieces can move horizontally, vertically and diagonally on a 10x10 board that has coordinates like Battleship. (a1,a2,a3,...j7,j8,j9). The pieces can't move over other pieces so I created a function to check this. The funcion parameters are: </p>

<ul>
<li>board: list with coordinates of cells occupated that changes throughout the game. Ex: board = ['a3','a5','h6']</li>
<li>intial_position: it's the coordinate of the piece the player is about to move</li>
<li>final_position: coordinate of wanted position.      </li>
</ul>

<p>Now, I made a function to convert a coordinate (string) into a list with the real x-y coordinates of the array (a10 = [0,0] , b10 = [0,1] , c9 = [1,2]) so I can create loops. And also there is a list with all the alphanumeric coordinates so I can go back to the string. Ex. L[0][0] = 'a10' , L[1][2] = 'c9'.</p>

<p>The code for vertical move is:</p>

<pre><code>def validate_movement(board,initial_position,final_position):
    invalid = 0
    a = get_coordinate(initial_position)
    b = get_coordinate(final_position)
    for i in range(3): 
        if final_position in board[i]:
            invalid += 1
        else:
            invalid += 0
        if a[0] != b[0] and a[1] == b[1]:
            if b[0] &gt; a[0]:
                for n in range(a[0],b[0]):
                    if L[n][a[1]] in board[i]:
                        invalid += 1
                    else:
                        invalid += 0
            else:
                for n in range(b[0],a[0]):
                    if L[n][a[1]] in board[i]:
                        invalid += 1
                    else:
                        invalid += 0
</code></pre>

<p>I'm really struggling with the function that checks diagonal moves. Hope you can help me with it, I know my code is really primitive but I'd like you to stick with the same logic so I can understand.</p>

<p>I've tried this:</p>

<pre><code>             if  (b[1] - a[1])//(b[0] - a[0]) == 1:
                 while a[0] != b[0] and a[1] != b[1]:
                     a[0] += 1
                     a[1] += 1
                     if L[a[0]][a[1]] in board:
                         invalid += 1
                     else:
                         invalid += 0
</code></pre>

<p>This would be for a case where a = [0,0] and b = [2,2], for example, but it gives me ZeroDivisionError.</p>