Advertisement

Efficient Implementation of Monte Carlo Player for Card Game

Started by July 02, 2013 09:31 PM
9 comments, last by Angus Hollands 11 years, 2 months ago

Before I write this, let me just state that I've made the (uninformed) decision to assume you're not well versed in Python optimisation. If you are, then fantastic, this post will be largely irrelevant.

Python can be slower than C/++ in certain areas, but there are often times when the order of magnitude of the time it takes to complete a task is simply unnecessary. Python has a few good articles on the subject around the web, but things to consider: (most apply to loops)

  1. Make localised namespace lookups instead of global ones (eg. don't look up an attribute on x.y.z if x is outside the current namespace. Instead, store a reference to x.y as w, and lookup there.
  2. Avoid tight loops, and where they're necessary, move as many operations outside the inner loops as possible.
  3. Avoid throwing away objects after creating them, instead use a generator or other structures that don't create the entire object in one swoop.
  4. Make use of lazy condition evaluation to save making unnecessary calculations.

Using PyPy is also a very good way of improving performance, but be aware you should learn its ins-and-outs in order to best gain performance. Good luck.

This topic is closed to new replies.

Advertisement