Sit-In Lab 1 Ob-CHESS-ion N-Queens Puzzle Checker
1 / 1

Sit-In Lab 1 Ob-CHESS-ion N-Queens Puzzle Checker

Author : faustina-dinatale | Published Date : 2025-05-12

Description: SitIn Lab 1 ObCHESSion NQueens Puzzle Checker Famous NQueens puzzle You want to check if the input solution is correct No 2 queens can be on the same row column or diagonal Write a piece of code to verify the solution Input N

Presentation Embed Code

Download Presentation

Download Presentation The PPT/PDF document "Sit-In Lab 1 Ob-CHESS-ion N-Queens Puzzle Checker" is the property of its rightful owner. Permission is granted to download and print the materials on this website for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.

Transcript:Sit-In Lab 1 Ob-CHESS-ion N-Queens Puzzle Checker:
Sit-In Lab 1 Ob-CHESS-ion N-Queens Puzzle Checker Famous N-Queens puzzle You want to check if the input solution is correct No 2 queens can be on the same row, column or diagonal Write a piece of code to verify the solution Input: N – Number of rows ( Number of queens on chessboard ) Followed by N rows of N numbers 0 – Empty space 1 – Queen Output whether the puzzle is a valid solution Example – Valid? Output : Example – Incorrect solution Output : INVALID Example – Valid Solution Output : VALID No other queen in same row, column and diagonal Algorithm Loop through each square of the array: Start from the top left, iterate row by row For each queen found Starting from the square on its right, check if there exists another queen in the same row Starting from the square right below it, check if there exists another queen in the same column Starting from the square on its bottom right, check if there exists another queen in the same right diagonal Starting from the square on its bottom left, check if there exists another queen in the same left diagonal Return false if there exists another queen Visualisation – Start from top left Visualisation – Queen is found, check rows and diagonals Visualisation – Queen is found, check rows and diagonals Valid Visualisation – Iterate row by row - No queen in this space Visualisation – Another Queen is found Visualisation – Queen is found, check rows and diagonals Valid Visualisation – Iterate row by row Visualisation – Another Queen is found Visualisation – Queen is found, check rows and diagonals Invalid Visualisation – Break from loop and return false Invalid Main method: Read in the inputs Call helper methods and print the output Helper methods: Check rows, columns and diagonals ( 4 directions ), returning false if another queen is found Check if given coordinates are out of array bounds ( >= N ) How to check diagonals? 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 [1][3] 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 [2][4] 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 [3][5] 0 1 2 3 4 5 6 7 0 1 2 3 4

Download Document

Here is the link to download the presentation.
"Sit-In Lab 1 Ob-CHESS-ion N-Queens Puzzle Checker"The content belongs to its owner. You may download and print it for personal use, without modification, and keep all copyright notices. By downloading, you agree to these terms.

Related Presentations

THE OFFICIAL RULES OF CHESS  CARDOZA PUBLISHING Rules of Chess ERIC SCHILLER  THE OFFICIAL Poems Eye halve a spelling checker httplearnenglish UIL Chess Puzzle Practice Material s you should know The consistency Checker, or Overhauling a PGDB The consistency Checker, or Overhauling a PGDB Forest Hills Medical Services Chess Skewer Puzzles Basic Chess Tactics SIDDE-SITZEN-SIT-ASSISESOVE-SCHLAFEN-SLEEP-DORMIRSIDDE-SITZEN-SIT-ASSI CUDI CAN YOU DO IT PUZZLEDear Puzzle LoversHere146s a puzzle that will Gentle Dental in Queens Gentle Dental in Queens, NY