60 likes | 153 Views
Count Mines. In the following slides, I will first show an ordinary algorithm to count mines in a mine field. I will use a 3*4 board as illustration, which can be easily scaled up to a bigger board of any size based on the same principle.
E N D
Count Mines • In the following slides, I will first show an ordinary algorithm to count mines in a mine field. • I will use a 3*4 board as illustration, which can be easily scaled up to a bigger board of any size based on the same principle. • After that, I will illustrate an improved algorithm and please think carefully. CG1101 (AY2012/13 Semester 1) 1
Ordinary algo. to count mines #1 Case 1 (inner cell) 3*4 mine board score board CG1101 (AY2012/13 Semester 1) 2
Ordinary algo. to count mines #2 Case 2 (boundary cell) 3*4 mine board score board CG1101 (AY2012/13 Semester 1) 3
Ordinary algo. to count mines #3 Case 3 (corner cell) 3*4 mine board score board CG1101 (AY2012/13 Semester 1) 4
Enlarged 5*7 mine board with outer frame of all 0 Improved algo. illustration Original 3*4 mine board CG1101 (AY2012/13 Semester 1) 5
Count Mines • Got it? • Ok, you may get the idea, then how to implement it? • That’s your task • Hint: you will need to do some major change to the given skeleton if you want to apply the improved algorithm to lab#4 ex5. • Overall, a better algorithm will make your program easier to write and debug. • Therefore, for complex problems, spend some time to thinking about the algorithm before coding! CG1101 (AY2012/13 Semester 1) 6