from random import choice
import unittest

# def choice(xs):
#     return xs[0]


class RPSGame:
    shapes = ['rock', 'paper', 'scissors']
    draws = [('rock', 'rock'), ('paper', 'paper'), ('scissors', 'scissors')]
    first_wins = [('rock', 'scissors'), ('scissors', 'paper'), ('paper', 'rock')]
    
    def _evaluate(self, player_move, computer_move):
        if (player_move, computer_move) in RPSGame.draws:
            return "Draw!"
        elif (player_move, computer_move) in RPSGame.first_wins:
            return "Player wins!"
        else:
            return "Computer wins!"

    def _computer_move(self):
        return choice(RPSGame.shapes)

    def _verify_move(self, player_move):
        if player_move not in RPSGame.shapes:
            raise Exception("Wrong input!")
        return player_move

    def play(self, rounds=1):
        for i in range(rounds):
            player_move = self._verify_move(input("[rock,paper,scissors]: "))
            computer_move = self._computer_move()
            winner = self._evaluate(player_move, computer_move)
            print(20 * "-")
            print("You played: %s" % player_move)
            print("Computer played: %s" % computer_move)
            print(winner)
            print(20 * "-")


class RPSGameTests(unittest.TestCase):
    def setUp(self):
        self.rps = RPSGame()

    def test_computer_move(self):
        moves = {'rock': 0, 'paper': 0, 'scissors': 0}
        n = 100000
        for i in range(n):
            cp = self.rps._computer_move()
            moves[cp] += 1
        for shape in moves:
            # self.assertEquals(moves[shape] / n, 1/3)
            self.assertAlmostEqual(moves[shape] / n, 1/3, 2)

    def test_verify_move(self):
        pairs = [('rock', 'rock'), ('paper', 'paper'), ('scissors', 'scissors')]
        for pair in pairs:
            self.assertEqual(self.rps._verify_move(pair[0]), pair[1])

        wrong_input = 'something'
        self.assertRaises(Exception, self.rps._verify_move, wrong_input)

if __name__ == '__main__':
    modes = ["test", "main"]
    switch = input("[test,main]: ")
    if switch == "test":
        unittest.main()
    else:
        rps = RPSGame()
        rps.play(rounds=3)


@@ -40,46 +40,8 @@
 st%0A%0A
-# def choice(xs):%0A#     return xs%5B0%5D%0A%0A
 %0Acla
@@ -56,20 +56,22 @@
 me:%0A    
-shap
+gestur
 es = %5B'r
@@ -105,90 +105,14 @@
     
-draws = %5B('rock', 'rock'), ('paper', 'paper'), ('scissors', 'scissors')%5D%0A    first
+player
 _win
@@ -185,16 +185,44 @@
 )%5D%0A    %0A
+    # the rules of the game%0A
     def 
@@ -277,17 +277,16 @@
      if 
-(
 player_m
@@ -280,33 +280,35 @@
   if player_move
-,
+ ==
  computer_move) 
@@ -309,26 +309,8 @@
 move
-) in RPSGame.draws
 :%0A  
@@ -391,13 +391,14 @@
 ame.
-first
+player
 _win
@@ -485,16 +485,34 @@
 wins!%22%0A%0A
+    # computer AI%0A
     def 
@@ -567,16 +567,46 @@
 ame.
-shapes)%0A
+gestures)%0A%0A    # verify player's input
 %0A   
@@ -681,20 +681,22 @@
 RPSGame.
-shap
+gestur
 es:%0A    
@@ -763,16 +763,69 @@
 r_move%0A%0A
+    # play n rounds of the game against the computer%0A
     def 
@@ -1368,227 +1368,886 @@
 est_
-computer_move(self):%0A        moves = %7B'rock': 0, 'paper': 0, 'scissors': 0%7D%0A        n = 100000%0A        for i in range(n):%0A            cp = self.rps._computer_move()%0A            moves%5Bcp%5D += 1%0A        for shape in moves:
+evaluate(self):%0A        # 1. test for draw%0A        for g in RPSGame.gestures:%0A            self.assertEqual(self.rps._evaluate(g, g), 'Draw!')%0A        # 2. test for player victory%0A        for g1, g2 in RPSGame.player_wins:%0A            self.assertEqual(self.rps._evaluate(g1, g2), 'Player wins!')%0A        # note that we don't have to test for the conditions when%0A        # computer wins as there are no other possibilities%0A%0A    def test_computer_move(self):%0A        moves = %7B'rock': 0, 'paper': 0, 'scissors': 0%7D%0A        n = 100000%0A        for i in range(n):%0A            cp = self.rps._computer_move()%0A            moves%5Bcp%5D += 1%0A        for gesture in RPSGame.gestures:%0A            # 1. Due to the fact the fraction 1/3 is infinite%0A            # assertEqual will never equate to true (unless n%0A            # is infinite). Therefore, we need to test%0A            # for almost equal.
 %0A   
@@ -2277,20 +2277,21 @@
 qual
-s
 (moves%5B
-shap
+gestur
 e%5D /
@@ -2299,16 +2299,115 @@
 n, 1/3)%0A
+            # 2. Test for almost equal with the precision of%0A            # up to 2 decimal places.%0A
         
@@ -2443,12 +2443,14 @@
 ves%5B
-shap
+gestur
 e%5D /

Clean up final implementation of the game.