INTRODUCTION TO COMPUTER SCIENCE I PROJECT 6 Sudoku! Revision 2 [2010-May-04] 1

Similar documents
Spring 06 Assignment 2: Constraint Satisfaction Problems

Spring 06 Assignment 2: Constraint Satisfaction Problems

CMSC 201 Fall 2018 Project 3 Sudoku

CMPT 310 Assignment 1

CSCE 2004 S19 Assignment 5. Halfway checkin: April 6, 2019, 11:59pm. Final version: Apr. 12, 2019, 11:59pm


In the game of Chess a queen can move any number of spaces in any linear direction: horizontally, vertically, or along a diagonal.

8. You Won t Want To Play Sudoku Again

UN DOS TREZ Sudoku Competition. Puzzle Booklet for Preliminary Round. 19-Feb :45PM 75 minutes

Final Project: Verify a Sudoku Solution Due Fri Apr 29 (2400 hrs)? Wed May 4 (1200 hrs)? 1

Sudoku Solver Version: 2.5 Due Date: April 5 th 2013

ENGR170 Assignment Problem Solving with Recursion Dr Michael M. Marefat

Mobile Application Programming: Android

ENEE 150: Intermediate Programming Concepts for Engineers Spring 2018 Handout #7. Project #1: Checkers, Due: Feb. 19th, 11:59p.m.

CPSC 217 Assignment 3

Homework Assignment #1

1 Recursive Solvers. Computational Problem Solving Michael H. Goldwasser Saint Louis University Tuesday, 23 September 2014

Homework Assignment #2

Mathematics of Magic Squares and Sudoku

On the Combination of Constraint Programming and Stochastic Search: The Sudoku Case

Tac Due: Sep. 26, 2012

Cryptic Crosswords for Bright Sparks

CMPT 310 Assignment 1

ISudoku. Jonathon Makepeace Matthew Harris Jamie Sparrow Julian Hillebrand

Investigation of Algorithmic Solutions of Sudoku Puzzles

isudoku Computing Solutions to Sudoku Puzzles w/ 3 Algorithms by: Gavin Hillebrand Jamie Sparrow Jonathon Makepeace Matthew Harris

You Can Make a Difference! Due November 11/12 (Implementation plans due in class on 11/9)

Techniques for Generating Sudoku Instances

Tic-tac-toe. Lars-Henrik Eriksson. Functional Programming 1. Original presentation by Tjark Weber. Lars-Henrik Eriksson (UU) Tic-tac-toe 1 / 23

SudokuSplashZone. Overview 3

An improved strategy for solving Sudoku by sparse optimization methods

Latin Squares for Elementary and Middle Grades

Printing: You may print to the printer at any time during the test.

GET OVERLAPPED! Author: Huang Yi. Forum thread:

1 Modified Othello. Assignment 2. Total marks: 100. Out: February 10 Due: March 5 at 14:30

CS61B, Fall 2014 Project #2: Jumping Cubes(version 3) P. N. Hilfinger

Assignment 2 (Part 1 of 2), University of Toronto, CSC384 - Intro to AI, Winter

CPSC 217 Assignment 3 Due Date: Friday March 30, 2018 at 11:59pm

The Mathematics Behind Sudoku Laura Olliverrie Based off research by Bertram Felgenhauer, Ed Russel and Frazer Jarvis. Abstract

Section Marks Agents / 8. Search / 10. Games / 13. Logic / 15. Total / 46

of Nebraska - Lincoln

Programming Project 2

Slitherlink. Supervisor: David Rydeheard. Date: 06/05/10. The University of Manchester. School of Computer Science. B.Sc.(Hons) Computer Science

CSE 231 Spring 2013 Programming Project 03

Applications of Advanced Mathematics (C4) Paper B: Comprehension WEDNESDAY 21 MAY 2008 Time:Upto1hour

Assignment 6 Play A Game: Minesweeper or Battleship!!! Due: Sunday, December 3rd, :59pm

MAS336 Computational Problem Solving. Problem 3: Eight Queens

Sudoku Mock Test 5. Instruction Booklet. 28 th December, IST (GMT ) 975 points + Time Bonus. Organized by. Logic Masters: India

Indian Sudoku Championship 2015

03/05/14 20:47:19 readme

