Exemple #1
0
    def testPlayerBothZeroRewardIfGameGoing(self):
        pongGame = Pong()

        pongGame.makeMove(1, NOTHING)
        pongGame.makeMove(2, NOTHING)

        self.assertEqual(pongGame.getReward(1), 0)
        self.assertEqual(pongGame.getReward(2), 0)
Exemple #2
0
    def testBallMovesAfterTwoMoves(self):
        pongGame = Pong()

        ballPos = pongGame.ballPosition
        ballVelocity = pongGame.ballVelocity

        pongGame = pongGame.makeMove(1, UP)
        pongGame = pongGame.makeMove(2, NOTHING)

        np.testing.assert_array_almost_equal(
            np.array(
                [ballPos[0] + ballVelocity[0], ballPos[1] + ballVelocity[1]]),
            pongGame.ballPosition)
Exemple #3
0
    def testBallOneMoveDoesNotAffectBoard(self):
        pongGame = Pong()
        ballPosition = pongGame.ballPosition

        pongGame = pongGame.makeMove(1, NOTHING)

        np.testing.assert_array_almost_equal(ballPosition,
                                             pongGame.ballPosition)
Exemple #4
0
    def testGameEndedAfterWinningMove(self):
        ballPosition = np.array([99.5, 2])
        ballVelocity = np.array([2, 0.1])
        pongGame = Pong(ballVelocity, ballPosition)

        pongGame = pongGame.makeMove(1, NOTHING)
        pongGame = pongGame.makeMove(2, NOTHING)

        self.assertTrue(pongGame.gameEnded())
Exemple #5
0
    def testPlayerTwoNegativeRewardIfLost(self):
        ballPosition = np.array([99.5, 2])
        ballVelocity = np.array([2, 0.1])
        pongGame = Pong(ballVelocity, ballPosition)
        expectedReward = -100

        pongGame = pongGame.makeMove(1, NOTHING)
        pongGame = pongGame.makeMove(2, NOTHING)

        self.assertEqual(expectedReward, pongGame.getReward(2))
Exemple #6
0
    def testGameNotEndedAfterMoves(self):
        pongGame = Pong()
        pongGame.makeMove(1, NOTHING)
        pongGame.makeMove(2, NOTHING)

        self.assertFalse(pongGame.gameEnded())
Exemple #7
0
 def testPlayersMultipleMovesThrowsValueError(self):
     pongGame = Pong()
     pongGame.makeMove(1, UP)
     with self.assertRaises(ValueError):
         pongGame.makeMove(1, UP)