-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9691b0b
commit cef9dbf
Showing
3 changed files
with
91 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import ArgsSerializer.*; | ||
import Exceptions.*; | ||
import GameExecutor.*; | ||
import Logger.*; | ||
import ReportMaker.ReportMaker; | ||
|
||
/** | ||
* Main entry point for the game simulation. | ||
*/ | ||
public class ArgsMain { | ||
private static final Logger logger = new Logger("Main"); | ||
|
||
/** | ||
* Entry point for the application. | ||
* | ||
* @param args Command-line arguments. | ||
* @throws InterruptedException If the game execution is interrupted. | ||
*/ | ||
public static void main(String[] args) throws InterruptedException { | ||
/* extract parameters */ | ||
logger.title("Parse arguments"); | ||
ArgsSerializer argsSerializer = new ArgsSerializer(args); | ||
GameArguments gameArguments; | ||
try { | ||
gameArguments = argsSerializer.serialize(); | ||
} catch (InvalidGameException | NotEnoughArgumentsException e) { | ||
logger.error(e.toString()); | ||
ArgsMain.printUsage(); | ||
return; | ||
} | ||
gameArguments.print(); | ||
|
||
/* run game */ | ||
logger.title("Execute Game"); | ||
GameExecutor gameExecutor = new GameExecutor(gameArguments); | ||
GameExecutorResults results = gameExecutor.runGame(); | ||
|
||
/* create reports */ | ||
ReportMaker reportMaker = new ReportMaker(); | ||
reportMaker.generateReport(gameArguments.numberOfAgents(), gameArguments.gameType(), gameArguments.fraction(), | ||
gameArguments.probability(), results.network(), results.audit()); | ||
|
||
/* conclude results */ | ||
logger.title("Game Results"); | ||
results.print(); | ||
} | ||
|
||
/** | ||
* Displays the correct usage of the application along with expected command-line arguments. | ||
*/ | ||
public static void printUsage(){ | ||
logger.info("### For Prisoner’s Dilemma (PD-" + GameType.PD.getValue() +") ###"); | ||
logger.info("Usage: java Main <number_of_agents:int> <probability_of_connection:double> " | ||
+ GameType.PD.getValue()); | ||
|
||
logger.info("### For Battle of the Sexes (BoS-"+GameType.BoS.getValue()+") ###"); | ||
logger.info("Usage: java Main <number_of_agents:int> <probability_of_connection:double> " | ||
+ GameType.BoS.getValue() + " <friction:int>"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,30 @@ | ||
import ArgsSerializer.*; | ||
import Exceptions.*; | ||
import GameExecutor.*; | ||
import Logger.*; | ||
import ReportMaker.ReportMaker; | ||
|
||
/** | ||
* Main entry point for the game simulation. | ||
*/ | ||
public class Main { | ||
private static final int NUMBER_OF_GAMES = 10; | ||
|
||
private static final Logger logger = new Logger("Main"); | ||
|
||
/** | ||
* Entry point for the application. | ||
* | ||
* @param args Command-line arguments. | ||
* @throws InterruptedException If the game execution is interrupted. | ||
*/ | ||
public static void main(String[] args) throws InterruptedException { | ||
/* extract parameters */ | ||
logger.debug("Parse arguments", LogType.Title); | ||
ArgsSerializer argsSerializer = new ArgsSerializer(args); | ||
GameArguments gameArguments; | ||
try { | ||
gameArguments = argsSerializer.serialize(); | ||
} catch (InvalidGameException | NotEnoughArgumentsException e) { | ||
logger.error(e.toString()); | ||
Main.printUsage(); | ||
return; | ||
} | ||
gameArguments.print(); | ||
|
||
/* run game */ | ||
logger.debug("Execute Game", LogType.Title); | ||
GameExecutor gameExecutor = new GameExecutor(gameArguments); | ||
GameExecutorResults results = gameExecutor.runGame(); | ||
logger.title("Randomize arguments"); | ||
GameArguments gameArguments = GameArguments.getRandomArguments(10, 0.5); | ||
|
||
/* create reports */ | ||
ReportMaker reportMaker = new ReportMaker(); | ||
reportMaker.generateReport(gameArguments.numberOfAgents(), gameArguments.gameType(), gameArguments.fraction(), | ||
gameArguments.probability(), results.network(), results.audit()); | ||
logger.title("Executing " + NUMBER_OF_GAMES +" Random Games"); | ||
int totalRawRounds = 0; | ||
int totalSW = 0; | ||
for (int i = 0; i < NUMBER_OF_GAMES; i++) { | ||
logger.info("Starting Game No." + (i + 1) + ": " + gameArguments.gameType()); | ||
GameExecutor gameExecutor = new GameExecutor(gameArguments); | ||
GameExecutorResults results = gameExecutor.runGame(); | ||
|
||
/* conclude results */ | ||
logger.debug("Game Results", LogType.Title); | ||
results.print(); | ||
} | ||
|
||
/** | ||
* Displays the correct usage of the application along with expected command-line arguments. | ||
*/ | ||
public static void printUsage(){ | ||
logger.debug("### For Prisoner’s Dilemma (PD-" + GameType.PD.getValue() +") ###"); | ||
logger.debug("Usage: java Main <number_of_agents:int> <probability_of_connection:double> " | ||
+ GameType.PD.getValue()); | ||
totalRawRounds += results.totalRounds(); | ||
totalSW += results.totalGain(); | ||
} | ||
|
||
logger.debug("### For Battle of the Sexes (BoS-"+GameType.BoS.getValue()+") ###"); | ||
logger.debug("Usage: java Main <number_of_agents:int> <probability_of_connection:double> " | ||
+ GameType.BoS.getValue() + " <friction:int>"); | ||
logger.title("Summarizing results"); | ||
logger.info("Average number of rounds: " + (totalRawRounds / NUMBER_OF_GAMES)); | ||
logger.info("Total SW: " + totalSW); | ||
} | ||
} |