Join Carlos Rivas for an in-depth discussion in this video Chess board validation, part of Code Clinic: Java.
- [Instructor] Scrolling down to line 46,…we'll find our validation functions.…Let's see how it works.…It takes three input parameters,…current row, current column…and the board array.…These three combined represent the current state…of the board.…The four loop in line 50, only runs up to the current row…and not the entire board.…This is because if we don't have a complete board yet…we don't need to spend computing cycles…checking the empty side of the board.…
Line 52 shows an if statement…that checks the value of the current column.…If this same value is found in our array,…then we have a problem and we reject this validation…by returning false.…No two queens can be in the same column or row.…Line 56 uses both column and row values…to make sure the diagonals are clear of other queens,…both up and down the board.…
Finally, if we make it all the way to line 60,…we have past validation of this chess board,…and if this happens to be on the last row…then we have ourselves a solution out of the possible 92.…If we run the program now,…
Visit other courses in the series to see how to solve the exact same challenges in languages like C#, C++, PHP, Python, and Ruby.
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
- 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.