PyGameExamplesAndAnswers

StackOverflow            reply.it reply.it

Grid

Related Stack Overflow quest

Draw grid

Related Stack Overflow quest

Performance and lag

Related Stack Overflow quest

Position in grid, grid index

Related Stack Overflow quest

Click in grid

Related Stack Overflow quest

Diagonal

Related Stack Overflow quest

Move in grid

Related Stack Overflow quest

Drag in grid

Related Stack Overflow quest

Chess board, checker texture

Related Stack Overflow quest

Grid an NumPy

Related Stack Overflow quest

import numpy

board = [
    ["bR", "bN", "bB", "bQ", "bK", "bB", "bN", "bR"],
    ["bp", "bp", "bp", "bp", "bp", "bp", "bp", "bp"],
    ["--", "--", "--", "--", "--", "--", "--", "--"],
    ["--", "--", "--", "--", "--", "--", "--", "--"],
    ["--", "--", "--", "--", "--", "--", "--", "--"],
    ["--", "--", "--", "--", "--", "--", "--", "--"],
    ["wp", "wp", "wp", "wp", "wp", "wp", "wp", "wp"],
    ["wR", "wN", "wB", "wQ", "wK", "wB", "wN", "wR"]
]

values, indices = numpy.unique(board, return_inverse=True)
indices = indices.reshape((8, 8))

print(values, '\n')
print(indices)

lookup = {
    "--": 0,
    "wK": 1, "wQ": 2, "wR": 3, "wB": 4, "wN": 5, "wp": 6,
    "bK": 7, "bQ": 8, "bR": 9, "bB": 10, "bN": 11, "bp": 12 
}
indices = numpy.array([[lookup[p] for p in row] for row in board])

print(indices)