From b32b61fad8ca4f3e26e99eec2c51691b8684a473 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Fri, 6 Dec 2024 17:31:01 -0500 Subject: [PATCH] revert to original files --- dotsboxesgm.cxx | 1 - main.cxx | 65 ++++++++++++++++++++++++++------------------ strategic_player.cxx | 2 +- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/dotsboxesgm.cxx b/dotsboxesgm.cxx index 70c20eb..a3e3777 100644 --- a/dotsboxesgm.cxx +++ b/dotsboxesgm.cxx @@ -151,7 +151,6 @@ string GameMaster(const vector& libpaths, vector& scores, vectorClose(); diff --git a/main.cxx b/main.cxx index f4dfa1a..898c4e8 100644 --- a/main.cxx +++ b/main.cxx @@ -1,28 +1,33 @@ -#include +#include +#include +#include #include +#include "common.h" +#include "board.h" #include "player.h" - using namespace std; #include // usleep() #include -string GameMaster(const vector &libpaths, vector &scores, vector ×pents, double sleep_sec); +string GameMaster(const vector& libpaths, vector& scores, vector& timespents, double sleep_sec); void CloseLibs(); -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) +{ // argv[0] : program name // argv[1] : 1st player library path // argv[2] : 2nd player library path // argv[3] : 3rd player library path - if (argc <= 2) + if(argc <= 2) return 0; vector libpaths; - vector scores; + vector scores; vector timespents; - for (int i = 1; i < argc; i++) { + for(int i=1; i lst_player_libhandle; - -typedef IPlayer *(*CreatePlayerType)(); - +vector lst_player_libhandle; +typedef IPlayer* (*CreatePlayerType)(); string LoadPlayer - (IPlayer *&iplayer, string libpath, int board_rows // the size of board (including dots, lines, and boxes) - , int board_cols // the size of board (including dots, lines, and boxes) - , char box_type // the character for the player's boxes - , char line_type // the character for the player's lines - ) { - void *player_libhandle = dlopen(libpath.c_str(), RTLD_LAZY); - if (player_libhandle == nullptr) { + ( IPlayer*& iplayer + , string libpath + , int board_rows // the size of board (including dots, lines, and boxes) + , int board_cols // the size of board (including dots, lines, and boxes) + , char box_type // the character for the player's boxes + , char line_type // the character for the player's lines + ) +{ + void* player_libhandle = dlopen(libpath.c_str(), RTLD_LAZY); + if(player_libhandle == nullptr) + { return "cannot load " + libpath; } lst_player_libhandle.push_back(player_libhandle); - void *pfunc = dlsym(player_libhandle, "PlayerFactory"); - if (pfunc == nullptr) { + void* pfunc = dlsym(player_libhandle, "PlayerFactory"); + if(pfunc == nullptr) + { return "cannot find PlayerFactory() function defined as extern C"; } - CreatePlayerType CreatePlayer = (CreatePlayerType) pfunc; + CreatePlayerType CreatePlayer = (CreatePlayerType)pfunc; iplayer = CreatePlayer(); iplayer->Init(board_rows, board_cols, box_type, line_type); - if (iplayer == nullptr) { + if(iplayer == nullptr) + { return "cannot create player using PlayerFactory() function"; } return ""; } - -void CloseLibs() { - for (void *player_libhandle: lst_player_libhandle) +void CloseLibs() +{ + for(void* player_libhandle : lst_player_libhandle) dlclose(player_libhandle); lst_player_libhandle.clear(); } diff --git a/strategic_player.cxx b/strategic_player.cxx index 00185cb..004f3b4 100644 --- a/strategic_player.cxx +++ b/strategic_player.cxx @@ -8,7 +8,7 @@ extern "C" IPlayer* PlayerFactory() string StrategicPlayer::PlayerInfo() { - return "Sapan Shah (scs6041@psu.edu), Sandipsinh Rathod (sdr5549@psu.edu)"; + return "Sandipsinh Rathod (sdr5549@psu.edu), Sapan Shah (scs6041@psu.edu)"; } void StrategicPlayer::Init(int board_rows, int board_cols, char box_type, char line_type) {