; THE ORIGNAL COPYRIGHTS OF THE GAME BELONG TO "WILLIAM JOHN TEAHAN" ; THE ORIGNAL SOURCE FILE CAN BE FOUND AT ; http://files.bookboon.com/ai/Sudoku-Builder.html ; Copyright 2009 William John Teahan can be found at the end. ; MODIFICATIONS WERE MADE BY ; MUHAMMAD RIZWAN ; GRADUATE OF NATIONAL UNIVERSITY OF SCIENCES AND TECHNOLOGY, ; SCHOOL OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCES (NUST-SEECS), ; ISLAMABAD, PAKISTAN. breed [squares box] ; This is a Square with 9 rows and 9 columns which are further sub divided globals [ A1 A2 A3 A4 B1 B2 B3 C1 C2 C3 D1 D2 D3 E1 E2 E3 F1 F2 F3 F4 G1 G2 G3 H1 H2 H3 H4 I1 I2 I3 sol-var solver-to-check-var buildcustommap-var chklessthanseventeen ] squares-own ; a square in the 9 by grid in which a number from 1 to 9 needs to be placed [ squareinX ; x square position in the grid; 1 is leftmost square; 9 is rightmost squareinY ; y square position in the grid; 1 is bottom square; 9 is top number ] ; the number placed into the square to Setup-Game ; This is a "Set/Reset Game" button listener. Here we are setting ; up the game map. This also Resets the game. clear-all ask patches [ set pcolor blue ] ; Blue Background Color draw-grid ; Drawing the basic grid outline (Defined below) setup-squares ; Squares where numbers are placed these, ; squares are within the grids which are drwan above set sol-var 1 set buildcustommap-var 1 set chklessthanseventeen 0 end to draw-Row [start-x end-x y] ; Drawing Horizontal lines (Rows) ; from start-x to end-x (along x axis) ask patches [ if (pxcor >= start-x) and (pxcor <= end-x) and (pycor = y) [ set pcolor black ] ; This is Black color for lines making Rows ] end to draw-Columns [x start-y end-y] ; Drawing Vertical Lines (Columns) ; from start-y to end-y (along y axis) ask patches [ if (pxcor = x) and (pycor >= start-y) and (pycor <= end-y) [ set pcolor black ] ; This is Black color for lines making Colum ] end to draw-rows [start-y ] ; Drawing Row lines from -90 (Left) to 90 (Right) ; And adding space between individual Rows let y start-y draw-Row -90 90 y draw-Row -90 90 y + 1 draw-Row -90 90 y + 21 draw-Row -90 90 y + 41 end to draw-cols [start-x] ; Drawing Column lines from -90 (Left) to 90 (Right) ; And adding space between individual Columns let x start-x draw-Columns x -90 90 draw-Columns x + 1 -90 90 draw-Columns x + 21 -90 90 draw-Columns x + 41 -90 90 end to draw-grid ; Here we are drawing the 9 by 9 basic Grid draw-rows -92 ; Drawing Rows for the grid draw-rows -31 draw-rows 30 draw-row -92 92 91 draw-row -92 92 92 draw-cols -92 draw-cols -31 ; Drawing Columns for the grid draw-cols 30 draw-Columns 91 -92 92 draw-Columns 92 -92 92 end to setup-squares ; Making Squares in grids let x 1 let y 1 while [x <= 9] ; Here we are making the squares in which numbers [ ; are placed. The span is from 1 to 9 along x and y set y 1 while [y <= 9] [ setup-square x y set y y + 1 ] set x x + 1 ] end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to-report square-location [this-square-x this-square-y] ; Whenever a number is entered in a square ; The x,y coordinates of that square are saved as a list report list (-99 + this-square-x * 20 + int (this-square-x / 3)) ; Calculatin x and y values and adding in list (-103 + this-square-y * 20 + int (this-square-y / 3)) end to setup-square [this-square-x this-square-y] ; Setting up squares at (square-x, square-y) ; in grid defined above. (1,1) is left bottom; ; (9,9) is right top. let location (square-location this-square-x this-square-y) let x first location let y last location create-squares 1 ; Creating and storing Squares info [ set size 0 setxy x y set squareinX this-square-x set squareinY this-square-y set number 0 ] end to Insert ; Listener for insert button ; By this button, we can insert the numbers in the boxes ; by getting x and y coordinates of boxes let this-square nobody let this-mouse-xcor 0 ; Initial value for variables set to 0 let this-mouse-ycor 0 if (mouse-down?) ; If mouse is pressed on a square [ set this-mouse-xcor mouse-xcor ; We get the X and Y coordinates of mouse set this-mouse-ycor mouse-ycor ; Getting Y coordinates set this-square min-one-of squares with [number = 0 or label-color = black] [distancexy this-mouse-xcor this-mouse-ycor] ; setting distancexy to the coodinates collected above if ([distancexy this-mouse-xcor this-mouse-ycor] of this-square < 5) ; If the distance of coordinates in within range of the square i-e differnece is NOT more than 5 [ ask this-square ;Ask the square to add the number [ set number InsertionNUMBER ;InsertionNUMBER is the number in the chooser/dropdown shown below the buttons set label (word number) ;This InsertionNUMBER is added in the box set label-color black ] if not Check ;Calling the check, this will be explained later [ stop ] ; It checks the sudoku Rules ] ] end to Build ; Action Listner for Build Custom Maps Button if (buildcustommap-var = 1 ) [ user-message ("Build your Custom Maps by inserting numbers from Chooser \n Note : Turning Hints ON will help you build a correct Map \n You can Save your Map by Save Game button") set buildcustommap-var 0 ] let this-square nobody let this-mouse-xcor 0 ; Initial value for variables set to 0 let this-mouse-ycor 0 if (mouse-down?) ; If mouse is pressed on a square [ set this-mouse-xcor mouse-xcor ; We get the X and Y coordinates of mouse set this-mouse-ycor mouse-ycor ; Getting Y coordinates set this-square min-one-of squares with [number = 0 or label-color = green] [distancexy this-mouse-xcor this-mouse-ycor] ; setting distancexy to the coodinates collected above if ([distancexy this-mouse-xcor this-mouse-ycor] of this-square < 5) ; If the distance of coordinates in within range of the square i-e differnece is NOT more than 5 [ ask this-square ;Ask the square to add the number [ set number InsertionNUMBER ;InsertionNUMBER is the number in the chooser/dropdown shown below the buttons set label (word number) ;This InsertionNUMBER is added in the box set label-color green ] if not Check ;Calling the check, this will be explained later [ stop ] ; It checks the sudoku Rules ] ] end to PrePlace ; This is listener for the "PrePlace numbers" button. ; It places some numbers initially in the map. ; let a random n-values ( 23 ) let list-of-numbers n-values (10 - 1 + 1) [ 1 + ? ] let shuffled-list shuffle list-of-numbers ;let selection sublist shuffled-list 0 9 ;let ee random 23 set A1 position 1 shuffled-list set A2 position 2 shuffled-list set A3 position 3 shuffled-list set A4 position 4 shuffled-list set B1 position 5 shuffled-list set B2 position 6 shuffled-list set B3 position 7 shuffled-list set C1 position 8 shuffled-list set C2 position 9 shuffled-list set C3 position 10 shuffled-list let this-square nobody let this-mouse-xcor 0 ;Setting up the initial variable values to zero let this-mouse-ycor 0 ;;;;;;;;;;;;;;;;;Box 1 PrePlaced Numbers;;;;;;;;;;;;;;; ;These are just Random Numbers placed in Box 1 let box1-xcordline1 n-values (3 - 1 + 1) [ 1 + ? ] let box1-xcoordlist1 shuffle box1-xcordline1 let xcorforbox1 -80 if (position 1 box1-xcoordlist1 = 0 )[ set xcorforbox1 -80] if (position 1 box1-xcoordlist1 = 1 )[ set xcorforbox1 -60] if (position 1 box1-xcoordlist1 = 2 )[ set xcorforbox1 -40] if HardLevel? [ set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox1 81] if (A1 != 0) [ ask this-square [ set InsertionNUMBER (word A1) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 2 box1-xcoordlist1 = 0 )[ set xcorforbox1 -80] if (position 2 box1-xcoordlist1 = 1 )[ set xcorforbox1 -60] if (position 2 box1-xcoordlist1 = 2 )[ set xcorforbox1 -40] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox1 60] if (A2 != 0) [ ask this-square [ set InsertionNUMBER (word A2) set number InsertionNUMBER set label (word number) set label-color orange ] ] let xcorforbox1lineA4 -80 if (position 3 box1-xcoordlist1 = 0 )[ set xcorforbox1 -80 set xcorforbox1lineA4 -40 ] if (position 3 box1-xcoordlist1 = 1 )[ set xcorforbox1 -60 set xcorforbox1lineA4 -80] if (position 3 box1-xcoordlist1 = 2 )[ set xcorforbox1 -40 set xcorforbox1lineA4 -60 ] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox1 40] if (A3 != 0) [ ask this-square [ set InsertionNUMBER (word A3) set number InsertionNUMBER set label (word number) set label-color orange ] ] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox1lineA4 40] if (A4 != 0) [ ask this-square [ set InsertionNUMBER (word A4) set number InsertionNUMBER set label (word number) set label-color orange ] ] ;;;;;;;;;;;;;;;;;Box 2 PrePlaced Numbers;;;;;;;;;;;;;;; ;These are just Random Numbers placed in Box 2 let box2-xcordline1 n-values (3 - 1 + 1) [ 1 + ? ] let box2-xcoordlist1 shuffle box2-xcordline1 let xcorforbox2 -20 if (position 1 box2-xcoordlist1 = 0 )[ set xcorforbox2 -20] if (position 1 box2-xcoordlist1 = 1 )[ set xcorforbox2 0] if (position 1 box2-xcoordlist1 = 2 )[ set xcorforbox2 20] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox2 82] if (B1 != 0) [ ask this-square [ set InsertionNUMBER (word B1) ; Number 5 placed in (x=-19 , y=82) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 2 box2-xcoordlist1 = 0 )[ set xcorforbox2 -20] if (position 2 box2-xcoordlist1 = 1 )[ set xcorforbox2 0] if (position 2 box2-xcoordlist1 = 2 )[ set xcorforbox2 20] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox2 60] if (B2 != 0) [ ask this-square [ set InsertionNUMBER (word B2) set number InsertionNUMBER set label (word number) set label-color orange ] ] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox2 40] if (position 3 box2-xcoordlist1 = 0 )[ set xcorforbox2 -20 ] if (position 3 box2-xcoordlist1 = 1 )[ set xcorforbox2 0] if (position 3 box2-xcoordlist1 = 2 )[ set xcorforbox2 20] if (B3 != 0) [ ask this-square [ set InsertionNUMBER (word B3) set number InsertionNUMBER set label (word number) set label-color orange ] ] ;;;;;;;;;;;;;;;;;Box 3 PrePlaced Numbers;;;;;;;;;;;;;;; ;These are just Random Numbers placed in Box 3 let box3-xcordline1 n-values (3 - 1 + 1) [ 1 + ? ] let box3-xcoordlist1 shuffle box3-xcordline1 let xcorforbox3 40 if (position 1 box3-xcoordlist1 = 0 )[ set xcorforbox3 40] if (position 1 box3-xcoordlist1 = 1 )[ set xcorforbox3 60] if (position 1 box3-xcoordlist1 = 2 )[ set xcorforbox3 80] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox3 82] if (C1 != 0) [ ask this-square [ set InsertionNUMBER (word C1) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 2 box3-xcoordlist1 = 0 )[ set xcorforbox3 40] if (position 2 box3-xcoordlist1 = 1 )[ set xcorforbox3 60] if (position 2 box3-xcoordlist1 = 2 )[ set xcorforbox3 80] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox3 60] if (C2 != 0) [ ask this-square [ set InsertionNUMBER (word C2) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 3 box3-xcoordlist1 = 0 )[ set xcorforbox3 40 ] if (position 3 box3-xcoordlist1 = 1 )[ set xcorforbox3 60] if (position 3 box3-xcoordlist1 = 2 )[ set xcorforbox3 80] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox3 40] if (C3 != 0) [ ask this-square [ set InsertionNUMBER (word C3) set number InsertionNUMBER set label (word number) set label-color orange ] ] ;;;;;;;;;;;;;;;;;Box 4 PrePlaced Numbers;;;;;;;;;;;;;;; ;These are just Random Numbers placed in Box 4 let box4-xcordline1 n-values (3 - 1 + 1) [ 1 + ? ] let box4-xcoordlist1 shuffle box4-xcordline1 let xcorforbox4 -80 if (position 1 box4-xcoordlist1 = 0 )[ set xcorforbox4 -80] if (position 1 box4-xcoordlist1 = 1 )[ set xcorforbox4 -60] if (position 1 box4-xcoordlist1 = 2 )[ set xcorforbox4 -40] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox4 20] set D1 B1 if (D1 != 0) [ ask this-square [ set InsertionNUMBER (word D1) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 2 box4-xcoordlist1 = 0 )[ set xcorforbox4 -80] if (position 2 box4-xcoordlist1 = 1 )[ set xcorforbox4 -60] if (position 2 box4-xcoordlist1 = 2 )[ set xcorforbox4 -40] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox4 0] set D2 B2 if (D2 != 0) [ ask this-square [ set InsertionNUMBER (word D2) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 3 box4-xcoordlist1 = 0 )[ set xcorforbox4 -80 ] if (position 3 box4-xcoordlist1 = 1 )[ set xcorforbox4 -60] if (position 3 box4-xcoordlist1 = 2 )[ set xcorforbox4 -40] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox4 -20] set D3 B3 if (D3 != 0) [ ask this-square [ set InsertionNUMBER (word D3) set number InsertionNUMBER set label (word number) set label-color orange ] ] ;;;;;;;;;;;;;;;;;Box 5 PrePlaced Numbers;;;;;;;;;;;;;;; ;These are just Random Numbers placed in Box 5 let box5-xcordline1 n-values (3 - 1 + 1) [ 1 + ? ] let box5-xcoordlist1 shuffle box5-xcordline1 let xcorforbox5 -20 if (position 1 box5-xcoordlist1 = 0 )[ set xcorforbox5 -20] if (position 1 box5-xcoordlist1 = 1 )[ set xcorforbox5 0] if (position 1 box5-xcoordlist1 = 2 )[ set xcorforbox5 20] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox5 20] set E1 C1 if (E1 != 0) [ ask this-square [ set InsertionNUMBER (word E1) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 2 box5-xcoordlist1 = 0 )[ set xcorforbox5 -20] if (position 2 box5-xcoordlist1 = 1 )[ set xcorforbox5 0] if (position 2 box5-xcoordlist1 = 2 )[ set xcorforbox5 20] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox5 20] set E2 C2 if (E2 != 0) [ ask this-square [ set InsertionNUMBER (word E2) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 3 box5-xcoordlist1 = 0 )[ set xcorforbox5 -20 ] if (position 3 box5-xcoordlist1 = 1 )[ set xcorforbox5 0] if (position 3 box5-xcoordlist1 = 2 )[ set xcorforbox5 20] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox5 0] set E3 C3 if (E3 != 0) [ ask this-square [ set InsertionNUMBER (word E3) set number InsertionNUMBER set label (word number) set label-color orange ] ] ;;;;;;;;;;;;;;;;;Box 6 PrePlaced Numbers;;;;;;;;;;;;;;; ;These are just Random Numbers placed in Box 6 let box6-xcordline1 n-values (3 - 1 + 1) [ 1 + ? ] let box6-xcoordlist1 shuffle box6-xcordline1 let xcorforbox6 40 if (position 1 box6-xcoordlist1 = 0 )[ set xcorforbox6 40] if (position 1 box6-xcoordlist1 = 1 )[ set xcorforbox6 60] if (position 1 box6-xcoordlist1 = 2 )[ set xcorforbox6 80] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox6 20] set F1 A1 if (F1 != 0) [ ask this-square [ set InsertionNUMBER (word F1) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 2 box6-xcoordlist1 = 0 )[ set xcorforbox6 40] if (position 2 box6-xcoordlist1 = 1 )[ set xcorforbox6 60] if (position 2 box6-xcoordlist1 = 2 )[ set xcorforbox6 80] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox6 0] set F2 A2 if (F2 != 0) [ ask this-square [ set InsertionNUMBER (word F2) set number InsertionNUMBER set label (word number) set label-color orange ] ] let xcorforbox6lineA4 40 if (position 3 box6-xcoordlist1 = 0 )[ set xcorforbox6 40 set xcorforbox6lineA4 80 ] if (position 3 box6-xcoordlist1 = 1 )[ set xcorforbox6 60 set xcorforbox6lineA4 40] if (position 3 box6-xcoordlist1 = 2 )[ set xcorforbox6 80 set xcorforbox6lineA4 60 ] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox6 0] set F3 A3 if (F3 != 0) [ ask this-square [ set InsertionNUMBER (word F3) set number InsertionNUMBER set label (word number) set label-color orange ] ] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox6 -20] set F4 A4 if (F4 != 0) [ ask this-square [ set InsertionNUMBER (word F4) set number InsertionNUMBER set label (word number) set label-color orange ] ] ;;;;;;;;;;;;;;;;;Box 7 PrePlaced Numbers;;;;;;;;;;;;;;; ;These are just Random Numbers placed in Box 7 let box7-xcordline1 n-values (3 - 1 + 1) [ 1 + ? ] let box7-xcoordlist1 shuffle box7-xcordline1 let xcorforbox7 -80 if (position 1 box7-xcoordlist1 = 0 )[ set xcorforbox7 -80] if (position 1 box7-xcoordlist1 = 1 )[ set xcorforbox7 -60] if (position 1 box7-xcoordlist1 = 2 )[ set xcorforbox7 -40] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox7 -40] set G1 C1 if (G1 != 0) [ ask this-square [ set InsertionNUMBER (word G1) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 2 box7-xcoordlist1 = 0 )[ set xcorforbox7 -80] if (position 2 box7-xcoordlist1 = 1 )[ set xcorforbox7 -60] if (position 2 box7-xcoordlist1 = 2 )[ set xcorforbox7 -40] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox7 -40] set G2 C2 if (G2 != 0) [ ask this-square [ set InsertionNUMBER (word G2) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 3 box7-xcoordlist1 = 0 )[ set xcorforbox7 -80 ] if (position 3 box7-xcoordlist1 = 1 )[ set xcorforbox7 -60] if (position 3 box7-xcoordlist1 = 2 )[ set xcorforbox7 -40] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox7 -80] set G3 C3 if (G3 != 0) [ ask this-square [ set InsertionNUMBER (word G3) set number InsertionNUMBER set label (word number) set label-color orange ] ] ;;;;;;;;;;;;;;;;;Box 8 PrePlaced Numbers;;;;;;;;;;;;;;; ;These are just Random Numbers placed in Box 8 let box8-xcordline1 n-values (3 - 1 + 1) [ 1 + ? ] let box8-xcoordlist1 shuffle box8-xcordline1 let xcorforbox8 -20 if (position 1 box8-xcoordlist1 = 0 )[ set xcorforbox8 -20] if (position 1 box8-xcoordlist1 = 1 )[ set xcorforbox8 0] if (position 1 box8-xcoordlist1 = 2 )[ set xcorforbox8 20] set H1 A1 if (H1 != 0) [ set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox8 -40] ask this-square [ set InsertionNUMBER (word H1) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 2 box8-xcoordlist1 = 0 )[ set xcorforbox8 -20] if (position 2 box8-xcoordlist1 = 1 )[ set xcorforbox8 0] if (position 2 box8-xcoordlist1 = 2 )[ set xcorforbox8 20] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox8 -40] set H2 A2 if (H2 != 0) [ ask this-square [ set InsertionNUMBER (word H2) set number InsertionNUMBER set label (word number) set label-color orange ] ] let xcorforbox8lineA4 -20 if (position 3 box8-xcoordlist1 = 0 )[ set xcorforbox8 -20 set xcorforbox8lineA4 20 ] if (position 3 box8-xcoordlist1 = 1 )[ set xcorforbox8 0 set xcorforbox8lineA4 -20] if (position 3 box8-xcoordlist1 = 2 )[ set xcorforbox8 20 set xcorforbox8lineA4 0 ] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox8 -62] set H3 A3 if (H3 != 0) [ ask this-square [ set InsertionNUMBER (word H3) set number InsertionNUMBER set label (word number) set label-color orange ] ] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox8 -80] set H4 A4 if (H4 != 0) [ ask this-square [ set InsertionNUMBER (word H4) set number InsertionNUMBER set label (word number) set label-color orange ] ] ;;;;;;;;;;;;;;;;;Box 9 PrePlaced Numbers;;;;;;;;;;;;;;; ;These are just Random Numbers placed in Box 9 let box9-xcordline1 n-values (3 - 1 + 1) [ 1 + ? ] let box9-xcoordlist1 shuffle box9-xcordline1 let xcorforbox9 40 if (position 1 box9-xcoordlist1 = 0 )[ set xcorforbox9 40] if (position 1 box9-xcoordlist1 = 1 )[ set xcorforbox9 60] if (position 1 box9-xcoordlist1 = 2 )[ set xcorforbox9 80] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox9 -40] set I1 B1 if (I1 != 0) [ ask this-square [ set InsertionNUMBER (word I1) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 2 box9-xcoordlist1 = 0 )[ set xcorforbox9 40] if (position 2 box9-xcoordlist1 = 1 )[ set xcorforbox9 60] if (position 2 box9-xcoordlist1 = 2 )[ set xcorforbox9 80] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox9 -40] set I2 B2 if (I2 != 0) [ ask this-square [ set InsertionNUMBER (word I2) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 3 box9-xcoordlist1 = 0 )[ set xcorforbox9 40 ] if (position 3 box9-xcoordlist1 = 1 )[ set xcorforbox9 60] if (position 3 box9-xcoordlist1 = 2 )[ set xcorforbox9 80] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox9 -62] set I3 B3 if (I3 != 0) [ ask this-square [ set InsertionNUMBER (word I3) set number InsertionNUMBER set label (word number) set label-color orange ] ] ] if (HardLevel? = False) [ ;;;;;;;;;;;;;;;;;Box 2 PrePlaced Numbers;;;;;;;;;;;;;;; ;These are just Random Numbers placed in Box 2 let box2-xcordline1 n-values (3 - 1 + 1) [ 1 + ? ] let box2-xcoordlist1 shuffle box2-xcordline1 let xcorforbox2 -20 if (position 1 box2-xcoordlist1 = 0 )[ set xcorforbox2 -20] if (position 1 box2-xcoordlist1 = 1 )[ set xcorforbox2 0] if (position 1 box2-xcoordlist1 = 2 )[ set xcorforbox2 20] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox2 82] if (B1 != 0) [ ask this-square [ set InsertionNUMBER (word B1) ; Number 5 placed in (x=-19 , y=82) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 2 box2-xcoordlist1 = 0 )[ set xcorforbox2 -20] if (position 2 box2-xcoordlist1 = 1 )[ set xcorforbox2 0] if (position 2 box2-xcoordlist1 = 2 )[ set xcorforbox2 20] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox2 60] if (B2 != 0) [ ask this-square [ set InsertionNUMBER (word B2) set number InsertionNUMBER set label (word number) set label-color orange ] ] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox2 40] if (position 3 box2-xcoordlist1 = 0 )[ set xcorforbox2 -20 ] if (position 3 box2-xcoordlist1 = 1 )[ set xcorforbox2 0] if (position 3 box2-xcoordlist1 = 2 )[ set xcorforbox2 20] if (B3 != 0) [ ask this-square [ set InsertionNUMBER (word B3) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (B1 = 0) [set chklessthanseventeen 1 ] if (B2 = 0) [set chklessthanseventeen 1 ] if (B3 = 0) [set chklessthanseventeen 1 ] ;;;;;;;;;;;;;;;;;Box 3 PrePlaced Numbers;;;;;;;;;;;;;;; ;These are just Random Numbers placed in Box 3 let box3-xcordline1 n-values (3 - 1 + 1) [ 1 + ? ] let box3-xcoordlist1 shuffle box3-xcordline1 let xcorforbox3 40 if (position 1 box3-xcoordlist1 = 0 )[ set xcorforbox3 40] if (position 1 box3-xcoordlist1 = 1 )[ set xcorforbox3 60] if (position 1 box3-xcoordlist1 = 2 )[ set xcorforbox3 80] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox3 82] if (C1 != 0) [ ask this-square [ set InsertionNUMBER (word C1) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 2 box3-xcoordlist1 = 0 )[ set xcorforbox3 40] if (position 2 box3-xcoordlist1 = 1 )[ set xcorforbox3 60] if (position 2 box3-xcoordlist1 = 2 )[ set xcorforbox3 80] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox3 60] if (C2 != 0) [ ask this-square [ set InsertionNUMBER (word C2) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 3 box3-xcoordlist1 = 0 )[ set xcorforbox3 40 ] if (position 3 box3-xcoordlist1 = 1 )[ set xcorforbox3 60] if (position 3 box3-xcoordlist1 = 2 )[ set xcorforbox3 80] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox3 40] if (C3 != 0) [ ask this-square [ set InsertionNUMBER (word C3) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (C1 = 0) [set chklessthanseventeen 1 ] if (C2 = 0) [set chklessthanseventeen 1 ] if (C3 = 0) [set chklessthanseventeen 1 ] ;;;;;;;;;;;;;;;;;Box 4 PrePlaced Numbers;;;;;;;;;;;;;;; ;These are just Random Numbers placed in Box 4 let box4-xcordline1 n-values (3 - 1 + 1) [ 1 + ? ] let box4-xcoordlist1 shuffle box4-xcordline1 let xcorforbox4 -80 if (position 1 box4-xcoordlist1 = 0 )[ set xcorforbox4 -80] if (position 1 box4-xcoordlist1 = 1 )[ set xcorforbox4 -60] if (position 1 box4-xcoordlist1 = 2 )[ set xcorforbox4 -40] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox4 20] set D1 B1 if (D1 != 0) [ ask this-square [ set InsertionNUMBER (word D1) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 2 box4-xcoordlist1 = 0 )[ set xcorforbox4 -80] if (position 2 box4-xcoordlist1 = 1 )[ set xcorforbox4 -60] if (position 2 box4-xcoordlist1 = 2 )[ set xcorforbox4 -40] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox4 0] set D2 B2 if (D2 != 0) [ ask this-square [ set InsertionNUMBER (word D2) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 3 box4-xcoordlist1 = 0 )[ set xcorforbox4 -80 ] if (position 3 box4-xcoordlist1 = 1 )[ set xcorforbox4 -60] if (position 3 box4-xcoordlist1 = 2 )[ set xcorforbox4 -40] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox4 -20] set D3 B3 if (D3 != 0) [ ask this-square [ set InsertionNUMBER (word D3) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (D1 = 0) [set chklessthanseventeen 1 ] if (D2 = 0) [set chklessthanseventeen 1 ] if (D3 = 0) [set chklessthanseventeen 1 ] ;;;;;;;;;;;;;;;;;Box 5 PrePlaced Numbers;;;;;;;;;;;;;;; ;These are just Random Numbers placed in Box 5 let box5-xcordline1 n-values (3 - 1 + 1) [ 1 + ? ] let box5-xcoordlist1 shuffle box5-xcordline1 let xcorforbox5 -20 if (position 1 box5-xcoordlist1 = 0 )[ set xcorforbox5 -20] if (position 1 box5-xcoordlist1 = 1 )[ set xcorforbox5 0] if (position 1 box5-xcoordlist1 = 2 )[ set xcorforbox5 20] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox5 20] set E1 C1 if (E1 != 0) [ ask this-square [ set InsertionNUMBER (word E1) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 2 box5-xcoordlist1 = 0 )[ set xcorforbox5 -20] if (position 2 box5-xcoordlist1 = 1 )[ set xcorforbox5 0] if (position 2 box5-xcoordlist1 = 2 )[ set xcorforbox5 20] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox5 20] set E2 C2 if (E2 != 0) [ ask this-square [ set InsertionNUMBER (word E2) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 3 box5-xcoordlist1 = 0 )[ set xcorforbox5 -20 ] if (position 3 box5-xcoordlist1 = 1 )[ set xcorforbox5 0] if (position 3 box5-xcoordlist1 = 2 )[ set xcorforbox5 20] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox5 0] set E3 C3 if (E3 != 0) [ ask this-square [ set InsertionNUMBER (word E3) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (E1 = 0) [set chklessthanseventeen 1 ] if (E2 = 0) [set chklessthanseventeen 1 ] if (E3 = 0) [set chklessthanseventeen 1 ] ;;;;;;;;;;;;;;;;;Box 7 PrePlaced Numbers;;;;;;;;;;;;;;; ;These are just Random Numbers placed in Box 7 let box7-xcordline1 n-values (3 - 1 + 1) [ 1 + ? ] let box7-xcoordlist1 shuffle box7-xcordline1 let xcorforbox7 -80 if (position 1 box7-xcoordlist1 = 0 )[ set xcorforbox7 -80] if (position 1 box7-xcoordlist1 = 1 )[ set xcorforbox7 -60] if (position 1 box7-xcoordlist1 = 2 )[ set xcorforbox7 -40] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox7 -40] set G1 C1 if (G1 != 0) [ ask this-square [ set InsertionNUMBER (word G1) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 2 box7-xcoordlist1 = 0 )[ set xcorforbox7 -80] if (position 2 box7-xcoordlist1 = 1 )[ set xcorforbox7 -60] if (position 2 box7-xcoordlist1 = 2 )[ set xcorforbox7 -40] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox7 -40] set G2 C2 if (G2 != 0) [ ask this-square [ set InsertionNUMBER (word G2) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 3 box7-xcoordlist1 = 0 )[ set xcorforbox7 -80 ] if (position 3 box7-xcoordlist1 = 1 )[ set xcorforbox7 -60] if (position 3 box7-xcoordlist1 = 2 )[ set xcorforbox7 -40] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox7 -80] set G3 C3 if (G3 != 0) [ ask this-square [ set InsertionNUMBER (word G3) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (G1 = 0) [set chklessthanseventeen 1 ] if (G2 = 0) [set chklessthanseventeen 1 ] if (G3 = 0) [set chklessthanseventeen 1 ] ;;;;;;;;;;;;;;;;;Box 9 PrePlaced Numbers;;;;;;;;;;;;;;; ;These are just Random Numbers placed in Box 9 let box9-xcordline1 n-values (3 - 1 + 1) [ 1 + ? ] let box9-xcoordlist1 shuffle box9-xcordline1 let xcorforbox9 40 if (position 1 box9-xcoordlist1 = 0 )[ set xcorforbox9 40] if (position 1 box9-xcoordlist1 = 1 )[ set xcorforbox9 60] if (position 1 box9-xcoordlist1 = 2 )[ set xcorforbox9 80] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox9 -40] set I1 B1 if (I1 != 0) [ ask this-square [ set InsertionNUMBER (word I1) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 2 box9-xcoordlist1 = 0 )[ set xcorforbox9 40] if (position 2 box9-xcoordlist1 = 1 )[ set xcorforbox9 60] if (position 2 box9-xcoordlist1 = 2 )[ set xcorforbox9 80] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox9 -40] set I2 B2 if (I2 != 0) [ ask this-square [ set InsertionNUMBER (word I2) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 3 box9-xcoordlist1 = 0 )[ set xcorforbox9 40 ] if (position 3 box9-xcoordlist1 = 1 )[ set xcorforbox9 60] if (position 3 box9-xcoordlist1 = 2 )[ set xcorforbox9 80] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox9 -62] set I3 B3 if (I3 != 0) [ ask this-square [ set InsertionNUMBER (word I3) set number InsertionNUMBER set label (word number) set label-color orange ] ] ] if (I1 = 0) [set chklessthanseventeen 1 ] if (I2 = 0) [set chklessthanseventeen 1 ] if (I3 = 0) [set chklessthanseventeen 1 ] ;;;;;;;;;;;;;;;;;Box 6 PrePlaced Numbers;;;;;;;;;;;;;;; ;These are just Random Numbers placed in Box 6 if ( chklessthanseventeen = 1 ) [ let box6-xcordline1 n-values (3 - 1 + 1) [ 1 + ? ] let box6-xcoordlist1 shuffle box6-xcordline1 let xcorforbox6 40 if (position 1 box6-xcoordlist1 = 0 )[ set xcorforbox6 40] if (position 1 box6-xcoordlist1 = 1 )[ set xcorforbox6 60] if (position 1 box6-xcoordlist1 = 2 )[ set xcorforbox6 80] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox6 20] set F1 A1 if (F1 != 0) [ ask this-square [ set InsertionNUMBER (word F1) set number InsertionNUMBER set label (word number) set label-color orange ] ] if (position 2 box6-xcoordlist1 = 0 )[ set xcorforbox6 40] if (position 2 box6-xcoordlist1 = 1 )[ set xcorforbox6 60] if (position 2 box6-xcoordlist1 = 2 )[ set xcorforbox6 80] set this-square min-one-of squares with [number = 0 or label-color = orange] [distancexy xcorforbox6 0] set F2 A2 if (F2 != 0) [ ask this-square [ set InsertionNUMBER (word F2) set number InsertionNUMBER set label (word number) set label-color orange ] ] ] end to Delete ; This is the action listener for the "Delete" button, by which user can delete numbers let this-square nobody let this-mouse-xcor 0 let this-mouse-ycor 0 if (mouse-down?) [ set this-mouse-xcor mouse-xcor set this-mouse-ycor mouse-ycor set this-square min-one-of squares with [label-color = black] [distancexy this-mouse-xcor this-mouse-ycor] if ([distancexy this-mouse-xcor this-mouse-ycor] of this-square < 5) [ ask this-square [ set number 0 ; Sets the number 0 set label "" ; Sets the label as empty so that no number is displayed set label-color black ] if not Check ; Now we check i the number fits correct accprding to soduku RULES (defined below) [ stop ] ; If it does not obey RULES, the check returns false and the error message is displayed ] ] end to-report placed-number [x y] ; Whenever a number is placed, it is reported, such that ; Its is saved and checked against the soduku RULES to ; display hints if RULES are violated ; the x and y coordinates of placed-number are reported and saved ; and then checked (below) report [number] of (one-of squares with [squareinX = x and squareinY = y]) end to Solver if ( sol-var = 1 ) [ user-message ( "NOTE : Solver is turned ON.\n Click on any square to let solver automatically place number" ) set sol-var 0 ] let this-square nobody let this-mouse-xcor 0 ; Initial value for variables set to 0 let this-mouse-ycor 0 let sol-num 1 let repeating-var 1 set solver-to-check-var 1 ; Tells the check to not to display errors while solver is in action if (mouse-down?) ; If mouse is pressed on a square [ set sol-num 1 set this-mouse-xcor mouse-xcor ; We get the X and Y coordinates of mouse set this-mouse-ycor mouse-ycor ; Getting Y coordinates set this-square min-one-of squares with [number = 0 or label-color = black] [distancexy this-mouse-xcor this-mouse-ycor] ; setting distancexy to the coodinates collected above if ([distancexy this-mouse-xcor this-mouse-ycor] of this-square < 5) ; If the distance of coordinates in within range of the square i-e differnece is NOT more than 5 [ while [repeating-var = 1 ] [ ask this-square ;Ask the square to add the number [ set InsertionNUMBER (word sol-num) set number InsertionNUMBER ;InsertionNUMBER is the number in the chooser/dropdown shown below the buttons set label (word number) ;This InsertionNUMBER is added in the box set label-color black ] if not Check ;Calling the check, this will be explained later [ set sol-num sol-num + 1 ] if (sol-num > 9) [ set repeating-var 0 set sol-num 1 user-message ( "Solver Entered Loop Hole Condition \n Please Rearrange Numbers \n Check Disabled" ) ] if Check [ set repeating-var 0 set sol-num 1 ] ] ] ] end to load-game let userSavedGame user-input ("Enter Name of saved game file ") if (userSavedGame = "") [user-message ("ERROR: Invalid or No name inserted!!!")] if (userSavedGame != "") [ file-open userSavedGame let saved-numbers [] while [ not file-at-end? ] [ set saved-numbers lput file-read saved-numbers ] file-close let this-square nobody let current-iter1 0 let xpos -82 let ypos -82 foreach n-values 81 [? + 1] [ set this-square min-one-of squares with [number = 0 or label-color = white] [distancexy xpos ypos ] ask this-square [ if ( item current-iter1 saved-numbers != 0 ) [ set InsertionNUMBER (word item current-iter1 saved-numbers) set number InsertionNUMBER set label (word number) set label-color white ]] set current-iter1 current-iter1 + 1 set ypos ypos + 20 if (ypos > 82) [ set ypos -82 set xpos xpos + 20 ] ] user-message ("Game is Now Loaded!!!\n White numbers are the saved game numbers") ] end to save-game let userFilename user-input ("Enter a Name to save game\n If file does not exist, it will be created") carefully [ file-delete userFilename ] [ ] file-open userFilename if (userFilename != "" ) [ foreach sort turtles [ ask ? [ file-print ( number) file-print "" file-print " " ; Used to print space after a number. ] ]] file-close if (userFilename != "") [user-message ("Game Saved Successfully!!")] if (userFilename = "") [user-message ("Invalid or No name of file entered") user-message ("ERROR: Game Not Saved!") ] end to-report Check ; ; Here we check the numbers ,if they follow the RULES let placed-numbers [] ; Array to store the numbers placed in a row or column let x 0 let y 0 ; We check three RULES ; 1st RULE is checking VERICAL Lines, i-e NO number is repeated in Vertical Line ; 2nd RULE is checking Horizontal Lines, i-e NO number is repeated in Horizontal Line ; 3rd RULE is checking 3 by 3 grids , i-e no number 1 to 9 is repeated in a single 3 by 3 grid let okVertical false ; Checking Vertical Lines let okHorizontal false ; Checking Horizontald Lines let okGrid false ; Checking 3 by 3 Grids ;;;; Checking Vertical Lines set okVertical false foreach n-values 9 [? + 1] ; 1 to 9 values [ set x ? set placed-numbers n-values 9 [placed-number x (? + 1)] set placed-numbers remove 0 placed-numbers ; Not Checking Empty Squares set okVertical (length placed-numbers = length remove-duplicates placed-numbers) ; This is the checking RULES part ; Here we are checking if the total no of vertical numbers in a column are equalto the numbers after the removal of ;duplicates then the RULES are OBEYED. and "okVertical" is set to "true". Otherwise it is false if Hints? ; If the "Hints" switch in Interface is On , only then we display the hints/message [ if not okVertical ; If vertical Rule is disobeyed display ERROR mesage below [ if (solver-to-check-var != 1) [ user-message (word "ERROR!!! \nLine : " x " Vertical \nNumbers = " placed-numbers "\nError Type : Repeated Numbers") ] report false ] ] ] ;;;; Checking Horizontal Lines set okHorizontal false foreach n-values 9 [? + 1] ; 1 to 9 values [ set y ? set placed-numbers n-values 9 [placed-number (? + 1) y] set placed-numbers remove 0 placed-numbers ; Not Checking Empty Squares set okHorizontal (length placed-numbers = length remove-duplicates placed-numbers) ; This is the checking RULES part ; Here we are checking if the total no of horizontal numbers in a row are equalto the numbers after the removal of ;duplicates then the RULES are OBEYED. and "okHorizontal" is set to "true". Otherwise it is false if Hints? ; If the "Hints" switch in Interface is On , only then we display the hints/message [ if not okHorizontal ; If Horizontal Rule is disobeyed display ERROR mesage below [ if (solver-to-check-var != 1) [ user-message (word "ERROR!!! \nLine : " y " Horizontal \nNumbers = " placed-numbers "\nError Type : Repeated Numbers") ] report false ] ] ] ;;;; Checking the Grids set okGrid false foreach [2 5 8] ; X of grid (Center) [ set x ? foreach [2 5 8] ; Y of grid (Center) [ set y ? set placed-numbers (list placed-number (x - 1) (y + 1) placed-number (x ) (y + 1) placed-number (x + 1) (y + 1) placed-number (x - 1) (y ) placed-number (x ) (y ) placed-number (x + 1) (y ) placed-number (x - 1) (y - 1) placed-number (x ) (y - 1) placed-number (x + 1) (y - 1) ) set placed-numbers remove 0 placed-numbers ; Not checking Emty squares in a Grid set okGrid (length placed-numbers = length remove-duplicates placed-numbers) ; This is the checking RULES part ; Here we are checking if the total no of [1 to 9] numbers in a GRID are equalto the numbers after the removal of ;duplicates then the RULES are OBEYED. and "okGrid" is set to "true". Otherwise it is false if Hints? [ if not okGrid [ if (solver-to-check-var != 1) [user-message (word "Error in Grid\nWith Numbers = " placed-numbers) ] report false ] ] ] ] report true end ;///////////////////////////////////////////////////////////////////////// ; Copyright 2009 William John Teahan. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from William John Teahan. ; Contact William John Teahan for appropriate licenses for redistribution for ; profit. ; ; To refer to this model in publications, please use: ; ; Teahan, W. J. (2010). Sudoku Builder NetLogo model. ; Artificial Intelligence. Ventus Publishing Aps ; Changes by Muhammad Rizwan, from NUST-SEECS, Islamabad, Pakistan ;///////////////////////////////////////////////////////////////////////// @#$#@#$#@ GRAPHICS-WINDOW 211 22 665 497 110 110 2.01 1 20 1 1 1 0 0 0 1 -110 110 -110 110 0 0 1 ticks 30.0 BUTTON 28 24 167 57 Set/Reset Game Setup-Game NIL 1 T OBSERVER NIL NIL NIL NIL 1 BUTTON 28 93 167 126 NIL Insert T 1 T OBSERVER NIL NIL NIL NIL 1 BUTTON 28 159 167 192 Check if Check\n[ user-message \"Ok! No Rules Violated\" ] \n NIL 1 T OBSERVER NIL NIL NIL NIL 1 BUTTON 28 126 167 159 NIL Delete T 1 T OBSERVER NIL NIL NIL NIL 1 CHOOSER 27 294 168 339 InsertionNUMBER InsertionNUMBER "1" "2" "3" "4" "5" "6" "7" "8" "9" 1 BUTTON 28 57 167 93 PrePlace Numbers PrePlace NIL 1 T OBSERVER NIL NIL NIL NIL 1 SWITCH 33 253 162 286 Hints? Hints? 0 1 -1000 SWITCH 32 206 160 239 HardLevel? HardLevel? 0 1 -1000 BUTTON 27 350 169 383 Solver Solver T 1 T OBSERVER NIL NIL NIL NIL 1 BUTTON 26 454 173 487 Load Game load-game NIL 1 T OBSERVER NIL NIL NIL NIL 1 BUTTON 26 488 173 521 Save Game save-game NIL 1 T OBSERVER NIL NIL NIL NIL 1 BUTTON 26 394 172 443 Build Custom Maps Build T 1 T OBSERVER NIL NIL NIL NIL 1 @#$#@#$#@ ## WHAT IS IT? This is a Soduku Game ## WHAT IS ITS PURPOSE? The Purpose of the game is to show how the game can be built and solved through the use of logics ## HOW IT WORKS It creates several squares, which store some initially placed "Orange" numbers in them. The user enters numbers of their choice in "Black" and the game checks if the numbers are according to the RULES defined for the game. If the rules are violated, the game displays error messages (If Hints is Turned On) ## HOW TO USE IT + INTERFACE To use it 1) First press "Set/Reset Game", this sets the game map 2) Then Press "PrePlace Numbers", this places some random Orange numbers in the map 3) Then Press "Insert" button and start inserting numbers in the game by selecting any number from the chooser/slider and then clicking in any empty square. The selected number from the chooser will be placed in the empty square 4) If you want to delete any placed number( black only) , you can press delete button and click on the number , it will be deleted. (Note: Orange Numbers Cannot be delted, as they are game specified) 5) Hints switch shows hints, if a wrong number is placed in the wrong square,it displays error 6) Check button displays the result if the map is correct or not. (Only works if Hint is enabled) 7) The solver places (Best Possible) numbers automatically 8) You can load/save game to a text file ## THINGS TO NOTICE 1) You cannot delete orange numbers, as they are predefined in game 2) If Hint is enabled, it shows the error message as soon as RULES are violated 3) The solver can solve the entire game IF it does not enter a loop hole. By loop hole, we mean that it cannot enter any number because no number is suitable and will cause repetition in any case. An image of loop hole is attached. @#$#@#$#@ default true 0 Polygon -7500403 true true 150 5 40 250 150 205 260 250 airplane true 0 Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15 arrow true 0 Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 box false 0 Polygon -7500403 true true 150 285 285 225 285 75 150 135 Polygon -7500403 true true 150 135 15 75 150 15 285 75 Polygon -7500403 true true 15 75 15 225 150 285 150 135 Line -16777216 false 150 285 150 135 Line -16777216 false 150 135 15 75 Line -16777216 false 150 135 285 75 bug true 0 Circle -7500403 true true 96 182 108 Circle -7500403 true true 110 127 80 Circle -7500403 true true 110 75 80 Line -7500403 true 150 100 80 30 Line -7500403 true 150 100 220 30 butterfly true 0 Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240 Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240 Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163 Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165 Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225 Circle -16777216 true false 135 90 30 Line -16777216 false 150 105 195 60 Line -16777216 false 150 105 105 60 car false 0 Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180 Circle -16777216 true false 180 180 90 Circle -16777216 true false 30 180 90 Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89 Circle -7500403 true true 47 195 58 Circle -7500403 true true 195 195 58 circle false 0 Circle -7500403 true true 0 0 300 circle 2 false 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 cow false 0 Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167 Polygon -7500403 true true 73 210 86 251 62 249 48 208 Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123 cylinder false 0 Circle -7500403 true true 0 0 300 directional circle true 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 Line -1 false 150 0 150 150 dot false 0 Circle -7500403 true true 90 90 120 face happy true 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240 face neutral false 0 Circle -7500403 true true 8 7 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Rectangle -16777216 true false 60 195 240 225 face sad true 0 Circle -7500403 true true 8 8 285 Circle -16777216 true false 60 75 60 Circle -16777216 true false 180 75 60 Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183 fish false 0 Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166 Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165 Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60 Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166 Circle -16777216 true false 215 106 30 flag false 0 Rectangle -7500403 true true 60 15 75 300 Polygon -7500403 true true 90 150 270 90 90 30 Line -7500403 true 75 135 90 135 Line -7500403 true 75 45 90 45 flower false 0 Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135 Circle -7500403 true true 85 132 38 Circle -7500403 true true 130 147 38 Circle -7500403 true true 192 85 38 Circle -7500403 true true 85 40 38 Circle -7500403 true true 177 40 38 Circle -7500403 true true 177 132 38 Circle -7500403 true true 70 85 38 Circle -7500403 true true 130 25 38 Circle -7500403 true true 96 51 108 Circle -16777216 true false 113 68 74 Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218 Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240 house false 0 Rectangle -7500403 true true 45 120 255 285 Rectangle -16777216 true false 120 210 180 285 Polygon -7500403 true true 15 120 150 15 285 120 Line -16777216 false 30 120 270 120 leaf false 0 Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195 Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195 line true 0 Line -7500403 true 150 0 150 300 line half true 0 Line -7500403 true 150 0 150 150 number: eight true 0 Polygon -7500403 true true 75 150 45 135 30 105 30 75 45 45 75 15 120 0 180 0 225 15 255 45 270 75 270 105 255 135 225 150 255 165 270 195 270 225 255 255 225 285 180 300 120 300 75 285 45 255 30 225 30 195 45 165 75 150 Polygon -1 true false 90 105 135 120 180 120 210 105 225 75 210 45 180 30 135 30 90 45 75 75 Polygon -1 true false 90 240 135 255 180 255 210 240 225 210 210 180 180 165 135 165 90 180 75 210 number: five true 0 Rectangle -7500403 true true 75 0 225 30 Rectangle -7500403 true true 75 30 120 150 Polygon -7500403 true true 120 105 150 105 195 120 225 150 240 195 240 225 225 255 195 285 150 300 120 300 75 285 45 270 45 225 75 240 105 255 135 270 165 255 195 225 195 195 180 165 150 150 120 150 number: four true 0 Rectangle -7500403 true true 150 0 195 300 Rectangle -7500403 true true 15 180 270 210 Polygon -7500403 true true 15 180 150 0 150 60 60 180 number: nine true 0 Polygon -7500403 true true 120 0 165 0 210 15 240 45 255 75 270 165 270 195 255 240 225 285 180 300 150 300 90 285 69 279 60 270 60 225 75 240 120 255 150 255 195 240 225 210 225 180 225 150 180 180 135 180 90 165 60 135 45 105 45 60 60 30 87 11 120 0 Polygon -1 true false 156 135 171 135 201 120 216 105 216 75 201 45 156 30 126 30 96 45 81 60 81 90 96 120 126 135 156 135 number: one true 0 Rectangle -7500403 true true 120 30 180 270 Rectangle -7500403 true true 60 270 240 300 Polygon -7500403 true true 180 0 180 30 180 45 60 45 60 15 180 0 number: seven true 0 Rectangle -7500403 true true 60 0 240 30 Polygon -7500403 true true 240 30 195 105 165 165 135 240 120 300 75 300 90 240 120 165 150 105 195 30 number: six true 0 Polygon -7500403 true true 180 300 135 300 90 285 60 255 45 225 30 135 30 105 45 60 75 15 120 0 150 0 210 15 231 21 240 30 240 75 225 60 180 45 150 45 105 60 75 90 75 120 75 150 120 120 165 120 210 135 240 165 255 195 255 240 240 270 213 289 180 300 Polygon -1 true false 144 165 129 165 99 180 84 195 84 225 99 255 144 270 174 270 204 255 219 240 219 210 204 180 174 165 144 165 number: ten true 0 Rectangle -7500403 true true 30 45 75 270 Rectangle -7500403 true true 0 240 105 270 Polygon -7500403 true true 75 60 75 15 60 15 0 30 0 60 Polygon -7500403 true true 120 60 135 30 165 15 225 15 255 30 270 60 285 120 285 180 270 225 240 255 210 270 180 270 150 255 120 225 105 180 105 120 120 60 Polygon -1 true false 150 120 165 60 180 45 210 45 225 60 240 120 240 180 225 225 210 240 180 240 165 225 150 180 150 120 number: three true 0 Polygon -7500403 true true 60 30 90 15 135 0 165 0 210 15 240 45 255 75 255 105 236 134 208 150 75 150 75 135 180 135 210 120 210 90 210 60 180 45 150 45 105 45 45 75 Polygon -7500403 true true 75 150 207 149 239 170 255 195 255 225 240 255 210 285 165 300 135 300 90 285 60 270 45 225 105 255 135 255 180 255 210 240 210 225 210 180 180 165 75 165 Rectangle -7500403 true true 75 135 195 165 number: two true 0 Polygon -7500403 true true 90 45 60 60 45 60 45 15 105 0 120 0 180 0 210 15 240 30 270 75 270 120 255 150 210 180 120 225 105 240 105 255 270 255 270 300 45 300 45 240 60 225 105 195 210 135 225 120 225 75 180 45 120 45 number: zero true 0 Polygon -7500403 true true 60 60 90 15 135 0 165 0 210 15 240 60 255 120 255 180 240 240 210 285 165 300 135 300 90 285 60 240 45 180 45 120 60 60 Polygon -1 true false 135 30 165 30 180 45 195 60 210 120 210 165 195 225 180 255 165 270 135 270 120 255 105 225 90 165 90 120 105 60 135 30 pentagon false 0 Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120 person false 0 Circle -7500403 true true 110 5 80 Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90 Rectangle -7500403 true true 127 79 172 94 Polygon -7500403 true true 195 90 240 150 225 180 165 105 Polygon -7500403 true true 105 90 60 150 75 180 135 105 plant false 0 Rectangle -7500403 true true 135 90 165 300 Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285 Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285 Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210 Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135 Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135 Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60 Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90 square false 0 Rectangle -7500403 true true 30 30 270 270 square 10 false 0 Rectangle -7500403 true true 30 15 285 270 Rectangle -1 true false 45 45 255 255 square 2 false 0 Rectangle -7500403 true true 30 30 270 270 Rectangle -16777216 true false 60 60 240 240 star false 0 Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108 target false 0 Circle -7500403 true true 0 0 300 Circle -16777216 true false 30 30 240 Circle -7500403 true true 60 60 180 Circle -16777216 true false 90 90 120 Circle -7500403 true true 120 120 60 tree false 0 Circle -7500403 true true 118 3 94 Rectangle -6459832 true false 120 195 180 300 Circle -7500403 true true 65 21 108 Circle -7500403 true true 116 41 127 Circle -7500403 true true 45 90 120 Circle -7500403 true true 104 74 152 triangle false 0 Polygon -7500403 true true 150 30 15 255 285 255 triangle 2 false 0 Polygon -7500403 true true 150 30 15 255 285 255 Polygon -16777216 true false 151 99 225 223 75 224 truck false 0 Rectangle -7500403 true true 4 45 195 187 Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194 Rectangle -1 true false 195 60 195 105 Polygon -16777216 true false 238 112 252 141 219 141 218 112 Circle -16777216 true false 234 174 42 Rectangle -7500403 true true 181 185 214 194 Circle -16777216 true false 144 174 42 Circle -16777216 true false 24 174 42 Circle -7500403 false true 24 174 42 Circle -7500403 false true 144 174 42 Circle -7500403 false true 234 174 42 turtle true 0 Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210 Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105 Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105 Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87 Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210 Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99 wheel false 0 Circle -7500403 true true 3 3 294 Circle -16777216 true false 30 30 240 Line -7500403 true 150 285 150 15 Line -7500403 true 15 150 285 150 Circle -7500403 true true 120 120 60 Line -7500403 true 216 40 79 269 Line -7500403 true 40 84 269 221 Line -7500403 true 40 216 269 79 Line -7500403 true 84 40 221 269 x false 0 Polygon -7500403 true true 270 75 225 30 30 225 75 270 Polygon -7500403 true true 30 75 75 30 270 225 225 270 @#$#@#$#@ NetLogo 5.0.3 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ default 0.0 -0.2 0 0.0 1.0 0.0 1 1.0 0.0 0.2 0 0.0 1.0 link direction true 0 Line -7500403 true 150 150 90 180 Line -7500403 true 150 150 210 180 @#$#@#$#@ 0 @#$#@#$#@