You are viewing a single comment's thread. Return to all comments →

I solved the problem using the following tricks. I guess my solution is not perfect but I hope it can help who struggled.

Assume using the following time:

N = 0 (initial board - time of bomb is 3)

N = 1 (do nothing - time of bomb is reduced to 2)

N = 2 (time of existing bombs is reduced to 1, add new bombs to empty cells with time 3)

N = 3 (boms with time 1 will exploded, new boms added in previous steps have time reduced to 2).

I use the following test to illustrate my algorithm.

4 3

O..O

.O..

....

I convert it to the following arrays in my solution:

3 0 0 3

0 3 0 0

0 0 0 0

(3 is bomb with time 3. 0 is empty cells i.e has no bombs).

Below are some observation:

1/ When N = 4, N = 6, ..., board is full of bombs.

2/ Board at N = 3 is the same with board at N = 7, N = 11

3/ Board at N = 5 is the same with board at N = 9, N = 13

4/ To solve board at N = 3. Calculate board at N = 2

Given example a board with N = 0 N = 2

3 0 0 3 1 3 3 1

0 3 0 0 -> 3 1 3 3

0 0 0 0 3 3 3 3

After 1 second (N = 3), cell with 1 will explode to 0 and make neighbour cells become 0. Cells with 3 become 2.

N = 3

2 0 2 2

5/ To solve board at N = 5. Use board at N = 3. N = 3 N = 5

0 0 0 0 2 2 2 2

0 0 0 0 -> 0 2 0 0

2 0 2 2 0 0 0 0

Note that cells with 0 become 2 and cells with 2 become 0. This is because

- cells with 0 is empty cells and it will be populated with bombs at previous step (N = 4).

- cells with 2 is bomb cells and it will explode to 0 and make neighbour cells become 0.

## The Bomberman Game

You are viewing a single comment's thread. Return to all comments →

I solved the problem using the following tricks. I guess my solution is not perfect but I hope it can help who struggled.

Assume using the following time:

N = 0 (initial board - time of bomb is 3)

N = 1 (do nothing - time of bomb is reduced to 2)

N = 2 (time of existing bombs is reduced to 1, add new bombs to empty cells with time 3)

N = 3 (boms with time 1 will exploded, new boms added in previous steps have time reduced to 2).

I use the following test to illustrate my algorithm.

4 3

O..O

.O..

....

I convert it to the following arrays in my solution:

3 0 0 3

0 3 0 0

0 0 0 0

(3 is bomb with time 3. 0 is empty cells i.e has no bombs).

Below are some observation:

1/ When N = 4, N = 6, ..., board is full of bombs.

2/ Board at N = 3 is the same with board at N = 7, N = 11

3/ Board at N = 5 is the same with board at N = 9, N = 13

4/ To solve board at N = 3. Calculate board at N = 2

Given example a board with N = 0 N = 2

3 0 0 3 1 3 3 1

0 3 0 0 -> 3 1 3 3

0 0 0 0 3 3 3 3

After 1 second (N = 3), cell with 1 will explode to 0 and make neighbour cells become 0. Cells with 3 become 2.

N = 3

0 0 0 0

0 0 0 0

2 0 2 2

5/ To solve board at N = 5. Use board at N = 3. N = 3 N = 5

0 0 0 0 2 2 2 2

0 0 0 0 -> 0 2 0 0

2 0 2 2 0 0 0 0

Note that cells with 0 become 2 and cells with 2 become 0. This is because

- cells with 0 is empty cells and it will be populated with bombs at previous step (N = 4).

- cells with 2 is bomb cells and it will explode to 0 and make neighbour cells become 0.