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)
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)
def testBallOneMoveDoesNotAffectBoard(self): pongGame = Pong() ballPosition = pongGame.ballPosition pongGame = pongGame.makeMove(1, NOTHING) np.testing.assert_array_almost_equal(ballPosition, pongGame.ballPosition)
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())
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))
def testGameNotEndedAfterMoves(self): pongGame = Pong() pongGame.makeMove(1, NOTHING) pongGame.makeMove(2, NOTHING) self.assertFalse(pongGame.gameEnded())
def testPlayersMultipleMovesThrowsValueError(self): pongGame = Pong() pongGame.makeMove(1, UP) with self.assertRaises(ValueError): pongGame.makeMove(1, UP)