track the money over the course of a axis and allies game in matlab

To track the money over the course of an Axis and Allies game in MATLAB, you can create a script that prompts the user for the starting amount and then allows them to input the amount earned/lost at the end of each turn. The script can then keep track of the total amount of money and plot it as a function of the number of turns.

Here's an example code:

main.m
% Prompt user for starting money
starting_money = input('Enter starting amount of money: ');

% Initialize variables
total_money = starting_money;
num_turns = 0;
money_history = [];

% Loop through each turn
while true
    % Prompt user for money earned/lost during turn
    money_this_turn = input(['Enter money earned/lost for turn ' num2str(num_turns+1) ': ']);
    
    % Add money to total and record history
    total_money = total_money + money_this_turn;
    money_history = [money_history; total_money];
    
    % Plot money history
    plot(money_history);
    xlabel('Turns');
    ylabel('Money');
    title('Money over time');
    
    % Ask user if they want to continue
    cont = input('Continue? (y/n): ','s');
    if cont == 'n'
        break;
    end
    
    % Update turn counter
    num_turns = num_turns + 1;
end
836 chars
33 lines

This code prompts the user for the starting amount of money, then enters a loop where it prompts the user for the amount earned or lost during each turn. It keeps track of the total amount of money and records a history of the money at the end of each turn. The plot function is called to plot the money history as a function of the number of turns. The user is then prompted whether they want to continue or not, and the loop continues until the user enters 'n'.

With this script, you can then track the money over the course of an Axis and Allies game and analyze the data to see how well different strategies perform financially.

gistlibby LogSnag