Learn how the problem of finding the queen's diagonal attack is solved in a recursive manner. The attack angle is checked, but more coding needs to be done to confirm that the square is safe.
- [Instructor] As I pondered my initial failure…with the N Queens program, I thought about how to fix it.…I believe the approach to check for attacks is sound…but the method of tracking a queen's attack was wrong,…so I reversed the method.…Instead of setting attacks, I'd be defensive…and scan a square for potential attacks from elsewhere.…The key to doing that is to find a queen's location…on the board and the key to that…is to store the queen's location…specifically as a row, column pair.…Then I thought about a two dimensional array,…one element for the row and another for the column.…
Given that, the first element would always be sequential,…row one through n and that's the same values…as an element in an array.…So all that's truly needed…is a one dimensional array of integers.…Each element gives the queen's column position…for a certain row.…Working with my original code…I combined the set queen function…with the find_square function.…The function takes as an argument the board array,…the current row, which is where the queen will be set…
Skill Level Intermediate
1. Summarize the Weather
2. Geolocation with C
3. Eight Queens with C
4. Build a Musical Instrument with C
5. Face Recognition with C
6. Web Dashboards with C
Next steps1m 2s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.