Things I Learned in Competition 9

I don't know how long this will last, but I thought I might make a list of things I learned while doing Competition #9.

Random Corruption

The Random class can get corrupted when accessed by multiple threads. If this happens, it just starts to return 0 constantly. The Random class should probably be a different instance per thread, or it should be placed in a lock.

The ThreadStatic Attribute

As a solution to the previous point, there is a [ThreadStatic] attribute that you can apply to anything that is static. What it means is that rather than having a value shared across all instances of a class, it is shared across all instances of a class but with a unique instance per thread.

Circle Defined by Two Points and One Direction at a Point

A stumbled into a need to define a circle from two points (P=Position, T=Target), one of which has a direction (D).

The center of the circle (C) can be computed by:

1. Find the bisecting line (b) of P and T.
2. Compute a vector N that is orthogonal to D.
3. Project P onto b along N.

The radius (r) of the circle is |P - C|, which can also be verified because it should be the same radius as |T - C|.