Assignment 2, University of Toronto, CSC384 - Intro to AI, Winter

WPF SUDOKU/PUZZLE GRAND PRIX 2014 WPFSUDOKU GP 2014 COMPETITIONBOOKLET ROUND6. Puzzle authors: Bulgaria Deyan Razsadov.

WPF SUDOKU/PUZZLE GRAND PRIX 2014 WPF SUDOKU GP 2014 COMPETITION BOOKLET ROUND 4. Puzzle authors: Russia Andrey Bogdanov, Olga Leontieva.

Computer Science COMP-250 Homework #4 v4.0 Due Friday April 1 st, 2016

Solving and Analyzing Sudokus with Cultural Algorithms 5/30/2008. Timo Mantere & Janne Koljonen

Applications of Advanced Mathematics (C4) Paper B: Comprehension INSERT WEDNESDAY 21 MAY 2008 Time:Upto1hour

Episode 3 16 th 19 th March Made In India and Regions by Prasanna Seshadri

CS 540-2: Introduction to Artificial Intelligence Homework Assignment #2. Assigned: Monday, February 6 Due: Saturday, February 18

Take Control of Sudoku

Serbian round at Logic Masters India

Unit 12: Artificial Intelligence CS 101, Fall 2018

AGLOA PRACTICE Equations Judges Certification Test Even Year Variations

Selected Game Examples

To use one-dimensional arrays and implement a collection class.

LMI Monthly Test May 2010 Instruction Booklet

SUDOKU Mahabharat. Episode 7 21 st 23 rd March. Converse by Swaroop Guggilam

Welcome to the Sudoku and Kakuro Help File.

Automatic Wordfeud Playing Bot

Task Scheduling. A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering. May 2007 Task Scheduling Slide 1

Math 3012 Applied Combinatorics Lecture 2

Overview. Initial Screen

COS 226 Algorithms and Data Structures Fall Midterm Exam

Comp th February Due: 11:59pm, 25th February 2014

CS61B Lecture #33. Today: Backtracking searches, game trees (DSIJ, Section 6.5)

INSTRUCTION BOOKLET SUDOKU MASTERS 2008 NATIONAL SUDOKU CHAMPIONSHIP FINALS Q&A SESSION 10:30 10:50 PART 1 CLASSICS 11:00 11:35

Lab 7: 3D Tic-Tac-Toe

puzzles may not be published without written authorization

Kenken For Teachers. Tom Davis January 8, Abstract

ON 4-DIMENSIONAL CUBE AND SUDOKU

Lab 1. Due: Friday, September 16th at 9:00 AM

CS 32 Puzzles, Games & Algorithms Fall 2013

Physical Zero-Knowledge Proof: From Sudoku to Nonogram

Yet Another Organized Move towards Solving Sudoku Puzzle

Grade 6 Math Circles March 7/8, Magic and Latin Squares

CS Programming Project 1

2359 (i.e. 11:59:00 pm) on 4/16/18 via Blackboard

15/03/23: BACA by John Bulten Theme: Beach Booty

3 rd -4 th September minutes

Introduction to Spring 2009 Artificial Intelligence Final Exam

Part III F F J M. Name

Ok, we need the computer to generate random numbers. Just add this code inside your main method so you have this:

Logic Masters India Presents. April 14 16, 2012 April 2012 Monthly Sudoku Test INSTRUCTION BOOKLET

CS 188 Fall Introduction to Artificial Intelligence Midterm 1

For slightly more detailed instructions on how to play, visit:

The remarkably popular puzzle demonstrates man versus machine, backtraking and recursion, and the mathematics of symmetry.

Task Scheduling. A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering. May 2016 Task Scheduling Slide 1

COS 226 Algorithms and Data Structures Fall Midterm Exam

CS151 - Assignment 2 Mancala Due: Tuesday March 5 at the beginning of class

The most difficult Sudoku puzzles are quickly solved by a straightforward depth-first search algorithm

Dutch Sudoku Advent 1. Thermometers Sudoku (Arvid Baars)

Transcription:

