Validate destinations of a piece in a board game
Yes, you can simplify the implementation of your algorithm by introducing the notion of direction, like you find in mathematics…

In Djanbi game, a token can move in 8 directions. You can define a vector d(d_x, d_y) which defines this notion of direction:


North: d = (0, 1),
East: d = (1, 0),
South: d = (0, -1),
West: d = (-1, 0),
North-East: d = (1, 1),
South-East: d = (1, -1),
North-West: d = (-1, 1),
South-West: d = (-1, -1).


First you can define the Point tuple to simplify coding:

import collections

Point = collections.namedtuple('Point', 'x y')


Then, you can use this named tuple to construct all possible directions:

import itertools

directions = [
    Point(*coord) for coord in itertools.product([-1, 0, 1], [-1, 0, 1])
]
directions.remove(Point(0, 0))


You get:

[Point(x=-1, y=-1), Point(x=-1, y=0), Point(x=-1, y=1), Point(x=0, y=-1), Point(x=0, y=1), Point(x=1, y=-1), Point(x=1, y=0), Point(x=1, y=1)]


For each direction, you can search for the possible moves. But before you need to calculate the next position of a token in a given direction. You can use a simple generator for that:

def next_pos(p, d):
    p0 = p
    while 0 &lt;= p.x &lt; 9 and 0 &lt;= p.y &lt; 9:
        if p != p0:
            yield Point(p.x, p.y)
        p = Point(p.x + d.x, p.y + d.y)


Then you can loop as follow:

# coordinates of the position of the chip
chip = Point(2, 4)

for direction in directions:
    print('In the direction: {0}'.format(direction))
    for pos in next_pos(chip, direction):
        ...


Here, pos is a Point instance that you can use to check if a position is valid…