Download presentation
Presentation is loading. Please wait.
Published byPhilip Bridges Modified over 6 years ago
1
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 1
2
Ordinary algo. to count mines #1
Case 1 (inner cell) abc'enter'def 3*4 mine board score board CG1101 (AY2012/13 Semester 1) 2 2
3
Ordinary algo. to count mines #2
Case 2 (boundary cell) abc'enter'def 3*4 mine board score board CG1101 (AY2012/13 Semester 1) 3 3
4
Ordinary algo. to count mines #3
Case 3 (corner cell) 3*4 mine board score board CG1101 (AY2012/13 Semester 1) 4 4
5
Enlarged 5*7 mine board with outer frame of all 0
Improved algo. illustration Enlarged 5*7 mine board with outer frame of all 0 Original 3*4 mine board CG1101 (AY2012/13 Semester 1) 5 5
6
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 6
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.