In a molecular docking, the affinity between a protein and a ligand is determined using what is called score functions. Each docking software has its own score function. These score functions are created/modified by the software developers and, in principle, they are not interchangeable: you can not compare two docking studies made with different docking software.
There are score functions (like those from GLIDE and AUTODOCK) that roughly represent the ligand/protein binding energy. In both cases, the score functions are in units of kcal/mol (or energy/mol) and the lower the value is, the better the docking is.
Other score functions like ChemPLP (used in PLANTS and GOLD software) are dimensionless and don't have a direct physical/chemical meaning. In this case, the lower values also represent the best docking.
There are also docking software were the score function return positive value, where higher (positive) score represents a better docking pose.
The score functions are designed in order to take into account different interactions types between the ligand and the protein. These interactions include electrostatic, hydrophobic, hydrophilic, and hydrogen interactions, for example. They can also be designed using a set of experimental binding data ($IC_{50}$, inhibition constant -$k_i$-, for example). The X-SCORE function is one that include three empirical scoring functions.