Beispiel #1
0
def evalAddTile(par_grid: GGL.gameGridLight, deep: int):
    if deep == 0:
        return par_grid.getScore()

    scores = []
    for x in range(par_grid.columns):
        for y in range(par_grid.rows):
            if not par_grid.canAddTile(x, y):
                continue
            for tileToAdd in [2, 4]:
                loc_grid = par_grid.clone()
                loc_grid.addTile(x, y, tileToAdd)
                _, score = evalMoveTo(loc_grid, deep)  # Yes, keep same deep here.
                scores.append(score)

    arrayScores = np.array(scores)
    avgScore = arrayScores.mean()
    return avgScore
Beispiel #2
0
def evalAddTile(par_grid: GGL.gameGridLight, deep: int):
    if deep == 0:
        return par_grid.getScore()
#    print("evalAddTile Deep " + str(deep))

    scores = np.zeros(2 * par_grid.rows * par_grid.columns) + 1000000000  # + inf
    for x in range(par_grid.columns):
        for y in range(par_grid.rows):
            if not par_grid.canAddTile(x,y):
                continue
            for tileToAdd in [2,4]:
#                print("Add tile {0} at ({1}, {2})".format(tileToAdd, x, y))
                loc_grid = par_grid.clone()
                loc_grid.addTile(x, y, tileToAdd)
#                print("Matrix")
                _, score = evalMoveTo(loc_grid, deep) # Yes, keep same deep here.
#                print("Add tile {0} at ({1}, {2}) => {3} pts".format(tileToAdd, x, y, score))

                index = coord_to_index(loc_grid, x, y, tileToAdd)
                scores[index] = score

    # min score : suppose the added tile is at the worst position
#    print( scores )
    return scores.min()