SHARE
TWEET

SIDE OF PONG

a guest Jun 25th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def trainingDataGeneratorForAI(ball, ballDirX, paddle1):
  2.     paddle1yInc = 0
  3.  
  4.     # TODO 2 - part A - write the logic for your training program
  5.     # Leverage conventionalPlayer code OR leverage your own manual play  
  6.     # Call recordData(???, ???, ???, ...) to record the training data in a csv file
  7.    
  8.     if ball.x < WINDOWWIDTH/2:
  9.         if ballDirX == -1:
  10.             if paddle1.centery < ball.centery:
  11.                 paddle1yInc = 1
  12.             else:
  13.                 paddle1yInc = -1                
  14.             recordData(ballDirX, ball.centery, paddle1.centery, paddle1yInc)
  15.        
  16.         paddle1.y += paddle1yInc      
  17.     return paddle1
  18.  
  19. # pong playing DNN
  20. def neuralNetworkAI(ball, ballDirX, paddle1):  
  21.     paddle1yInc = 0
  22.    
  23.     thisFeatureInstance = np.array([
  24.         [ballDirX, ball.centery, paddle1.centery]
  25.     ])
  26.    
  27.     labelMatrix = model.predict(thisFeatureInstance)
  28.     paddle1yInc = labelMatrix[0][0]
  29.    
  30.     if paddle1yInc > 0.6:
  31.         paddle1yInc = 1
  32.     elif paddle1yInc < -0.6:
  33.         paddle1yInc = -1
  34.    
  35.    
  36.  
  37.    
  38.     paddle1.y += paddle1yInc
  39.     return paddle1
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top