コード例 #1
0
ファイル: ABTestingBase.py プロジェクト: RudraNilBasu/edx_AI
 def create_slowgrid_from_list(self, l, size=4) -> FastGrid:
     sut = Grid()
     sut.map = l
     sut.size = size
     return sut
コード例 #2
0
from random import randint
from BaseAI_3 import BaseAI
from Grid_3 import Grid
from PlayerAI_3 import PlayerAI

grid = Grid()
grid.map = [[4, 64, 8, 4], [32, 8, 64, 8], [256, 512, 32, 4], [4, 8, 4, 2]]

moves = [1, 2, 3, 4]
print(moves)
moves[2] = 7
print(moves)

print(len(grid.getAvailableCells()))
print(grid.map)
print(PlayerAI.is_state_terminal(grid, 'min'))
                current_value = self.__log2(grid.map[row][current_col])
                next_value = self.__log2(
                    grid.map[row][grid.size -
                                  1 if next_col == grid.size else next_col])

                if (current_value < next_value):
                    monotonicity[RIGHT] += current_value - next_value
                else:
                    monotonicity[LEFT] += next_value - current_value

                current_col = next_col

        return max(monotonicity[UP], monotonicity[DOWN]) + max(
            monotonicity[LEFT], monotonicity[RIGHT])


if __name__ == '__main__':
    from PlayerAI_3 import PlayerAI
    from Grid_3 import Grid

    player_ai = PlayerAI()
    grid = Grid()

    grid.map = [[0, 0, 2, 4], [0, 0, 2, 4], [0, 2, 2, 2], [0, 2, 2, 1024]]
    # Test case for PlayerAI.__maximize:
    utility = player_ai._PlayerAI__maximize(grid, 3, 0, 0)
    print("[Maximized Utility]: {}".format(utility))
    # Test case for PlayerAI.__eval:
    utility = player_ai._PlayerAI__eval(grid)
    print("[Utility]: {}".format(utility))
コード例 #4
0
 def to_slowgrid(self):
     g = Grid()
     g.map = Util.array_to_2dlist(self.board)
     return g
コード例 #5
0
ファイル: PlayerAI_3.py プロジェクト: luoweimeng/2048-Game
    def find_next(self, m, i, j, right=True):
        if right:
            j = j + 1
            while j < self.grid.size and m[i, j] == 0:
                j += 1
            return m[i, j] if j < self.grid.size else None
        else:
            i = i + 1
            while i < self.grid.size and m[i, j] == 0:
                i += 1
            return m[i, j] if i < self.grid.size else None


if __name__ == '__main__':
    g = Grid()
    g.map = [[4, 0, 0, 0], [64, 16, 4, 0], [256, 128, 32, 8],
             [512, 256, 64, 16]]
    displayer = Displayer()
    displayer.display(g)
    s = State(g, 2, 0, None, 0, 0)
    print(s.smoothness())

    print(s.eval())
    testAI = PlayerAI()
    print(actionDic[testAI.getMove(g)])
    g.move(3)
    displayer.display(g)
    s1 = State(g, 2, 0, None, 0, 0)
    print(s1.eval())
    # for child in s.get_children_min():
    #     print(child.grid.map)