Wednesday, January 19, 2011

End Course Project 12: Programming the bomb

One of the most important roles it the Lego Strike game, plays the bomb. It’s an NXT unit equipped with 2 lights (green and red), a touch sensor, a motor, an IR ball and build-in LCD display (see Picture 30 : Bomb unit with active countdown). Lights are used to inform player (Counter Terrorist) if he cuts the right cable. The green light flashes on correct color and the red one on incorrect. Motor has a function of claws which holds to terrorist unit. They open only when the terrorist plants the bomb.

The touch sensor is used as a trigger for a state “defusable”. It is important to mention that there was a bouncing problem we had to solve. During the drive the IR ball was bouncing on the touch sensor causing it to trigger a defusable state in the wrong moment. There was also the same problem while the bomb was planted and CTU was trying to push the ball off the bomb. We solved this problem by simply giving a 2 seconds delay during which we checked if the touch sensor was pressed again. 

Picture 37 : How to give a delay for the touch sensor in order to avoid taking ball bouncing into account

When counter terrorist pushes the IR ball from it, the bomb will generate and send the color sequence which is a string of 10 letters [ygbr] where y-yellow, g-green, b-blue, r-red. 

LCD display shows the countdown timer. We used image converter[1] which can convert general format images into LeJOS NXJ source code or LeJOS NXT format images and saved them in the source code file. We may use that countdown timer on NTX LCD for further improvements for example we may hide remaining time from game interface so it will be only visible on the bomb.

Picture 38 : Bomb unit with active countdown

The bomb is running through different states that are (see also Picture 31: Block diagram of bomb states and Picture 32: Bomb decision diagram):

1.       Waiting for PC connection – is passed when there is a connection between host and the bomb (when the game is launched).
2.       Waiting for Game Start – is passed when a method recievedNewMessage receives a “GT####” message with the game time in seconds.
3.       Waiting for planted – after the game is started, the bomb can explode (random chance or timeout) and can be planted. 
4.       Waiting for “defusable” – when the bomb is planted it can be set to “defusable” (by pushing the IR ball off) or can explode because of timeout or random chance.
5.       Waiting for Defuse Sequence (but could explode or be defused)

Picture 39: Block diagram of bomb states

Picture 40: Bomb decision diagram

During the game there is a chance that the bomb will explode without warning (sudden death mode). Here are the chances (Default, editable values):

·         For the first half time the chance is 0%
·         For next ¾ of time the chance raises to 1%
·         Between ¾ and 7/8 of game time the chance is 5%
·         And from 7/8 till 8/8 of game time the chance is 15%

The source code for Sudden death mode:

Picture 41 : source code for Sudden Death mode

When the bomb is becoming defusable (and each time CTU will cut incorrect cable), it will generate a sequence of randomly placed colors in a string.

Method checkSequence will verify if the cable cut was correct:

Picture 42 : checking that the cable cut is correct

No comments:

Post a Comment