Learn how to write the code for checking whether any two queens on the same row threaten each other.
- [Instructor] Now implementing the IsSafe method…depends very much on our representation of the chess board.…So you see on line nine, I've made the assumption…that we have a single vector, a single array…of integers and so our board is represented just…by eight numbers.…A number for every column indicating…which row the queen is on.…And so to determine whether that's safe,…whether any of those queens attack each other,…we have essentially two tasks.…I'll click on line 12, add a line,…and just some pseudo code, so we know we have queens…that can attack each other across rows,…but not columns, we only have one queen per column.…
And so no two queens may be on the same row.…That's one condition to test for.…A no two queens may be on the same diagonal.…And so these are the two things…we have to test for in our chess board.…Now the board itself is just a single array of numbers,…and so very much our calculation will depend on that format.…And so the first thing to note is…on the same row means that two numbers…within that vector may not be the same.…
Skill Level Intermediate
1. Problem 1: Pond Oreille
2. Problem 2: Where Am I?
3. Problem 3: Eight Queens
4. Problem 4: Accessing Peripherals
5. Problem 5: Facial Recognition
6. Problem 6: Real-Time Information Dashboard
Next steps2m 46s
- 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.