def test_against_dumb_move_2(self): """Take from a real gameplay scenarios where a fatal wrong move was made: starting position: 128 32 8 4 32 2 128 16 0 2 8 8 0 4 4 8 position after going down (which should not be the preferred choice) 0 0 8 0 0 32 128 4 128 4 8 16 32 4 4 16 """ p = PlayerAI() g1 = self.create_slowgrid_from_list([[128, 32, 8, 4], [32, 2, 128, 16], [0, 2, 8, 8], [0, 4, 4, 8]]) m = p.getMove(g1) self.assertNotEqual(m, DOWN, 'should not have chosen move Down')
def test_against_dumb_move_1(self): """Take from a real gameplay scenarios where a fatal wrong move was made: Computer's turn: 256 32 128 2 4 16 16 64 32 4 2 2 4 0 4 4 Player's Turn:DOWN (should have been RIGHT) 256 0 128 2 4 32 16 64 32 16 2 2 4 4 4 4 RIGHT: [ [256, 32, 128, 2], [0, 4, 32, 64], [0, 32, 4, 4], [0, 0, 4, 8] ] """ p = CompositeCalculation.CompositeUtilityCalculator() gstart = self.create_fastgrid_from([256, 32, 128, 2, 4, 16, 16, 64, 32, 4, 2, 2, 4, 0, 4, 4]) gDOWN = self.create_fastgrid_from([256, 0, 128, 2, 4, 32, 16, 64, 32, 16, 2, 2, 4, 4, 4, 4]) ustart = p.compute_utility(gstart) udown = p.compute_utility(gDOWN) self.assertGreater(ustart, udown) gright = gstart.clone() gright.move(RIGHT) uright = p.compute_utility(gright) self.assertGreater(uright, udown) available_moves = gstart.moves self.assertNotEquals(1, len(available_moves)) p1 = PlayerAI() suggestedMove = p1.getMove(gstart.to_slowgrid()) self.assertNotEquals(suggestedMove, DOWN)
def test_against_dumb_move_3(self): """Take from a real gameplay scenarios where a fatal wrong move was made: Computer's turn: 32 16 32 2 4 16 4 2 4 2 8 2 2 4 8 2 Player's Turn:DOWN (should have been UP) 0 0 0 0 32 32 32 0 8 2 4 4 2 4 16 4 UP would have been: 32 32 32 4 8 2 4 4 2 4 16 0 0 0 0 0 """ p = PlayerAI() gstart = self.create_fastgrid_from([32, 16, 32, 2, 4, 16, 4, 2, 4, 2, 8, 2, 2, 4, 8, 2]) ok, gdown = gstart.move(DOWN) ok, gup = gstart.move(UP) ce = CompositeUtilityCalculator() ustart = ce.compute_utility(gstart) udown = ce.compute_utility(gdown) uup = ce.compute_utility(gup) self.assertGreater(ustart, udown) self.assertGreater(uup, udown, "the UP move should have a higher score than the DOWN move") available_moves = gstart.moves self.assertNotEquals(1, len(available_moves), "there are two options (UP or DOWN)") chosen_move = p.getMove(gstart.to_slowgrid()) self.assertNotEquals(chosen_move, DOWN, "down is the inferior move, and should not have been chosen")