Appendix A
Source for the Eight-Queens Puzzle
This appendix gives the full programs for the eight-queens puzzle discussed in Chapter 6.
A.1 ⊡ Eight-Queens in Apple Object Pascal
(* Eight-Queens Puzzle in Object Pascal Written by Tim Budd, Oregon State University, 1996 *) Program EightQueen; type Queen = object (* data fields *) row : integer; column : integer; neighbor : Queen; (* initiaiization *) procedure initialize (col : integer; ngh : Queen); (* operations *) function canAttack (testRow, testColumn : integer) : boolean; function findSolution : boolean; function advance : boolean; procedure print; end; var neighbor, lastQueen : Queen; i : integer; procedure Queen.initialize (col : integer; ngh : Queen); begin ...
Get An Introduction to Object-Oriented Programming, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.