The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach.

Slides:



Advertisements
Similar presentations
COSC2007 Data Structures II
Advertisements

Haas MFE SAS Workshop Lecture 3:
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 5. 2 List Utilities Scheme built-in procedures –(list x y z...) –(list-ref lst index) –(length lst) –(append.
CREATED BY: CALVIN WILLIAMS Bidirectional Search.
When “ANYDATE” Doesn’t Mean Any Date: A Macro Solution Charlotte King, Alberta Health Services John Fleming, Alberta Health Services SAS Global Forum Paper.
How SAS implements structured programming constructs
RAPTOR Syntax and Semantics By Lt Col Schorsch
Structural Equation Modeling Mgmt 290 Lecture 6 – LISREL Nov 2, 2009.
879 CISC Parallel Computation High Performance Fortran (HPF) Ibrahim Halil Saruhan Although the [Fortran] group broke new ground …
Slide C.1 SAS MathematicalMarketing Appendix C: SAS Software Uses of SAS  CRM  datamining  data warehousing  linear programming  forecasting  econometrics.
Nonstandard Problmes Produced by E. Gretchen Gascon.
Outline Proc Report Tricks Kelley Weston. Outline Examples 1.Text that spans columnsText that spans columns 2.Patient-level detail in the titlesPatient-level.
Creating a Compact Columnar Output with PROC REPORT Walter R. Young Principal Clinical Programmer Analyst Wyeth.
Aim: How do we find confidence interval using SPSS? SPSS Assignment 3 due Thursday.
Solving Systems of Linear Equations Part Pivot a Matrix 2. Gaussian Elimination Method 3. Infinitely Many Solutions 4. Inconsistent System 5. Geometric.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing.
An Euler Circuit is a cycle of an undirected graph, that traverses every edge of the graph exactly once, and ends at the same node from which it began.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Chapter 2 Writing Simple Programs
Basic And Advanced SAS Programming
Please close your laptops and turn off and put away your cell phones, and get out your note-taking materials. Today’s daily homework quiz will be given.
Understanding SAS Data Step Processing Alan C. Elliott stattutorials.com.
Data Cleaning 101 Ron Cody, Ed.D Robert Wood Johnson Medical School Piscataway, NJ.
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
1 Chapter 9 Spaces with LINDA. 2 Linda Linda is an experimental programming concept unlike ADA or Occam which are fully developed production-quality languages.
Chapter 10:Processing Macro Variables at Execution Time 1 STAT 541 © Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Specialised (user defined) constraints in JChoco 2 examples: max and subtour elimination.
Lesson 13-1: Matrices & Systems Objective: Students will: State the dimensions of a matrix Solve systems using matrices.
INTRODUCTION TO SAS MACRO PROCESSING James R. Bence, Ph.D., Co-Director Quantitative Fisheries Center Professor Department of Fisheries and Wildlife March.
Please close your laptops and turn off and put away your cell phones, and get out your note-taking materials.
Chapter 9 Matrices and Determinants Copyright © 2014, 2010, 2007 Pearson Education, Inc Multiplicative Inverses of Matrices and Matrix Equations.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Water Resources Development and Management Optimization (Linear Programming) CVEN 5393 Mar 4, 2011.
Macro Overview Mihaela Simion. Macro Facility Overview Definition : The SAS Macro Facility is a tool within base SAS software that contains the essential.
Chapter P Prerequisites: Fundamental Concepts of Algebra 1 Copyright © 2014, 2010, 2007 Pearson Education, Inc. 1 P.9 Linear Inequalities and Absolute.
Data Structures and Algorithms Lecture 3 Instructor: Quratulain Date: 8 th September, 2009.
Define your Own SAS® Command Line Commands Duong Tran – Independent Contractor, London, UK Define your Own SAS® Command Line Commands Duong Tran – Independent.
Class Opener:. Identifying Matrices Student Check:
Macro Variable Resolution Enio Presutto York University, Toronto, Canada.
© OCS Biometric Support 1 APPEND, EXECUTE and MACRO Jim Groeneveld, OCS Biometric Support, ‘s Hertogenbosch, Netherlands. PhUSE 2010 – CC05 PhUSE 2010.
Slide Copyright © 2009 Pearson Education, Inc. 7.3 Matrices.
Copyright © 2011 Pearson Education, Inc. Solving Linear Systems Using Matrices Section 6.1 Matrices and Determinants.
3.6 Solving Systems Using Matrices You can use a matrix to represent and solve a system of equations without writing the variables. A matrix is a rectangular.
ALGORITHMS.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Copyright © 2012, 2009, 2005, 2002 Pearson Education, Inc. Section 6.7 Solving Quadratic Equations by Factoring.
An Introduction Katherine Nicholas & Liqiong Fan.
Computing with SAS Software A SAS program consists of SAS statements. 1. The DATA step consists of SAS statements that define your data and create a SAS.
An Introduction to Proc Transpose David P. Rosenfeld HR Consultant, Workforce Planning & Data Management City of Toronto.
CS 100Lecture 171 CS100A Lecture 17 n Previous Lecture –Programming concepts n Two-dimensional arrays –Java Constructs n Constructors for two-dimensional.
BMTRY 789 Lecture 6: Proc Sort, Random Number Generators, and Do Loops Readings – Chapters 5 & 6 Lab Problem - Brain Teaser Homework Due – HW 2 Homework.
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 6. 2 List Utilities Scheme built-in procedures –(list x y z...) –(list-ref lst index) –(length lst) –(append.
Two Dimensional Arrays. Students will be able to: code algorithms to solve two- dimensional array problems. use 2-D arrays in programs. pass two-use 2-D.
Boolean Algebra and Computer Logic Mathematical Structures for Computer Science Chapter 7 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Boolean Logic.
Chapter 6: Modifying and Combining Data Sets  The SET statement is a powerful statement in the DATA step DATA newdatasetname; SET olddatasetname;.. run;
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Today… Preparation for doing Assignment 1. Invoking methods overview. Conditionals and Loops. Winter 2016CMPE212 - Prof. McLeod1.
Online Programming| Online Training| Real Time Projects | Certifications |Online Classes| Corporate Training |Jobs| CONTACT US: STANSYS SOFTWARE SOLUTIONS.
Designed by Victor Help you improve MATRICES Let Maths take you Further… Know how to write a Matrix, Know what is Order of Matrices,
Name each of the following moon phases..
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 16 & 17 By Tasha Chapman, Oregon Health Authority.
Lecture 1 Gunjeet kaur Dronacharya group of institutions.
CSE 143 read: 12.5 Lecture 18: recursive backtracking.
Chapter 2 Writing Simple Programs
Data Structures and Algorithms
Sit-In Lab 1 Ob-CHESS-ion
CHAPTER 9: GAUSSIAN ELIMINATION.
CS100J Lecture 18 Previous Lecture Programming concepts This Lecture
Presented By: David Miller
CS100J Lecture 18 Previous Lecture Programming concepts This Lecture
Presentation transcript:

The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach Abstract 2. Heuristic Method 3. Identify Knight Moves 5. SAS Solution Knight’s Tour: A sequence of moves on a chess board such that a knight visits each square only once. Heuristic Solution: Always move the knight to an adjacent, unvisited square with minimal degree. – H.C. Warnsdorff a8  b6, c7 (Degree 2) c6  b8, d8, a7, e7, a5, e5, b4, e4 (Degree 8) Identify the number of possible moves from every square. Find a tour Move the knight to viable square Revise chess board Update knight moves data set Continue until completed tour Make sure the knight does not fall off the board The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach data knightmoves; array board{8,8} m11-m18 m21-m28 m31-m38 m41-m48 m51-m58 m61-m68 m71-m78 m81-m88; do r = 1 to 8; do c = 1 to 8; counter = 0; do step1 = -2,-1,1,2; do step2 = -2,-1,1,2; if (abs(step1) ne abs(step2)) then do; if 1 le (r+step1) le 8 and 1 le (c+step2) le 8 then counter+1; end; board{r,c} = counter; end; drop r c step1 step2 counter; run; %macro Warnsdorff; %do r = 1 %to 8; %do c = 1 %to 8; %end; %mend Warnsdorff; 4. Knight Moves Data Set 1. Knight Moves

7. Find Next Move 6. Find Knight’s Tour Discern valid step values (e.g. -2,1) Find valid row and column (Stay on the board) Find viable square (Unused square) Take next step. if abs(step1) ne abs(step2) then do; if ( 1 le (r+step1) le 8 ) and ( 1 le (c+step2) le 8 ) and board(r+step1,c+step2) eq. then do; if moves{r+step1,c+step2} lt pmoves then do; nxtr = r + step1; nxtc = c + step2; pmoves = moves{r+step1, c+step2}; end; data solution; retain r &r. c &c.; retain s11-s18 s21-s28 s31-s38 s41-s48 s51-s58 s61-s68 s71-s78 s81-s88; array board{8,8} s11-s18 s21-s28 s31-s38 s41-s48 s51-s58 s61-s68 s71-s78 s81-s88; array moves{8,8} m11-m18 m21-m28 m31-m38 m41-m48 m51-m58 m61-m68 m71-m78 m81-m88; set knightmoves; board{r,c} = 1; do position = 2 to 64; nxtr = 0; nxtc = 0; pmoves = 9; do step1 = -2,-1,1,2; do step2 = -2,-1,1,2; end; end; run; Update chess board Update knight moves data set if 1 le nxtr le 8 and 1 le nxtc le 8 then do; r = nxtr; c = nxtc; board{r,c} = position; do step1 = -2,-1,1,2; do step2 = -2,-1,1,2; if abs(step1) ne abs(step2) and (1 le (r+step1) le 8) and (1 le (c+step2) le 8) then moves{r+step1,c+step2}= moves{r+step1,c+step2}-1; end; 8. Update Metadata The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach

The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach 9. Update Metadata – Before and After The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach MOVES BOARD MOVES Before Knight a8 to c7 After Number of possible knight moves at position a8 decreased from 2 to 1. Create the macro variable SOLVED. Boolean expression assigns the values {0,1}. data _null_; array board{8,8} s11-s18 s21-s28 s31-s38 s41-s48 s51-s58 s61-s68 s71-s78 s81-s88; set solution; call symput(‘solved’ left(put(n(of board{*}) eq 64,1.))); run; 10. Completed Tour? %macro ShowBoard(dsn = solution, elements = s11-s18 s21-s28 s31-s38 s41-s48 s51-s58 s61-s68 s71-s78 s81-s88); data board(keep=c1-c8); array board{8,8} &elements.; array cols{8} c1-c8; set &dsn.; do r = 1 to 8; do c = 1 to 8; cols{c} = board{r,c}; end; output; end; run; 11. Display Chess Board %if %solved. %then %do; %ShowBoard(dsn = solution, elements = s11-s18 s21-s28 s31-s38 s41-s48 s51-s58 s61-s68 s71-s78 s81-s88, title = Chess Board -- Run #&run.); %end; 12. Display Chess Board The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach

The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach 13. Display Chess Board (cont.) The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach proc report data=board nowindows headskip; columns c1-c8; define c1 / display width=3 ''; define c2 / display width=3 ''; define c3 / display width=3 ''; define c4 / display width=3 ''; define c5 / display width=3 ''; define c6 / display width=3 ''; define c7 / display width=3 ''; define c8 / display width=3 ''; format c1-c8 best3.1; title2 "&title."; run; %mend ShowBoard; %ShowBoard Macro: Converts data set from 1 observation to 8 rows / 8 columns. Uses REPORT procedure to render the chess board. 15. Making a Wrong Turn 14. Display Chess Board – Knight’s Tour # Using First Instance of Using Last Instance of Minimal Degree Minimal Degree Tour #23 Tour # The Set Union of First & Last Instances of Minimal Degree produces a complete set of knight tours The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach

The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach Knight’s Tour #1 The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach Knight’s Tour # Knight’s Tour #2 Knight’s Tour # Knight’s Tour #5 Knight’s Tour # Corrected using first instance of minimal degree The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach

The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach Knight’s Tour #19 The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach Knight’s Tour # Corrected using last instance of minimal degree. Knight’s Tour #23 Knight’s Tour # Knight’s Tour #64 Thank you! Welcome to Dallas, Texas. Thanks to SAS Global Forum 2015 and Dataceutics, Inc. John R. Gerlach The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach The Knight’s Tour in Chess – Implementing a Heuristic Solution John R Gerlach