INTRODUCTION TO COMPUTER SCIENCE I PROJECT 6 Sudoku! Revision 2 [2010-May-04] 1 1 The game of Sudoku Sudoku is a game that is currently quite popular and giving crossword puzzles a run for their money in newspapers. It s a game well suited for computers because it is a matter of finding legal placements for numbers on the board. The game: Sudoku is played on a 9 9 grid. Initially, a few of the cells of that grid contain a numbers, all integers between 1 and 9. The goal for the player is to fill in the remaining cells of the grid, also with integers between 1 and 9, given the following constraints: Each value (1 through 9) must appear exactly once in each row. Each value (1 through 9) must appear exactly once in each column. Each value (1 through 9) must appear exactly once in each 3 3 sub-grid, where the 9 9 board is divided into 9 such sub-grids. A valid Sudoku game begins with initial numbers that, when combined with the constraints above, admit exactly one complete solution. That is, the initial numbers cannot make it impossible to fill in the board legal, nor can they allow multiple solutions. 2 Your assignment 2.1 Copying files from my directory You must copy some files from my directory to get started on this project. To do so, follow these steps: 1. Login to remus/romulus and open a shell. 2. Create a project-6 directory and change into it. 3. Issue the following command from within your project-6 directory: cp -r sfkaplan/public/cs11/project-6/*. If you look at your directory (use the ls -l command), you will see that there is one Java class file (Support.class) and three Sudoku board files (e.g., medium.board). 1 See Appendix A for a revision history. 1

2.2 The overall goal You need to write a program, named Sudoku (written, of course, in a file named Sudoku.java), that can be run like this: (remus) /project-6> java Sudoku medium.board Initial board: 0 0 0 0 0 0 0 0 7 0 0 0 0 7 0 3 0 8 0 0 0 5 0 4 0 6 0 0 0 0 0 0 0 0 8 0 7 1 0 0 9 0 0 0 5 8 0 0 0 1 5 9 0 0 3 0 0 0 0 0 0 0 0 0 0 8 9 4 0 6 3 0 0 2 7 6 0 3 0 0 0 Final board: 6 8 1 2 3 9 5 4 7 2 4 5 1 7 6 3 9 8 9 7 3 5 8 4 2 6 1 5 9 4 7 6 2 1 8 3 7 1 6 3 9 8 4 2 5 8 3 2 4 1 5 9 7 6 3 6 9 8 2 1 7 5 4 1 5 8 9 4 7 6 3 2 4 2 7 6 5 3 8 1 9 Correct solution! That is, the file medium.board contains a Sudoku puzzle (with 0 values where there would normally be blank entries). Go ahead, open it in Emacs and look. Your Sudoku program must read that board into a two-dimensional array of int. It must then solve the puzzle. That s all there is to it! Well, there are a few more details that you should know about... 2.3 Importing needed classes Since your program must use a number of special objects for opening and reading files (and catching exceptions that may be thrown by the methods in those objects), then you must tell the compiler about these object types classes, using Java terminology. We have needed to do this kind of importing in past projects, but those statements were provided in the partial code that you obtained from me. Here, you are writing the Sudoku program from scratch, so you must declare these imports. An import statement must come before you declare the beginning of the class/program, right at the very top of your Sudoku.java file. There are a number of importations needed in your program. One is for the Scanner class, and the others for File, FileNotFoundException, and the like are all part of a collection of classes used for input/output functions, or I/O. Rather than list each one-by-one, we can use a wildcard a symbol that stands in for a number of possible 2

class names. Specifically, the use of the asterisk (*) is our way of telling the compiler to include a group of classes; in this case, the entire set of Java I/O classes. So, your Sudoku.java file should begin like this: import java.util.scanner; import java.io.*; public class Sudoku {... 2.4 Using the Support methods There are two methods in the Support class that you must use in your program. To use each, you call them from your Sudoku program by using the prefix Support. (including the dot!). That is, to call, for example, printresults (documented below), then you would write the call as Support.printResults(isSolved, board). public static void printandverifyinitialboard (int[][] board, String initialstatepath) When your program has read the initial state of the board from its file into a two-dimensional array of int, it must call this method, passing both the 2D array and the file name from which it was created. This method will print the initial board; it will also check the 2D array against the file, verifying that the array is correct. public static void printresults (boolean issolved, int[][] board) After your program has (tried) to solve the puzzle, it must call this method. The first parameter, issolved, should indicate whether your solver believed that it solved the puzzle. The second parameter, board, should be the 2D array containing the solved puzzle. This method will print the 2D array that is passed. Moreover, if issolved is true, then this method will verify that the puzzle is indeed solved. If issolved is false, this method will determine whether a solution should have been found. 2.5 Suggestions for a progression Do not try to write all of this code at one. Break it into pieces, program and test each piece, and then move onto the next one. This incremental approach will reduce your programming and your debugging time. Here is a suggestions for how to go about this problem: 1. Read the board files: Write a method capable of reading a board file and returning its contents as a 2D array of int. Test this method by calling it, and then passing its result to Support.printAndVerifyInitialBoard() to see if it worked correctly. 2. Test legal placements: Write a method that can determine whether the placement of a particular value in a particular position on the board is legal. That is, does placing a value v 3

in row r and column c violate the rules because v already exists in r, in c, or in the sub-grid to which (r, c) belongs? Test this method by reading in a board file and then placing values that are known to be legal and illegal in particular positions, calling your tester method on each to see if it evaluates the situation correctly. 3. Write the solver: With an initial board loaded and a method that can determine whether the placement of a value into a blank location on the board is valid, you can now write the actual solver method. Use Support.printResults() to determine whether your solver is doing its job correctly. 2.6 Testing your code There are three Sudoku board files: easy.board The easiest of the puzzles to solve. Start with this one. medium.board Fewer initial values are provided than in easy.board, making the search a bit harder. evil.board A minimal number of values are provided. This solution requires backtracking to work correctly. (That is, certain values will be placed, but their incorrectness will not be evident until much later in the search.) So long as you call the Support methods at the right times, you should be able simply to use these three provided puzzles to test and debug your code. Feel free, also, to find other puzzles and make your own Sudoku board files. 2.7 Extra challenges The following are possible extensions to this assignment that you may pursue for additional credit. To be clear, the effort for one or both of these challenges substantially exceeds the credit that each would earn you. Although you may earn some small additional credit for (nearly) completing any part of these, you should take them on because you find the challenge compelling. You should also know that there will be little guidance on how to solve these problems. To devise a solution, plan on spending some significant time and effort in puzzling it out. Creating a puzzle generator: The core of this assignment is creating a program that solves an existing Sudoku puzzle. But how do those puzzles get created? We want an algorithm, and then code that implements that algorithm, to create a new Sudoku puzzle. Your task is simply to create such an algorithm and then to program it. If you manage to develop such a puzzle generator, you can then take on the additional challenge of making it optimal: generate puzzles that contain the smallest number of initially provided values possible. xxx 4

Variables sizes and dimensions: Just as we have used the 4 4 kids Sudoku puzzle during lectures in addition to the 9 9 standard puzzle, the game is easily defined for any k k configuration for all integer k > 0. 2 So, as a first step, generalize your code to read and solve k k Sudoku puzzles (again, for integer k > 0). Having made this change, now consider that Sudoku need not be only a 2-dimensional game. Consider, for starters, a 3-dimensional Sudoku. Here, there are not just horizontal rows and vertical columns, but also depth-based tunnels. 3 Whereas the standard puzzle is a 3 2 3 2 arrangement, we could consider, say, a 3 3 3 3 3 3 = 27 27 27 puzzle, one would need to place the digits 1 through 27 such that each digit appears exactly once in each: 1. row 2. column 3. tunnel (third dimensional line from front to back) 4. subcube (each cube created by dividing the 3-dimensional cube into 81 separate 3 3 3 cubes. 3 How to submit your work Use the cs11-submit command: $ cs11-submit project-6 Sudoku.java If you complete any portion of the extra credit projects, submit them something like this: $ cs11-submit project-6-extra SudokuMaker.java SudokuMultiSize.java This assignment is due on Thursday, May 6, at 11:59 pm A Revision history Revision 0 [2010-Apr-20]: The initial, complete version. Revision 1 [2010-Apr-22]: Inserted Section 2.3; fixed a typo in Section 2.4 to make clear that the method is named printresults. Revision 2 [2010-Apr-30]: Added Section 2.7 with extra challenges. 2 There are also configurations of the puzzle for non-squares (e.g., 3 4), but we can skip those arrangements here. 3 Perhaps not the best choice of name for this third dimension, but it will do. 5