An open exchange for the MATLAB and Simulink user community |
Hosted by The MathWorks |
Welcome to Blockbuster, the 13th MATLAB Online Programming Contest.
The ProblemIn this contest, you are given a grid of numbers which you can imagine corresponds to a box filled with colored blocks. Your goal is to empty the box.
You remove a block by popping it. When a block pops, it vanishes and all blocks above it fall down one space as though pulled down by gravity. Furthermore, all similarly colored contiguous blocks also disappear. In fact, in order to pop a block, it must have at least one similar neighbor. Isolated blocks cannot be popped. In order to maximize the effectiveness of your block removal, you can perform block swaps. Pick a pair of adjacent blocks (adjacent is defined vertical and horizontal only, no diagonal swaps) and exchange their positions. You may not swap a block with empty space.
ExampleHere's an example of what a sequence of events might look like. Starting with the board on the left, we will first swap two blocks at the bottom and then remove four contiguous blocks.
As an exercise, what is the minimum number of pops required to clear this board? How it worksHere are some of the specifics about the rules.
The APIYou define your move with a three element vector.[row column command]A command code of zero means pop the block in the specified row and column. A command code of 1, 2, 3, or 4 indicates a swap with the block to the north, east, south, or west as shown below.
To command a swap of the leftmost column in the matrix below (thereby changing matrix a1 into matrix a2), use the vector move as shown.
a1 = [ 9 23 2 ]
[ 12 12 15 ]
move = [1 1 3]
a2 = [ 12 23 2 ]
[ 9 12 15 ]
Note that the move vector [2 1 1] would have exactly the same result.
To command a removal of block (2,2) in the matrix below (thereby changing matrix a3 into matrix a4), use the vector move.
a3 = [ 23 12 23 ]
[ 9 23 23 ]
move = [2 2 0]
a4 = [ 23 0 0 ]
[ 9 12 0 ]
In this case the move vectors [1 3 0] and [2 3 0] would have done the same thing, since they all touch the same contiguous block of 23s.
Popping empty space and swapping with empty space are considered no-ops by the contest code. Your code will not error out, but no action is performed. Similarly, attempting to pop an isolated block is an errorless no-op. ScoringThe score is simply the sum of all remaining numbers in the matrix after you have taken all your moves. If the matrix a4 shown above is your ultimate board, then>> sum(a4(:)) ans = 44your final score would be 44. The overall score for your entry is a combination of how well your algorithm does and how fast it runs on a multi-problem test suite. How well your algorithm does (the "result") depends on how low your final score is. The average result for the entire test suite, along with the associated runtime of your entry, gets passed to our scoring algorithm before returning a final score, according to the equation
We don't publish the values k1, k2, and k3, but they aren't hard to figure out. Your entry will time out and be disqualified if it takes more than 180 seconds (three minutes). Developing Your EntryThe files you need to get started on the contest are included in a ZIP-file available on the MATLAB Central File Exchange. If you download and uncompress this ZIP-file, you will have the files described below.The main routine is solver.m. moves = solver(board, nMoves)where board is the matrix representing the blocks in your initial game configuration, and nMoves is the number of moves you are allowed. The return matrix moves can be no longer than nMoves rows. Keep in mind that this function must have the right signature: two input arguments, one output argument. Variable names are unimportant. To test this function with the test suite in the ZIP-file, run runcontest.m. >> runcontest Size limitationsSome of you have asked about the limit to code size. The column in our MySQL database that stores the M-code is of type text, which is limited of 65535 characters. Submissions longer than this limit will fail.About the ContestThe contest is divided into three segments. Most of the week will run as usual, with free sharing of code, but the first two days of the contest will hide some of the information about each entry.
Collaboration and Editing Existing EntriesOnce an entry has been submitted, it cannot be changed. However, any entry can be viewed, edited, and resubmitted as a new entry. You are free to view and copy any entry in the queue. If your modification of an existing entry improves its score, then you are the "author" for the purpose of determining the winners of this contest. We encourage you to examine and optimize existing entries.We also encourage you to discuss your solutions and strategies with others. You can do this by posting to the newsgroup thread that we've started. Fine PrintThe allowable functions are those contained in the basic MATLAB package available in $MATLAB/toolbox/matlab, where $MATLAB is the root MATLAB directory. Functions from other toolboxes will not be available. Entries will be tested against MATLAB R2006a.The following are prohibited:
FAQCheck our FAQ for answers to frequently asked questions about the contest. |
|
| Related Topics |
| New Products | Support | Documentation | Training | Webinars | Careers | Newsletters | RSS |
| Problems? Suggestions? Contact us at contest@mathworks.com | © 1994-2008 The MathWorks, Inc. Trademarks Privacy Policy |