diff --git a/.DS_Store b/.DS_Store index 7e1cf6af650f4856839383fec3ac7e1495eaf13e..0e23e772b737faf303350bf9ce9424c18f060d1c 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/100k_false/Figure_1.png b/False/100k_false/Figure_1.png similarity index 100% rename from 100k_false/Figure_1.png rename to False/100k_false/Figure_1.png diff --git a/100k_false/Figure_2.png b/False/100k_false/Figure_2.png similarity index 100% rename from 100k_false/Figure_2.png rename to False/100k_false/Figure_2.png diff --git a/100k_false/Figure_3.png b/False/100k_false/Figure_3.png similarity index 100% rename from 100k_false/Figure_3.png rename to False/100k_false/Figure_3.png diff --git a/10k_false/Figure_1.png b/False/10k_false/Figure_1.png similarity index 100% rename from 10k_false/Figure_1.png rename to False/10k_false/Figure_1.png diff --git a/10k_false/Figure_2.png b/False/10k_false/Figure_2.png similarity index 100% rename from 10k_false/Figure_2.png rename to False/10k_false/Figure_2.png diff --git a/10k_false/Figure_3.png b/False/10k_false/Figure_3.png similarity index 100% rename from 10k_false/Figure_3.png rename to False/10k_false/Figure_3.png diff --git a/1M_false/Figure_1.png b/False/1M_false/Figure_1.png similarity index 100% rename from 1M_false/Figure_1.png rename to False/1M_false/Figure_1.png diff --git a/1M_false/Figure_2.png b/False/1M_false/Figure_2.png similarity index 100% rename from 1M_false/Figure_2.png rename to False/1M_false/Figure_2.png diff --git a/1M_false/Figure_3.png b/False/1M_false/Figure_3.png similarity index 100% rename from 1M_false/Figure_3.png rename to False/1M_false/Figure_3.png diff --git a/True/.DS_Store b/True/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..65c98b221e72bb3d1db3ee1342abd30ec2bd6fe6 Binary files /dev/null and b/True/.DS_Store differ diff --git a/True/100k_true/Figure_1.png b/True/100k_true/Figure_1.png new file mode 100644 index 0000000000000000000000000000000000000000..5e9a68bccaf7e4882a7cf8ea349c88b49c1a5c62 Binary files /dev/null and b/True/100k_true/Figure_1.png differ diff --git a/True/100k_true/Figure_2.png b/True/100k_true/Figure_2.png new file mode 100644 index 0000000000000000000000000000000000000000..e912c52e8d16cc90dfd27a6f1597f6af07650900 Binary files /dev/null and b/True/100k_true/Figure_2.png differ diff --git a/True/10k_true/Figure_1.png b/True/10k_true/Figure_1.png new file mode 100644 index 0000000000000000000000000000000000000000..42e592d8867720140c20f0a6fbfb34a4bf0e520f Binary files /dev/null and b/True/10k_true/Figure_1.png differ diff --git a/True/10k_true/Figure_2png.png b/True/10k_true/Figure_2png.png new file mode 100644 index 0000000000000000000000000000000000000000..cde985da26380232ec2af3f0fc2ad649531f6510 Binary files /dev/null and b/True/10k_true/Figure_2png.png differ diff --git a/True/Figure_1.png b/True/Figure_1.png new file mode 100644 index 0000000000000000000000000000000000000000..24ece654432293eec22b7fffbebbe63a954af8ed Binary files /dev/null and b/True/Figure_1.png differ diff --git a/plot.py b/plot.py index dd9d81a94f56c6565128e3e98c01ef73fe16aeaa..0873e38f216b3208c22fef117109412d1279ca4d 100644 --- a/plot.py +++ b/plot.py @@ -30,7 +30,7 @@ def plot_state_based_turns(): plt.figure(figsize=(12, 6)) # Simulate and plot average turns for each strategy for strategy, name in zip(strategies, strategy_names): - mean_turns = validation_instance.simulate_state(strategy, layout, circle, num_games) + mean_turns = validation_instance.state_simulation(strategy, layout, circle, num_games) plt.plot(range(len(mean_turns)), mean_turns, marker='o', linestyle='-', label=name) plt.xlabel('State') @@ -93,11 +93,18 @@ if __name__ == '__main__': ##### Paramètres ##### # Define the layout of the game board - layout = [0, 0, 3, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 1, 0] + #layout = [0, 0, 3, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 1, 0] + + #layout = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 2, 1, 0] + + #layoutfastlaneWt = [0, 0, 3, 0, 2, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0] + #layoutslowlaneWt = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 2, 1, 0] + + layout = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # Indicates whether the board is circular or linear circle = False # Number of games to simulate - num_games = 10000 + num_games = 100 # Initialize Validation instance with the specified layout and circle type validation_instance = Val(layout, circle) @@ -106,5 +113,5 @@ if __name__ == '__main__': # Run the defined plotting functions with specified parameters plot_strategy_comparison(num_games) plot_state_based_turns() - plot_state_based_comparison(num_games_list = [10, 100, 1000]) + plot_state_based_comparison(num_games_list = [10,100,1000]) plot_state_based_comparison_once(num_games) \ No newline at end of file diff --git a/validation.py b/validation.py index 7e72b5e1340e6042451f7018ac1624e56f972c68..052645c9655c22c145ebd27e97ae0c35e5f167b3 100644 --- a/validation.py +++ b/validation.py @@ -42,7 +42,7 @@ class Validation: self.costs_by_dice_type['RiskyDice'][i] = 3 if die_type == 3 else 0 - def simulate_game(self, strategy: list, n_iterations: int): + def simulate_rounds(self, strategy: list, n_iterations: int): """Simulate the game using a given strategy over multiple iterations.""" transition_matrices = [self.safe_dice, self.normal_dice, self.risky_dice] total_turns = np.zeros(n_iterations) @@ -74,7 +74,7 @@ class Validation: return np.mean(total_turns) - def simulate_state(self, strategy: list, layout: list, circle: bool, n_iterations: int): + def state_simulation(self, strategy: list, layout: list, circle: bool, n_iterations: int): """Simulate game states using a given strategy.""" safe_dice = self.tmc_instance._compute_safe_matrix() normal_dice = self.tmc_instance._compute_normal_matrix(layout, circle)[0] @@ -117,7 +117,7 @@ class Validation: def play_optimal_policy(self, n_iterations : int): """Play using the optimal policy for a number of iterations.""" - return self.simulate_game(self.optimal_policy, n_iterations) + return self.simulate_rounds(self.optimal_policy, n_iterations) def play_dice_strategy(self, dice_choice, n_iterations : int): """Play using a specific dice strategy for a number of iterations.""" @@ -130,17 +130,17 @@ class Validation: if strategy is None: raise ValueError("Invalid dice choice") - return self.simulate_game(strategy, n_iterations) + return self.simulate_rounds(strategy, n_iterations) def play_random_strategy(self, n_iterations : int ): """Play using a random strategy for a number of iterations.""" - return self.simulate_game(self.random_strategy, n_iterations) + return self.simulate_rounds(self.random_strategy, n_iterations) def compare_empirical_vs_value_iteration(self, num_games : int): """Compare expected value iteration turns with empirical turns.""" value_iteration_turns = self.expec - empirical_turns = self.simulate_state(self.optimal_policy, self.layout, self.circle, n_iterations=num_games) + empirical_turns = self.state_simulation(self.optimal_policy, self.layout, self.circle, n_iterations=num_games) mean_turns_by_state = { 'ValueIteration': value_iteration_turns.tolist(), @@ -148,34 +148,22 @@ class Validation: } return mean_turns_by_state - - def empirical_cost_of_square(self, strategy: list, n_iterations: int): - """Calculate the empirical cost of a square for a given strategy.""" - total_square_costs = [] - - for _ in range(n_iterations): - game_cost = self.simulate_game(strategy, 1) - square_cost = game_cost ** 2 - total_square_costs.append(square_cost) - - empirical_cost = np.mean(total_square_costs) - return empirical_cost def compare_state_based_turns(self, num_games : int ): # Compare the expected turns from value iteration with empirical state-based turns value_iteration = self.expec - empirical_turns = self.simulate_state(self.optimal_policy, self.layout, self.circle, n_iterations=num_games) + empirical_turns = self.state_simulation(self.optimal_policy, self.layout, self.circle, n_iterations=num_games) return value_iteration, empirical_turns def compare_strategies(self, num_games : int): # Compare the costs of different strategies over a number of games - optimal_cost = self.simulate_game(self.optimal_policy, n_iterations=num_games) - dice1_cost = self.simulate_game(self.safe_strategy, n_iterations=num_games) - dice2_cost = self.simulate_game(self.normal_strategy, n_iterations=num_games) - dice3_cost = self.simulate_game(self.risky_strategy, n_iterations=num_games) - random_cost = self.simulate_game(self.random_strategy, n_iterations=num_games) + optimal_cost = self.simulate_rounds(self.optimal_policy, n_iterations=num_games) + dice1_cost = self.simulate_rounds(self.safe_strategy, n_iterations=num_games) + dice2_cost = self.simulate_rounds(self.normal_strategy, n_iterations=num_games) + dice3_cost = self.simulate_rounds(self.risky_strategy, n_iterations=num_games) + random_cost = self.simulate_rounds(self.random_strategy, n_iterations=num_games) return { 'Optimal': optimal_cost,