Esempio n. 1
0
def solve():
    selected_level = levels_menu()
    algorithm, heuristic = algorithms_menu()

    board_matrix, max_touches = utils.read_level_file(selected_level)
    board = Board(board_matrix)

    game_state = GameState(board, max_touches)

    print_header(game_state)
    utils.print_board(game_state.board)

    start_time = time.time()
    solution = algorithm.execute(game_state, heuristic)
    end_time = time.time()
    total_time = round(end_time - start_time, 2)

    for move in solution:
        move_row, move_col = move
        game_state.update_board(move_row, move_col)
        print("Move: [", move_row, ",", move_col, "]")
        print_header(game_state)
        utils.print_board(game_state.board)

    if game_state.result == GameResults.Win:
        print("**** You Won! ****")
    else:
        print("**** You Lost! ****")

    print("\nSolved in ", total_time, " seconds", sep="")
    print()
Esempio n. 2
0
    def test_update_board_no_changes(self):
        curr_board = Board([[1, 0, 2, 0], [0, 0, 1, 1], [1, 1, 2, 2],
                            [0, 1, 0, 1]])
        game_state = GameState(curr_board, 1)
        game_state.update_board(0, 1)

        assert game_state.board == curr_board
        assert game_state.result == None
Esempio n. 3
0
    def test_valid_moves_no_touches_left(self):
        # level 7
        board = Board([[0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [1, 2, 1, 2, 1],
                       [0, 2, 0, 2, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0]])

        game_state = GameState(board, 0)

        expected = []

        assert game_state.valid_moves() == expected
Esempio n. 4
0
    def __init__(self, game_info):
        GameState.__init__(self, GameState.STATE_LOAD, GameState.STATE_GAME)

        self.game_info = game_info
        self.text_helper = TextHelper()

        self.load_screen_time = -1
        # Mario frame
        sprite_sheet = SpriteSheet("data/characters.gif")
        self.mario_frame = sprite_sheet.get_image(coords.MARIO_SMALL_STANDING_RIGHT, c.IMG_MULTIPLIER)
Esempio n. 5
0
    def test_update_board_single_red_bubble(self):
        empty_board = Board()
        curr_board = Board([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0],
                            [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])

        game_state = GameState(curr_board, 1)
        game_state.update_board(2, 2)

        assert game_state.board == empty_board
        assert game_state.result == GameResults.Win
Esempio n. 6
0
    def test_update_board_multiple_red_bubbles(self):
        empty_board = Board()
        curr_board = Board([[1, 0, 1, 0, 1], [0, 0, 0, 0, 0], [1, 0, 1, 0, 1],
                            [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 0, 1, 0, 1]])

        game_state = GameState(curr_board, 1)
        game_state.update_board(0, 0)

        assert game_state.board == empty_board
        assert game_state.result == GameResults.Win
Esempio n. 7
0
 def test_singleton(self):
     a = GameState()
     b = GameState()
     assert id(a) == id(b)
     a.update_coins(Team.ALLY.value, 5)
     assert b.get_ally_coins() == 5
     a.update_coins(Team.ALLY.value, -5)
Esempio n. 8
0
    def test_valid_moves(self):
        # level 7
        board = Board([[0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [1, 2, 1, 2, 1],
                       [0, 2, 0, 2, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0]])

        game_state = GameState(board, 2)

        expected = [(1, 1), (1, 3), (2, 0), (2, 1), (2, 2), (2, 3), (2, 4),
                    (3, 1), (3, 3), (4, 1), (4, 3)]

        assert game_state.valid_moves() == expected
Esempio n. 9
0
    def __init__(self, game_info):
        GameState.__init__(self, GameState.STATE_LOAD, GameState.STATE_GAME)

        self.game_info = game_info
        self.text_helper = TextHelper()

        self.load_screen_time = -1
        # Mario frame
        sprite_sheet = SpriteSheet("data/characters.gif")
        self.mario_frame = sprite_sheet.get_image(
            coords.MARIO_SMALL_STANDING_RIGHT, c.IMG_MULTIPLIER)
Esempio n. 10
0
    def test_update_board_level_18(self):
        expected_board = Board()

        curr_board = Board([[0, 3, 2, 4, 0], [1, 1, 1, 2, 0], [0, 1, 4, 1, 2],
                            [0, 4, 2, 0, 1], [1, 1, 1, 2, 2], [0, 4, 0, 1, 1]])

        game_state = GameState(curr_board, 1)
        game_state.update_board(4, 2)

        assert game_state.board == expected_board
        assert game_state.result == GameResults.Win
Esempio n. 11
0
    def __init__(self, game_info, sound_manager):
        GameState.__init__(self, GameState.STATE_GAME_OVER, GameState.STATE_MENU)

        self.game_info = game_info
        self.sound_manager = sound_manager

        self.load_screen_time = -1

        self.sound_manager.play_music(c.MUSIC_GAME_OVER)

        self.text_helper = TextHelper()
Esempio n. 12
0
    def __init__(self, game_info, sound_manager):
        GameState.__init__(self, GameState.STATE_GAME_OVER,
                           GameState.STATE_MENU)

        self.game_info = game_info
        self.sound_manager = sound_manager

        self.load_screen_time = -1

        self.sound_manager.play_music(c.MUSIC_GAME_OVER)

        self.text_helper = TextHelper()
Esempio n. 13
0
    def test_update_board_level_16(self):
        expected_board = Board([[1, 1, 1, 0, 0], [0, 0, 0, 0, 0],
                                [0, 0, 0, 0, 0], [0, 0, 0, 0, 0],
                                [0, 0, 0, 0, 0], [1, 0, 0, 0, 0]])

        curr_board = Board([[2, 4, 4, 1, 1], [2, 2, 2, 0, 4], [0, 4, 2, 2, 2],
                            [1, 1, 1, 3, 1], [1, 4, 0, 1, 4], [4, 0, 3, 2, 0]])

        game_state = GameState(curr_board, 1)
        game_state.update_board(3, 2)

        assert game_state.board == expected_board
        assert game_state.result == GameResults.Lose
Esempio n. 14
0
    def test_update_board_red_green_bubbles(self):
        expected_board = Board([[0, 0, 0, 0, 0], [0, 1, 0, 1, 0],
                                [1, 1, 0, 1, 1], [0, 2, 0, 2, 0],
                                [0, 1, 0, 1, 0], [0, 0, 0, 0, 0]])

        # level 7
        curr_board = Board([[0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [1, 2, 1, 2, 1],
                            [0, 2, 0, 2, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0]])

        game_state = GameState(curr_board, 2)
        game_state.update_board(2, 2)

        assert game_state.board == expected_board
        assert game_state.result == None
Esempio n. 15
0
 def test_upgrade(self):
     GameState().clear()
     unit = AllyFactory().get_big_fighter()
     print(unit)
     old_hp = unit.hp
     unit.upgrade_attribute('hp', 12)
     assert unit.hp == old_hp + 12
Esempio n. 16
0
    def on_events(self, events):
        for event in events:
            if event.type == py.MOUSEBUTTONDOWN:
                if self.next_button.is_clicked(self.mouse_position):
                    self.doorgaan = True
                    from src.game_screens.news_screen.news_screen import NewsScreen
                    self.game.drawer.clear()
                    NewsScreen(self.game)

                if self.hair_button_1.is_clicked(self.mouse_position):
                    self.hair_global = "resources/graphics/char/female_hairstyles/Female_Haircut_1.png"
                    GameState().set_char_hair(self.hair_global)
                    self.game.set_char_hair(self.hair_global)
                if self.hair_button_2.is_clicked(self.mouse_position):
                    self.hair_global = "resources/graphics/char/female_hairstyles/Female_Haircut_2.png"
                    self.on_render()
                    self.game.set_char_hair(self.hair_global)
                if self.hair_button_3.is_clicked(self.mouse_position):
                    self.hair_global = "resources/graphics/char/female_hairstyles/Female_Haircut_3.png"
                    self.on_render()
                    self.game.set_char_hair(self.hair_global)
                if self.hair_button_4.is_clicked(self.mouse_position):
                    self.hair_global = "resources/graphics/char/female_hairstyles/Female_Haircut_4.png"
                    self.on_render()
                    self.game.set_char_hair(self.hair_global)

                if self.color_button_1.is_clicked(self.mouse_position):
                    self.color_global = "resources/graphics/char/female_character/Female_Black.png"
                    self.on_render()
                    self.game.set_char_color(self.color_global)
                if self.color_button_2.is_clicked(self.mouse_position):
                    self.color_global = "resources/graphics/char/female_character/Female_Brown.png"
                    self.on_render()
                    self.game.set_char_color(self.color_global)
                if self.color_button_3.is_clicked(self.mouse_position):
                    self.color_global = "resources/graphics/char/female_character/Female_Pale.png"
                    self.on_render()
                    self.game.set_char_color(self.color_global)
                if self.color_button_4.is_clicked(self.mouse_position):
                    self.color_global = "resources/graphics/char/female_character/Female_White.png"
                    self.on_render()
                    self.game.set_char_color(self.color_global)

                if self.clothes_button_1.is_clicked(self.mouse_position):
                    self.clothes_global = "resources/graphics/char/female_clothes/Female_Clothes_1.png"
                    self.on_render()
                    self.game.set_char_clothes(self.clothes_global)
                if self.clothes_button_2.is_clicked(self.mouse_position):
                    self.clothes_global = "resources/graphics/char/female_clothes/Female_Clothes_2.png"
                    self.on_render()
                    self.game.set_char_clothes(self.clothes_global)
                if self.clothes_button_3.is_clicked(self.mouse_position):
                    self.clothes_global = "resources/graphics/char/female_clothes/Female_Clothes_3.png"
                    self.on_render()
                    self.game.set_char_clothes(self.clothes_global)
                if self.clothes_button_4.is_clicked(self.mouse_position):
                    self.clothes_global = "resources/graphics/char/female_clothes/Female_Clothes_4.png"
                    self.on_render()
                    self.game.set_char_clothes(self.clothes_global)
Esempio n. 17
0
    def test_bfs_level_26(self):
        board = Board([[1, 1, 1, 1, 1], [4, 2, 3, 1, 2], [2, 1, 4, 1, 2],
                       [3, 0, 1, 3, 0], [2, 1, 0, 4, 3], [0, 3, 2, 3, 1]])

        game_state = GameState(board, 3)

        solution = BFS.execute(game_state)

        simulate_game(game_state, solution)
Esempio n. 18
0
    def test_bfs_level_17(self):
        board = Board([[0, 4, 3, 2, 2], [1, 2, 2, 2, 1], [1, 2, 2, 2, 2],
                       [0, 3, 1, 1, 3], [3, 2, 0, 2, 0], [2, 4, 2, 2, 0]])

        game_state = GameState(board, 2)

        solution = BFS.execute(game_state)

        simulate_game(game_state, solution)
Esempio n. 19
0
    def test_bfs_level_12(self):
        board = Board([[1, 4, 3, 1, 2], [1, 0, 3, 1, 4], [1, 1, 3, 4, 4],
                       [2, 2, 1, 2, 1], [2, 2, 1, 0, 3], [0, 0, 1, 2, 1]])

        game_state = GameState(board, 1)

        solution = BFS.execute(game_state)

        simulate_game(game_state, solution)
Esempio n. 20
0
def play():
    selected_level = levels_menu()

    board_matrix, max_touches = utils.read_level_file(selected_level)
    board = Board(board_matrix)

    game_state = GameState(board, max_touches)

    game_loop(game_state)
Esempio n. 21
0
  def test_dfs_level_7(self):
    board = Board([
      [0,0,0,0,0], 
      [0,1,0,1,0], 
      [1,2,1,2,1], 
      [0,2,0,2,0],
      [0,1,0,1,0],
      [0,0,0,0,0]
    ])

    game_state = GameState(board, 2)
    
    solution = DFS.execute(game_state)

    simulate_game(game_state, solution)
Esempio n. 22
0
  def test_dfs_level_16(self):
    board = Board([
      [2,4,4,1,1], 
      [2,2,2,0,4], 
      [0,4,2,2,2], 
      [1,1,1,3,1],
      [1,4,0,1,4],
      [4,0,3,2,0]
    ])

    game_state = GameState(board, 2)
    
    solution = DFS.execute(game_state)

    simulate_game(game_state, solution)
Esempio n. 23
0
 def __init__(self):
     self.enable_logging()
     self.running = False
     self.drawer = None
     self.py_screen = None
     self.screen = None
     self.screen_change = None
     self.temp_screen = None
     self.config = None
     self.FULLSCREEN = False
     self.DEBUG = False
     self.clock = py.time.Clock()
     self.screen_center_width = None
     self.screen_center_height = None
     self.game_state = GameState()
     self.character_color = "resources/graphics/char/female_character/Female_Pale.png"
     self.character_clothes = "resources/graphics/char/female_clothes/Female_Clothes_3.png"
     self.character_hairstyle = "resources/graphics/char/female_hairstyles/Female_Haircut_3.png"
     self.money = 0
     self.dingengoed = 0
     self.need_instruction = True
Esempio n. 24
0
    def test_update_board_level_17(self):
        expected_board = Board([[0, 4, 3, 2, 2], [1, 2, 2, 2, 1],
                                [1, 2, 1, 1, 2], [0, 2, 0, 0, 1],
                                [3, 2, 0, 1, 0], [2, 4, 1, 2, 0]])

        curr_board = Board([[0, 4, 3, 2, 2], [1, 2, 2, 2, 1], [1, 2, 2, 2, 2],
                            [0, 3, 1, 1, 3], [3, 2, 0, 2, 0], [2, 4, 2, 2, 0]])

        game_state = GameState(curr_board, 2)
        game_state.update_board(3, 3)

        assert game_state.board == expected_board
        assert game_state.result == None

        expected_board = Board()
        game_state.update_board(4, 3)

        assert game_state.board == expected_board
        assert game_state.result == GameResults.Win
Esempio n. 25
0

# Make sure the game is properly defined
validate(src.utils.game_module)
# For debugging with heapy.
if args.debug:
    src.debug.init_debug(comm.Get_rank())
    send = src.debug.debug_send(comm.send)
    recv = src.debug.debug_recv(comm.recv)
    abort = src.debug.debug_abort(comm.Abort)

initial_position = src.utils.game_module.initial_position()

process = Process(comm.Get_rank(),
                  comm.Get_size(),
                  comm,
                  send,
                  recv,
                  abort,
                  stats_dir=args.statsdir)

if process.rank == process.root:
    initial_gamestate = GameState(GameState.INITIAL_POS)
    initial_job = Job(Job.LOOK_UP, initial_gamestate, process.rank,
                      Job.INITIAL_JOB_ID)
    process.add_job(initial_job)

process.run()

comm.Barrier()
Esempio n. 26
0
 def test_getting_reward_twice(self):
     GameState().clear()
     unit = AllyFactory().get_big_fighter()
     unit.death()
     unit.death()
     assert GameState().get_enemy_coins() == unit.reward
Esempio n. 27
0
 def test_creating_units(self):
     unit = AllyFactory().get_big_fighter()
     assert GameState().get_ally_warriors_count() == 1
     unit.death()
     assert GameState().get_ally_warriors_count() == 0
Esempio n. 28
0

season = 10
day = 0
setup(season, day)
#print_info()
make_team_states(season, day)
team_states[Team.TIGERS].is_home = False
game = GameState(
    game_id="1",
    season=season,
    day=day,
    stadium=team_states[Team.DALE].stadium,
    home_team=team_states[Team.DALE],
    away_team=team_states[Team.TIGERS],
    home_score=Decimal("0"),
    away_score=Decimal("0"),
    inning=1,
    half=InningHalf.TOP,
    outs=0,
    strikes=0,
    balls=0,
    weather=Weather.SUN2,
)
model = load(os.path.join("..", "season_sim", "models", "pitch_v1.joblib"))
fv = game.gen_pitch_fv(
    game.cur_batting_team.get_cur_batter_feature_vector(),
    game.cur_pitching_team.get_pitcher_feature_vector(),
    game.cur_pitching_team.get_defense_feature_vector(),
    game.stadium.get_stadium_fv(),
)
#print("fv = "+ str(fv))
Esempio n. 29
0
 def __init__(self):
     self.team = Team.ENEMY.value
     super().__init__()
     GameState().update_warriors(self.team, 1)
     GameState().update_coins(self.team, -self.price)
Esempio n. 30
0
    isend = src.debug.debug_send(comm.isend)
    recv = src.debug.debug_recv(comm.recv)
    abort = src.debug.debug_abort(comm.Abort)

initial_position = src.utils.game_module.initial_position()

process = Process(comm.Get_rank(),
                  comm.Get_size(),
                  comm,
                  isend,
                  recv,
                  abort,
                  stats_dir=args.statsdir)

if process.rank == process.root:
    initial_gamestate = GameState(GameState.INITIAL_POS)

    tup = (initial_gamestate.to_tuple())
    # Uncomment for new_solver
    initial_job = Job(Job.LOOK_UP, process.rank, Job.INITIAL_JOB_ID, tup)
    # initial_job = Job(
    #     Job.LOOK_UP,
    #     initial_gamestate,
    #     process.rank,
    #     Job.INITIAL_JOB_ID,
    # )
    process.work.put(initial_job)

process.run()

comm.Barrier()
Esempio n. 31
0
 def death(self):
     if self.alive:
         GameState().update_warriors(self.team, -1)
         GameState().update_coins(self.team ^ 1, self.reward)
         self.alive = False