Skip to content
Ayush edited this page Jan 21, 2021 · 8 revisions

Welcome to the gamePyd wiki!

Hello, do you wanna mess around with games with your pet snake ?? You came to the right page then!!

Documentation

Reading Inputs

Reading capabilities are provided by the rPad class in in readPad.py. It's initialization is as simple as choosing port number of the gamepad you want to observe. By default, it'll read controller 1

>>> from gamepyd import *
>>> foo=rPad() #Supported ports are 1,2,3,4
Now reading gamepad#1

Convenience Methods

We've tried to cover most of the common usage scenarios:

Record

One generally wants to capture a sequence of inputs, this can be done with record. It records for duration seconds, polling rate times per second, optionally, writing a DataFrame to a file named file (if the file already exists, it'll be overwritten). Finally, it returns a DataFrame with gamepad-state dictionaries as rows, with the addition of: time in nanoseconds, time difference between consequent reads in milliseconds and error from the requested rate.

foo.record(duration=5, rate=float(1 / 120), file="",type="df",) #These are the default values

Note that once invoked, there's no pause before the capture starts, so you'll ideally want to switch to the game immediately.

Capture

Capture is similar to record, with the only twist being that instead of recording for a pre-specified duration, it records until a particular button is pressed.

LEGO(TM)

Following is a description of the blocks I used to build the above functions, provided for reference and convenience. The read property provides a simple way to access the instantaneous state of the corresponding gamepad as a dictionary; With keys referring to different inputs on the controller. Buttons and D-pad values are booleans. Each analog stick has one value for its x-axis, and one for y-axis, both being between 32767 and -32767. The triggers' values are stored as an unsigned 8-bit integer, i.e. lie between 0 and 255.

>>> foo.read
{'LT': 255, 'RT': 80, 'Lx': -31638, 'Ly': -18937, 'Rx': 395, 'Ry': 602, 'UP': True, 'DOWN': False, 'LEFT': True, 'RIGHT': False,
 'START': False, 'SELECT': False, 'L3': False, 'R3': False, 'LB': True, 'RB': False, 'A': False, 'B': True, 'X': False, 'Y': Fal
se}

_ - [] TODO: Also, the type is there as a placeholder for now, the intention is to add support for saving and/or returning different formats. Namely pytorch and tensorflow types._

Emulating gamepad(s)

Philosophy