It’s like an ELO or MMR system, where each match you play updates the estimate of your strength and lowers the uncertainty of your strength, together which form your score. Let’s say you beat a player much stronger than your current rank–you’ll gain many points. If you beat a player much weaker than your current rank, you’ll gain a very small number of points. Inverse for losses: lose to someone weaker, lose many points; lose to someone stronger, lose few points.
The implementation of the math is open source here.