Detecting loops with the Beamsplitter

We recently released Khet 2.0 for PC, Mac and Linux and have been working on the Beamsplitter expansion piece (among other things).

The Beamsplitter piece lets the laser pass through and also reflects it at a 90-degree angle. This changes the concept of the laser from being a linked-list to being a directed-graph. This makes most of the code become recursive, but also leads to an interesting challenge: easily detecting infinite-loops.

We could use a heavy-handed approach of storing a record of every beamsplitter and every side that a laser comes out of, then comparing it to results of any new beamsplitter hits, to see if anything changed. However, it turns out there are some generalities that may let us do it more gracefully.
eye of horus beamsplitter diagram
In this diagram, the laser source at “A” gets reflected to “B” and also travels through to “C” while the direction “D” is not affected yet. Regardless of the rotation of the beamsplitter, if we follow this key, the following rules will always be true if a laser hits the Beamsplitter again on any of the 4 surfaces:

  • “A”: If “A” is hit (which I’m not sure is possible since I think it would require a loop to already have ended), then nothing changes. The inbound laser can be considered a “closed loop” ending.
  • “B” & “C”: If either of these spots are hit, then there will be a new exit-point at “D”. Any future hits to this same Beamsplitter will be “closed loops” regardless of where they hit.
  • “D”: Hitting here has used up the last junction and is a “closed loop”. Any future hits to this same Beamsplitter will be “closed loops” regardless of where they hit.

Also convenient is that we only need to detect loops at Beamsplitters. This will let some laser-segments overlap each other occasionally, but they will only overlap once before hitting a Beamsplitter, so there is no danger of infinite-looping as long as this logic is enforced at each Beamsplitter.

That was just a random tech rambling. Hope it was interesting! 🙂

EDIT: Incidentally, I finished writing the laser logic and the brute-force approach ended up being really simple & with no real overhead so I just went that way. Oh well, I was proud of myself while I thought it mattered. ;).

Announcing our next game: Khet 2.0 for Xbox 360!

Khet 2.0
Keeping up with the exciting pace of this year so far… we have an awesome announcement to make:

BlueLine Game Studios has been given an exclusive license to bring the extremely popular Khet 2.0 board game to Xbox!

Khet 2.0 is an Egyptian-themed two-player game with real lasers. It has been growing in popularity world-wide, and has a successful iPhone/iPad version.

The game is already well into development, and we are using the same board game engine that we wrote while making Hive for Xbox. The Xbox version of Khet 2.0 is planned to have single-player (against AI), local multiplayer, pass-n-play (if you only have one controller), online multiplayer, full 3D graphics & camera-control, a global highscores list… and frickin’ lasers!

If you want to be notified when the game goes into Alpha/Beta testing or for the final release, please sign up for the BlueLine Games “Release Announcements” mailing list.