From a7ea92e8a52512a1448edf2d779e6f1b77ca3929 Mon Sep 17 00:00:00 2001 From: Greg Date: Wed, 19 Nov 2014 21:44:10 -0500 Subject: [PATCH 01/20] Create RPSGame.py --- RPSGame.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 RPSGame.py diff --git a/RPSGame.py b/RPSGame.py new file mode 100644 index 0000000..1dd9b02 --- /dev/null +++ b/RPSGame.py @@ -0,0 +1,25 @@ +__author__ = 'g_ric_000' + + +class RPSGame(Game): + ## this class simulates two players playing rock, paper, scissors + def __init__(self): + + + def play_game(self, player1, player2): + result = "" + move1 = player1.get_move() + move2 = player2.get_move() + if self.is_valid_move(move1) and self.is_valid_move(move2): + if move1 == move2: + result = "The match has ended in a tie!" + elif (move1 == "rock" and move2 == "scissors") or (move1 == "paper" and move2 == "rock") or (move1 == "scissors" and move2 == "paper"): + result = "Player1 is the winner!" + else: + result = "Player2 is the winner!" + else: + result = "Valid moves were not made by both teams." + return result + + def is_valid_move(self, move): + return move in ('rock', 'paper', 'scissors') From d94500b5f120c797c09bf9a86507fc95710c0f49 Mon Sep 17 00:00:00 2001 From: Joe Kvedaras Date: Sun, 23 Nov 2014 21:35:56 -0500 Subject: [PATCH 02/20] Created TournamentService with register_player(player) and set_game(game) --- TournamentService.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 TournamentService.py diff --git a/TournamentService.py b/TournamentService.py new file mode 100644 index 0000000..e6a7816 --- /dev/null +++ b/TournamentService.py @@ -0,0 +1,22 @@ +__author__ = "Joe Kvedaras and Collin Day" +#Set up a tournament with a game and register players +from Tournament.py import * + + +class TournamentService: + + def __init__(self, tournament): + """initialize a new tournament with a game""" + self.tournament = tournament + + + def register_player(self, player): + """register a player in the current tournament""" + self.tournament.register_player(player) + + + def set_game(self,game): + """set the game of the current tournament""" + #Do not know if I have to create a new tournament with the game + #type or add the game to an existing tournament + pass From dea15f6084168706258f116c62ceb88f888d08db Mon Sep 17 00:00:00 2001 From: Joe Kvedaras Date: Sun, 23 Nov 2014 21:52:29 -0500 Subject: [PATCH 03/20] Added comments --- TournamentService.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TournamentService.py b/TournamentService.py index e6a7816..4f5cd01 100644 --- a/TournamentService.py +++ b/TournamentService.py @@ -6,7 +6,7 @@ class TournamentService: def __init__(self, tournament): - """initialize a new tournament with a game""" + #Is tournament service the one to create a new tournament? self.tournament = tournament From fcd993a5f60e4911248dbf82d6e4a71ffdc08b1a Mon Sep 17 00:00:00 2001 From: Greg Date: Mon, 24 Nov 2014 10:25:38 -0500 Subject: [PATCH 04/20] Update RPSGame.py edited the RPSGame class to match up with the Game class --- RPSGame.py | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/RPSGame.py b/RPSGame.py index 1dd9b02..6c13343 100644 --- a/RPSGame.py +++ b/RPSGame.py @@ -1,25 +1,32 @@ -__author__ = 'g_ric_000' +__author__ = 'Greg Richards' + +import Game class RPSGame(Game): - ## this class simulates two players playing rock, paper, scissors + ## this class simulates two players playing a game of rock, paper, scissors def __init__(self): + super(RPSGame, self).__init__() - - def play_game(self, player1, player2): - result = "" - move1 = player1.get_move() - move2 = player2.get_move() - if self.is_valid_move(move1) and self.is_valid_move(move2): + def get_result(self, moves): + move1, move2 = moves # unpack the tuple that was passed as a parameter + x = is_legal(move1) + y = is_legal(move2) + result = (0,0) # result is a tuple of the points that each player has earned respectively + if x and y: if move1 == move2: - result = "The match has ended in a tie!" - elif (move1 == "rock" and move2 == "scissors") or (move1 == "paper" and move2 == "rock") or (move1 == "scissors" and move2 == "paper"): - result = "Player1 is the winner!" + result = (1,1) + elif (move1 == 0 and move2 != 1) or (move1 == 1 and move2 != 2) or (move1 == 2 and move2 != 0): + result = (1,0) else: - result = "Player2 is the winner!" + result = (0,1) + elif x and not y: + result = (1,0) + elif not x and y: + result = (0,1) else: - result = "Valid moves were not made by both teams." + result = result return result - def is_valid_move(self, move): - return move in ('rock', 'paper', 'scissors') + def is_legal(self, move): + return move in (0, 1, 2) From 8683d4e23ae8a1d903c9a1ad914343ff19de8fa0 Mon Sep 17 00:00:00 2001 From: Joe Kvedaras Date: Mon, 24 Nov 2014 11:53:28 -0500 Subject: [PATCH 05/20] Added set_tournament and run methods --- TournamentService.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/TournamentService.py b/TournamentService.py index 4f5cd01..7789cd1 100644 --- a/TournamentService.py +++ b/TournamentService.py @@ -1,13 +1,14 @@ __author__ = "Joe Kvedaras and Collin Day" #Set up a tournament with a game and register players from Tournament.py import * - +from AllPlayAll.py import * class TournamentService: - def __init__(self, tournament): + def __init__(self): #Is tournament service the one to create a new tournament? - self.tournament = tournament + self.tournament + self.game def register_player(self, player): @@ -15,8 +16,25 @@ def register_player(self, player): self.tournament.register_player(player) - def set_game(self,game): + def set_game(self, game): """set the game of the current tournament""" - #Do not know if I have to create a new tournament with the game - #type or add the game to an existing tournament - pass + #Tournament initializes with a game and you can not change + #game type afterwards + self.game = game + + def set_tournament(self, tournament_type = None): + """Allow client to set the tournament type. Defaults to + AllPlayAll tournament type""" + if tournament_type is None: + #AllPlayAll takes registration as a parameter. I don't think they + #need that there + self.tournament = AllPlayAll(self.game, None, 1000) + else: + self.tournament = tournament_type(self.game, None, 1000) + + def run(self): + """Set the game and run the tournament""" + if self.tournament is None: + print ("Can not run tournament. Tournament is null") + else: + self.tournament.run() From ab01a7e75e65ec40bb32d559cdd4818ff6fb1d6e Mon Sep 17 00:00:00 2001 From: Joe Kvedaras Date: Sun, 23 Nov 2014 21:35:56 -0500 Subject: [PATCH 06/20] Created TournamentService with register_player(player) and set_game(game) --- TournamentService.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 TournamentService.py diff --git a/TournamentService.py b/TournamentService.py new file mode 100644 index 0000000..e6a7816 --- /dev/null +++ b/TournamentService.py @@ -0,0 +1,22 @@ +__author__ = "Joe Kvedaras and Collin Day" +#Set up a tournament with a game and register players +from Tournament.py import * + + +class TournamentService: + + def __init__(self, tournament): + """initialize a new tournament with a game""" + self.tournament = tournament + + + def register_player(self, player): + """register a player in the current tournament""" + self.tournament.register_player(player) + + + def set_game(self,game): + """set the game of the current tournament""" + #Do not know if I have to create a new tournament with the game + #type or add the game to an existing tournament + pass From 7ac94929d3ea31a6c81c41a7e734cf3a83477c49 Mon Sep 17 00:00:00 2001 From: Joe Kvedaras Date: Sun, 23 Nov 2014 21:52:29 -0500 Subject: [PATCH 07/20] Added comments --- TournamentService.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TournamentService.py b/TournamentService.py index e6a7816..4f5cd01 100644 --- a/TournamentService.py +++ b/TournamentService.py @@ -6,7 +6,7 @@ class TournamentService: def __init__(self, tournament): - """initialize a new tournament with a game""" + #Is tournament service the one to create a new tournament? self.tournament = tournament From a04dcef729e2baf1e9fbfcb3a081a08efafa5008 Mon Sep 17 00:00:00 2001 From: Joe Kvedaras Date: Mon, 24 Nov 2014 11:53:28 -0500 Subject: [PATCH 08/20] Added set_tournament and run methods --- TournamentService.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/TournamentService.py b/TournamentService.py index 4f5cd01..7789cd1 100644 --- a/TournamentService.py +++ b/TournamentService.py @@ -1,13 +1,14 @@ __author__ = "Joe Kvedaras and Collin Day" #Set up a tournament with a game and register players from Tournament.py import * - +from AllPlayAll.py import * class TournamentService: - def __init__(self, tournament): + def __init__(self): #Is tournament service the one to create a new tournament? - self.tournament = tournament + self.tournament + self.game def register_player(self, player): @@ -15,8 +16,25 @@ def register_player(self, player): self.tournament.register_player(player) - def set_game(self,game): + def set_game(self, game): """set the game of the current tournament""" - #Do not know if I have to create a new tournament with the game - #type or add the game to an existing tournament - pass + #Tournament initializes with a game and you can not change + #game type afterwards + self.game = game + + def set_tournament(self, tournament_type = None): + """Allow client to set the tournament type. Defaults to + AllPlayAll tournament type""" + if tournament_type is None: + #AllPlayAll takes registration as a parameter. I don't think they + #need that there + self.tournament = AllPlayAll(self.game, None, 1000) + else: + self.tournament = tournament_type(self.game, None, 1000) + + def run(self): + """Set the game and run the tournament""" + if self.tournament is None: + print ("Can not run tournament. Tournament is null") + else: + self.tournament.run() From a588acae1521f725460608fbc24a79ea9c2b8e7b Mon Sep 17 00:00:00 2001 From: Joe Kvedaras Date: Mon, 24 Nov 2014 12:01:12 -0500 Subject: [PATCH 09/20] Added error checking --- TournamentService.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/TournamentService.py b/TournamentService.py index 7789cd1..9fcde23 100644 --- a/TournamentService.py +++ b/TournamentService.py @@ -13,7 +13,10 @@ def __init__(self): def register_player(self, player): """register a player in the current tournament""" - self.tournament.register_player(player) + if self.tournament is None: + print("Can not add player. Tournament is null") + else: + self.tournament.register_player(player) def set_game(self, game): @@ -35,6 +38,6 @@ def set_tournament(self, tournament_type = None): def run(self): """Set the game and run the tournament""" if self.tournament is None: - print ("Can not run tournament. Tournament is null") + print("Can not run tournament. Tournament is null") else: self.tournament.run() From 012741a51f7198d7043b8075d396746b6d1e5b54 Mon Sep 17 00:00:00 2001 From: Joe Kvedaras Date: Mon, 24 Nov 2014 12:14:42 -0500 Subject: [PATCH 10/20] Tried to fix rebase issues --- TournamentService.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/TournamentService.py b/TournamentService.py index 540ce3c..f254706 100644 --- a/TournamentService.py +++ b/TournamentService.py @@ -13,14 +13,11 @@ def __init__(self): def register_player(self, player): """register a player in the current tournament""" -<<<<<<< HEAD if self.tournament is None: print("Can not add player. Tournament is null") else: self.tournament.register_player(player) -======= - self.tournament.register_player(player) ->>>>>>> 8683d4e23ae8a1d903c9a1ad914343ff19de8fa0 + def set_game(self, game): @@ -42,10 +39,6 @@ def set_tournament(self, tournament_type = None): def run(self): """Set the game and run the tournament""" if self.tournament is None: -<<<<<<< HEAD print("Can not run tournament. Tournament is null") -======= - print ("Can not run tournament. Tournament is null") ->>>>>>> 8683d4e23ae8a1d903c9a1ad914343ff19de8fa0 else: self.tournament.run() From 1b591d75d18bdb2048f2b723ed3d075dafa9af63 Mon Sep 17 00:00:00 2001 From: ezekie97 Date: Mon, 24 Nov 2014 16:12:36 -0500 Subject: [PATCH 11/20] Updated All Play All --- AllPlayAll.py | 72 ++++++++++++++++++++------------------------------ AllPlayAll.py~ | 49 ++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 43 deletions(-) create mode 100644 AllPlayAll.py~ diff --git a/AllPlayAll.py b/AllPlayAll.py index 04a030e..2e0c6ca 100644 --- a/AllPlayAll.py +++ b/AllPlayAll.py @@ -1,49 +1,35 @@ __author__ = "Paul Council & William Ezekiel" -__date__ = "November 19 2014" -__version__ = "1.0" - -from Game import * -from Registration import * -""" AllPlayAll Tournament Type, every player plays every other player in - 1 match""" -class AllPlayAll(Tournament): - def __init__(self,game,registration,rounds=1000): - """ Initialize AllPlayAll class. Requires Game, Registration - and Rounds. Rounds is optional and will be 1000 by default. - """ - if(rounds>0): - self.rounds = rounds - else: - self.rounds = 1000 - self.game = game - self.registration = registration +__date__ = "November 24 2014" +__version__ = "1.0.1" +#imports +import Tournament - def set_players(self): - """ Place all active players into tournament bracket.""" - self.bracket = self.registration.get_players() - - def create_next_match(self,i,j): - """Create a match consisting of two players. Players - are determined by positions i and j in bracket""" - #i == j will never happen - return [bracket[i],bracket[j]] +""" AllPlayAll Tournament Type, every player is in a match with every other player """ +class AllPlayAll(Tournament.Tournament): + + def __init__(self,rounds = 100): + """ Initialize AllPlayAll + :param rounds the number of rounds per match, 100 by default + """ + Tournament.Tournament.__init__(self) + # variables to help us pick players 1 and 2. + self.p = 0 # player 1 index + self.q = 1 # player 2 index + self.rounds = rounds - def play_match(self,match): - """ play match: play a game a certain number of rounds""" - self.game.connect() - for i in range(0,rounds): - self.game.play(match[0],match[1]) - # assuming games updates scoreboard on winner. - - + def create_next_match(self): + """ Create the next match """ + if self.q >= len(self.playerList): # Gone through all possible matchups. + return None + match = (self.playerList[self.p],self.playerList[self.q]) + self.q = self.q+1 + if self.q >= len(self.playerList): # if index out of bounds + self.p = self.p+1 + self.q = self.p+1 + return match def run(self): - """ Run the All-Play-All Tournament. - Each player plays all other players in one match. - """ - for i in range(0,len(self.bracket)): - for j in range(i+1,len(self.bracket)): - match = create_next_match(i,j) - play_match(match) - + """ Run the All-Play-All Tournament """ + super(AllPlayAll,self).run() + diff --git a/AllPlayAll.py~ b/AllPlayAll.py~ new file mode 100644 index 0000000..04a030e --- /dev/null +++ b/AllPlayAll.py~ @@ -0,0 +1,49 @@ +__author__ = "Paul Council & William Ezekiel" +__date__ = "November 19 2014" +__version__ = "1.0" + +from Game import * +from Registration import * +""" AllPlayAll Tournament Type, every player plays every other player in + 1 match""" +class AllPlayAll(Tournament): + def __init__(self,game,registration,rounds=1000): + """ Initialize AllPlayAll class. Requires Game, Registration + and Rounds. Rounds is optional and will be 1000 by default. + """ + if(rounds>0): + self.rounds = rounds + else: + self.rounds = 1000 + self.game = game + self.registration = registration + + + def set_players(self): + """ Place all active players into tournament bracket.""" + self.bracket = self.registration.get_players() + + def create_next_match(self,i,j): + """Create a match consisting of two players. Players + are determined by positions i and j in bracket""" + #i == j will never happen + return [bracket[i],bracket[j]] + + def play_match(self,match): + """ play match: play a game a certain number of rounds""" + self.game.connect() + for i in range(0,rounds): + self.game.play(match[0],match[1]) + # assuming games updates scoreboard on winner. + + + + def run(self): + """ Run the All-Play-All Tournament. + Each player plays all other players in one match. + """ + for i in range(0,len(self.bracket)): + for j in range(i+1,len(self.bracket)): + match = create_next_match(i,j) + play_match(match) + From 54a67d5e8c3aa5517235b0695c88a9ffbab98edd Mon Sep 17 00:00:00 2001 From: ezekie97 Date: Mon, 24 Nov 2014 16:21:58 -0500 Subject: [PATCH 12/20] Delete AllPlayAll.py~ --- AllPlayAll.py~ | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 AllPlayAll.py~ diff --git a/AllPlayAll.py~ b/AllPlayAll.py~ deleted file mode 100644 index 04a030e..0000000 --- a/AllPlayAll.py~ +++ /dev/null @@ -1,49 +0,0 @@ -__author__ = "Paul Council & William Ezekiel" -__date__ = "November 19 2014" -__version__ = "1.0" - -from Game import * -from Registration import * -""" AllPlayAll Tournament Type, every player plays every other player in - 1 match""" -class AllPlayAll(Tournament): - def __init__(self,game,registration,rounds=1000): - """ Initialize AllPlayAll class. Requires Game, Registration - and Rounds. Rounds is optional and will be 1000 by default. - """ - if(rounds>0): - self.rounds = rounds - else: - self.rounds = 1000 - self.game = game - self.registration = registration - - - def set_players(self): - """ Place all active players into tournament bracket.""" - self.bracket = self.registration.get_players() - - def create_next_match(self,i,j): - """Create a match consisting of two players. Players - are determined by positions i and j in bracket""" - #i == j will never happen - return [bracket[i],bracket[j]] - - def play_match(self,match): - """ play match: play a game a certain number of rounds""" - self.game.connect() - for i in range(0,rounds): - self.game.play(match[0],match[1]) - # assuming games updates scoreboard on winner. - - - - def run(self): - """ Run the All-Play-All Tournament. - Each player plays all other players in one match. - """ - for i in range(0,len(self.bracket)): - for j in range(i+1,len(self.bracket)): - match = create_next_match(i,j) - play_match(match) - From 71f541b51cb9dc8aa4abdea92aea5475ff070a87 Mon Sep 17 00:00:00 2001 From: ezekie97 Date: Mon, 24 Nov 2014 18:12:42 -0500 Subject: [PATCH 13/20] Fixed AllPlayAll.py problems, deleted AllPlayAll.py~ --- AllPlayAll.py | 5 ----- AllPlayAll.py~ | 49 ------------------------------------------------- 2 files changed, 54 deletions(-) delete mode 100644 AllPlayAll.py~ diff --git a/AllPlayAll.py b/AllPlayAll.py index 2e0c6ca..75e111e 100644 --- a/AllPlayAll.py +++ b/AllPlayAll.py @@ -28,8 +28,3 @@ def create_next_match(self): self.p = self.p+1 self.q = self.p+1 return match - - def run(self): - """ Run the All-Play-All Tournament """ - super(AllPlayAll,self).run() - diff --git a/AllPlayAll.py~ b/AllPlayAll.py~ deleted file mode 100644 index 04a030e..0000000 --- a/AllPlayAll.py~ +++ /dev/null @@ -1,49 +0,0 @@ -__author__ = "Paul Council & William Ezekiel" -__date__ = "November 19 2014" -__version__ = "1.0" - -from Game import * -from Registration import * -""" AllPlayAll Tournament Type, every player plays every other player in - 1 match""" -class AllPlayAll(Tournament): - def __init__(self,game,registration,rounds=1000): - """ Initialize AllPlayAll class. Requires Game, Registration - and Rounds. Rounds is optional and will be 1000 by default. - """ - if(rounds>0): - self.rounds = rounds - else: - self.rounds = 1000 - self.game = game - self.registration = registration - - - def set_players(self): - """ Place all active players into tournament bracket.""" - self.bracket = self.registration.get_players() - - def create_next_match(self,i,j): - """Create a match consisting of two players. Players - are determined by positions i and j in bracket""" - #i == j will never happen - return [bracket[i],bracket[j]] - - def play_match(self,match): - """ play match: play a game a certain number of rounds""" - self.game.connect() - for i in range(0,rounds): - self.game.play(match[0],match[1]) - # assuming games updates scoreboard on winner. - - - - def run(self): - """ Run the All-Play-All Tournament. - Each player plays all other players in one match. - """ - for i in range(0,len(self.bracket)): - for j in range(i+1,len(self.bracket)): - match = create_next_match(i,j) - play_match(match) - From 0c8535307fdb181729cffc341513b6ae126af598 Mon Sep 17 00:00:00 2001 From: TenLetters <10letterz@gmail.com> Date: Mon, 24 Nov 2014 18:26:42 -0500 Subject: [PATCH 14/20] deleted feature_Torunament.py --- feature_Tournament.py | 77 ------------------------------------------- 1 file changed, 77 deletions(-) delete mode 100644 feature_Tournament.py diff --git a/feature_Tournament.py b/feature_Tournament.py deleted file mode 100644 index 18c7d76..0000000 --- a/feature_Tournament.py +++ /dev/null @@ -1,77 +0,0 @@ -# Alex Ciaramella and Greg Suner -# Abstract Tournament Class - -#Tournament is observable while players are observers - -import Message - -class Tournament(Observable): - # set up a list of players when tournament is initialized - def __init__(self): - self.playerList = [] - self.game - - # run the tournament - def run(self): - self.begin_tournament() - while(True): - match = self.create_next_match() - if match == None: - break - self.play_match(match) - self.end_tournament() - - - # get a reference to the next game to be played - def create_next_match(self): - pass - - # register a player for the tournament by adding them to # the list of current players - def register_player(self, player): - self.playerList.append(player) - - # stores a reference to the type of game we will be playing - def set_game(self, game): - self.game = game - - # play the next match and return the results - def play_match(self, match): - self.start_match(match[0]) - result = self.play_game(match) - self.end_match(match[0], result) - - # plays each indvidual game in the match - def play_game(self, match): - for i in range(0, match[1]): - self.start_game(match[0]) - result = match.get_results(match[0]) - # need to find out definite structure of results!! - self.end_game(result[0], result[1], result[2]) - - # notifies players tournament has begun - def begin_tournament(self): - pass - - # Announces results of tournament to all players - def end_tournament(self): - pass - - # send a message containing a list of all the players in the current match - def start_match(self, players): - message = Message.get_match_start_message(players) - self.notify_all(message) - - # send a message containing the result of the match - def end_match(self,players, result): - message = Message.get_match_end_message(players, result) - self.notify_all(message) - - # send a message containing the players in the next game - def start_game(self, players): - message = Message.get_round_start_message(players) - self.notify_all(message) - - # send a message containing the players, moves, and result of the last game - def end_game(players, moves, result): - message = Message.get_round_end_message(players, moves, result) - self.notify_all(message) From 48508d4ce3f41bf8634cad6586ee969317f8cbd9 Mon Sep 17 00:00:00 2001 From: TenLetters <10letterz@gmail.com> Date: Mon, 24 Nov 2014 18:26:53 -0500 Subject: [PATCH 15/20] Delete feature_Tournament.pyc --- feature_Tournament.pyc | Bin 2817 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 feature_Tournament.pyc diff --git a/feature_Tournament.pyc b/feature_Tournament.pyc deleted file mode 100644 index 958797b1803d3d5c4b9ed9e9b3baa1a17e538a7e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2817 zcmb_eTW{P%6h5|hH@llnOK)5%K&X|_K2-FfJn&F)D?&oRf+mqFB7x5Bvc5zBBf&gIdW&WHaOA@tJe^&Ns(S{@NM;`A4-km-;Wk^>YmOA*LMv zkt{^^A;e-MIgBJvB>Ozz6x8C4^$XRzNNxQ@}UZ2$ww+|OFmX%BKfuoJCaXS zxF%+Ix`PPjjE5t}c!J?>V>%MK5J`1DjwC{ayHje-rqt8iP8Zp^t-dRq_dRYwnyR9A z&Mpq8SQVYz9Y}{Z^Q+3H8%#brJ@-RANz9gU zRV(Xn;OV?V1~x72nNLqLKYyl=XUo#A@u=6YLEDyj%aX!o5<2Q*((Rq_;g)JuUdP4J ztVCmgGr_MH-3TBx6?{S+!q=)6cW71AcNdRl3tR4DI07%xys5#u4kSpZ1E^7B+j2=g z!WpUnCY1sEZmR=bgIgOYCds|U4Aj8l$p@ds3bt0*= zJ|)NRLBH*t1>#WjKYgR8y&MKV0ChJI!k?b0V%S1EBjP?c{USNTj1cnlv&)f1;D@L~gh=OG+v}|0| zvr}c|Q8;k{92P~f!fG0lcG^~mj&>z(ZGodU4O!d?oSRU5fZ>LiB)SWDZpG`iNn;8R zo#dM~N!`~xcx((GV>Ild>1O;-F4$qo(Z&UlC3SdJ7au@Cg7nKe*GrZscxXLMXHeQ|i6W{ZXLJ9I-D2*=u~v6HZ&Q)SqcA7j+-43L&Fu@Jm! zKKCK4^9hHoCL*|*yeuWd-skzk+T^0=ECgoW#S?wa2S&YzTji2rTj~_{Ehv70QHOmq zoHd60U&|0;Zt$;`D=_~G{vm3*Xhq#Q;5V`F>rKEdoQbvK%^D5LK>^9UI?*?x|9p0YH=hnR@=x<~5w-`0(ccLlZEcNFHKhe@u-{NU{vdmWt z+!_sW0xf+d8tNNxW~b{G`tx4xFu?X9o+b20FXbq#uVgKV^H@ZZL`e0S$=Y1ONa4 From fa291ea10cc558ade7bf6b61246d510b9948d704 Mon Sep 17 00:00:00 2001 From: Greg Date: Mon, 24 Nov 2014 18:55:49 -0500 Subject: [PATCH 16/20] Update RPSGame.py updated indentation and documentation --- RPSGame.py | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/RPSGame.py b/RPSGame.py index 6c13343..24e87e9 100644 --- a/RPSGame.py +++ b/RPSGame.py @@ -5,28 +5,32 @@ class RPSGame(Game): ## this class simulates two players playing a game of rock, paper, scissors - def __init__(self): - super(RPSGame, self).__init__() + def __init__(self): + super(RPSGame, self).__init__() - def get_result(self, moves): - move1, move2 = moves # unpack the tuple that was passed as a parameter - x = is_legal(move1) - y = is_legal(move2) - result = (0,0) # result is a tuple of the points that each player has earned respectively - if x and y: - if move1 == move2: - result = (1,1) - elif (move1 == 0 and move2 != 1) or (move1 == 1 and move2 != 2) or (move1 == 2 and move2 != 0): - result = (1,0) + def get_result(moves): + # unpack the tuple that was passed as a parameter + move1, move2 = moves + x = is_legal(move1) + y = is_legal(move2) + result = (0, 0) + if x and y: + if move1 == move2: + result = (1, 1) + elif (move1 == 0 and move2 != 1) \ + or (move1 == 1 and move2 != 2) \ + or (move1 == 2 and move2 != 0): + # result is tuple with points each player has earned respectively + result = (1, 0) + else: + result = (0, 1) + elif x and not y: + result = (1, 0) + elif not x and y: + result = (0, 1) else: - result = (0,1) - elif x and not y: - result = (1,0) - elif not x and y: - result = (0,1) - else: - result = result - return result + result = result + return result - def is_legal(self, move): - return move in (0, 1, 2) + def is_legal(move): + return move in (0, 1, 2) From 4b7b46e93f734abc623b3fd96b94ca13dddee989 Mon Sep 17 00:00:00 2001 From: geebzter Date: Mon, 24 Nov 2014 16:58:10 -0800 Subject: [PATCH 17/20] Minor fixes --- RPSGame.py | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/RPSGame.py b/RPSGame.py index 24e87e9..240ecd7 100644 --- a/RPSGame.py +++ b/RPSGame.py @@ -4,33 +4,33 @@ class RPSGame(Game): - ## this class simulates two players playing a game of rock, paper, scissors - def __init__(self): - super(RPSGame, self).__init__() + # # this class simulates two players playing a game of rock, paper, scissors + def __init__(self): + super(RPSGame, self).__init__() - def get_result(moves): - # unpack the tuple that was passed as a parameter - move1, move2 = moves - x = is_legal(move1) - y = is_legal(move2) + def get_result(self, moves): + # unpack the tuple that was passed as a parameter + move1, move2 = moves + x = self.is_legal(move1) + y = self.is_legal(move2) + + if x and y: + if move1 == move2: result = (0, 0) - if x and y: - if move1 == move2: - result = (1, 1) - elif (move1 == 0 and move2 != 1) \ - or (move1 == 1 and move2 != 2) \ - or (move1 == 2 and move2 != 0): - # result is tuple with points each player has earned respectively - result = (1, 0) - else: - result = (0, 1) - elif x and not y: - result = (1, 0) - elif not x and y: - result = (0, 1) - else: - result = result - return result + elif (move1 == 0 and move2 != 1) \ + or (move1 == 1 and move2 != 2) \ + or (move1 == 2 and move2 != 0): + # result is tuple with points each player has earned respectively + result = (1, 0) + else: + result = (0, 1) + elif x and not y: + result = (1, 0) + elif not x and y: + result = (0, 1) + else: + result = (0, 0) + return result - def is_legal(move): - return move in (0, 1, 2) + def is_legal(self, move): + return isinstance(move,int) and (move in (0, 1, 2)) From c28992bb393a9592e1b1259de5f20b34c1e258a8 Mon Sep 17 00:00:00 2001 From: geebzter Date: Mon, 24 Nov 2014 17:26:10 -0800 Subject: [PATCH 18/20] Tournament received several fixes. RPSPlayerExample had a faulty comment that was fixed. AllPlayAll had a minor fix --- AllPlayAll.py | 3 +- RPSPlayerExample.py | 7 ++-- Tournament.py | 83 ++++++++++++++++++++++++++++----------------- 3 files changed, 56 insertions(+), 37 deletions(-) diff --git a/AllPlayAll.py b/AllPlayAll.py index 75e111e..ea13ceb 100644 --- a/AllPlayAll.py +++ b/AllPlayAll.py @@ -20,9 +20,10 @@ def __init__(self,rounds = 100): def create_next_match(self): """ Create the next match """ + self.playerList = self.get_players() if self.q >= len(self.playerList): # Gone through all possible matchups. return None - match = (self.playerList[self.p],self.playerList[self.q]) + match = ((self.playerList[self.p],self.playerList[self.q]), self.rounds) self.q = self.q+1 if self.q >= len(self.playerList): # if index out of bounds self.p = self.p+1 diff --git a/RPSPlayerExample.py b/RPSPlayerExample.py index 3d19c97..fd0b834 100644 --- a/RPSPlayerExample.py +++ b/RPSPlayerExample.py @@ -36,9 +36,9 @@ def notify(self, msg): players = msg.get_players() # Check if this message is for me and only then proceed if (players[0] == self) or (players[1] == self): - # In this case, (by convention) the info is a tuple of the moves made and result e.g. ((1, 0), 1) which + # In this case, (by convention) the info is a tuple of the moves made and result e.g. ((1, 0), (1,0)) which # means player 1 played paper (1), the player 2 played rock(0) and the result was that - # player 1 won + # player 1 won (got 1 point) and player 2 lost (got 0 point) moves, result = msg.get_info() @@ -88,9 +88,8 @@ def play(opponents_moves): player = RPSPlayerExample() opponent = RPSPlayerExample() players = [opponent,player] - fakeinfo = ((0,1),1) - fakeresult = 1 fakemoves = (1,2) + fakeresult = (0,1) player.notify(Message.Message.get_match_start_message(players)) player.notify(Message.Message.get_round_start_message(players)) diff --git a/Tournament.py b/Tournament.py index 5c18662..72a6dfb 100644 --- a/Tournament.py +++ b/Tournament.py @@ -1,77 +1,96 @@ # Alex Ciaramella and Greg Suner # Abstract Tournament Class -#Tournament is observable while players are observers +# Tournament is observable while players are observers import Message +import Observable -class Tournament(Observable): +class Tournament(Observable.Observable): # set up a list of players when tournament is initialized def __init__(self): + Observable.Observable.__init__(self) self.playerList = [] - self.game + self.game = None + + # Returns the players in the tournament + def get_players(self): + return self.playerList # run the tournament - def run(self): + def run(self): self.begin_tournament() - while(True): - match = self.create_next_match() - if match == None: - break - self.play_match(match) + while (True): + match = self.create_next_match() + if match == None: + break + self.play_match(match) self.end_tournament() - - + + # get a reference to the next game to be played def create_next_match(self): pass - # register a player for the tournament by adding them to # the list of current players + # register a player for the tournament by adding them to + # the list of current players def register_player(self, player): self.playerList.append(player) + self.add_observer(player) # stores a reference to the type of game we will be playing def set_game(self, game): self.game = game + + # Computes the result of a round based on the moves made by the players + def get_result(self, moves): + return self.game.get_result(moves) + # play the next match and return the results def play_match(self, match): - self.start_match(match[0]) - result = self.play_game(match) - self.end_match(match[0], result) + players = match[0] + self.start_match(players) + result = self.play_rounds(match) + self.end_match(players, result) # plays each indvidual game in the match - def play_round(self, match): - for i in range(0, match[1]): - self.start_round(match[0]) - result = match.get_results(match[0]) - # need to find out definite structure of results!! - self.end_round(result[0], result[1], result[2]) - - # notifies players tournament has begun + def play_rounds(self, match): + players = match[0] + rounds = match[1] + for i in range(rounds): + self.start_round(players) + moves = [] + for p in players: + moves.append(p.play()) + result = self.get_result(moves) + self.end_round(players, moves, result) + + + # notifies players tournament has begun def begin_tournament(self): - pass - - # Announces results of tournament to all players + pass + + # Announces results of tournament to all players def end_tournament(self): pass # send a message containing a list of all the players in the current match def start_match(self, players): - message = Message.get_match_start_message(players) + message = Message.Message.get_match_start_message(players) self.notify_all(message) # send a message containing the result of the match - def end_match(self,players, result): - message = Message.get_match_end_message(players, result) + def end_match(self, players, result): + message = Message.Message.get_match_end_message(players, result) self.notify_all(message) # send a message containing the players in the next game def start_round(self, players): - message = Message.get_round_start_message(players) + message = Message.Message.get_round_start_message(players) self.notify_all(message) # send a message containing the players, moves, and result of the last game - def end_round(players, moves, result): - message = Message.get_round_end_message(players, moves, result) + def end_round(self, players, moves, result): + message = Message.Message.get_round_end_message(players, moves, result) self.notify_all(message) From 78908fce826e92c6c7323be0d86d6f2f7b2b7e37 Mon Sep 17 00:00:00 2001 From: Greg Date: Mon, 1 Dec 2014 18:37:04 -0500 Subject: [PATCH 19/20] Added player --- GSACPlayer.py | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 GSACPlayer.py diff --git a/GSACPlayer.py b/GSACPlayer.py new file mode 100644 index 0000000..7f67d52 --- /dev/null +++ b/GSACPlayer.py @@ -0,0 +1,103 @@ + # Greg Suner and Alex Ciarmella + # Concrete Player Class + +import Player +import Message + +class GSACPlayer(Player.Player): + + def __init__(self): + # Call super class constructor + Player.Player.__init__(self) + self.reset() + + def play(self): + return RpsPlayingStrategy.play(self.opponents_moves) + + def reset(self): + self.opponents_moves = [] + + def get_name(self): + return self.name + + def set_name (self, playername): + self.name = playername + + def notify(self, msg): + + # We use notifications to store opponent's moves in past rounds + # Process match-start and round-end messages + # At the start of the match, clear opponent moves history since a new match has started + # At the end of a round, append move to opponent's move history. Move history is used + # to compute the next move played. + if msg.is_match_start_message(): + players = msg.get_players() + if players[0] == self or players[1] == self: + self.reset() + elif msg.is_round_end_message(): + players = msg.get_players() + # Check if this message is for me and only then proceed + if (players[0] == self) or (players[1] == self): + # In this case, (by convention) the info is a tuple of the moves made and result e.g. ((1, 0), 1) which + # means player 1 played paper (1), the player 2 played rock(0) and the result was that + # player 1 won + + moves, result = msg.get_info() + + # RPS is a two person game; figure out which of the players is me + # and which one is the opponent + if players[0] == self: + opponent = 1 + else: + opponent = 0 + + # Update opponent's past moves history + self.opponents_moves.append(moves[opponent]) + +class RpsPlayingStrategy(object): + + #Decides next move based on opponents past moves + #Looks for what opponent throws the most and tries to counter it. 0-rock, 1-paper, 2-scissors + #Takes list of opponents past moves + def play(pastmoves): + rock, paper, scissors = 0, 0, 0 + + for index, move in enumerate(pastmoves): + + if move == 0: + rock += 1 + elif move == 1: + paper += 1 + else: + scissors += 1 + else: + return 0 + + #Look for most thrown move and throw counter + if rock > paper and rock > scissors: + return 0 + elif paper > rock and paper > scissors: + return 2 + elif scissors > rock and scissors > paper: + return 1 + else: #Arbitrary throw if 2 or 3 are thrown evenly + return 0 + + + +# Test driver +# Run by typing "python3 GSACPlayer.py" + +if __name__ == "__main__": + player = GSACPlayer() + opponent = GSACPlayer() + players = [opponent,player] + fakeinfo = ((0,1),1) + fakeresult = 1 + fakemoves = (1,2) + + player.notify(Message.Message.get_match_start_message(players)) + player.notify(Message.Message.get_round_start_message(players)) + move = player.play() + print ("Move played: ", move) + player.notify(Message.Message.get_round_end_message(players,fakemoves,fakeresult)) \ No newline at end of file From 659f2c7a305ae4910822f80e794328b8b4d3a174 Mon Sep 17 00:00:00 2001 From: Greg Date: Mon, 8 Dec 2014 21:57:40 -0500 Subject: [PATCH 20/20] Fixed missing name --- GSACPlayer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/GSACPlayer.py b/GSACPlayer.py index 7f67d52..4b25ff6 100644 --- a/GSACPlayer.py +++ b/GSACPlayer.py @@ -10,6 +10,7 @@ def __init__(self): # Call super class constructor Player.Player.__init__(self) self.reset() + self.name = "Alex and Greg" def play(self): return RpsPlayingStrategy.play(self.opponents_moves)