WITH Useful; WITH WRITEBOARD; WITH ada.text_io; PROCEDURE addQueen (R : IN OUT Useful.ZeroToEight; UpF : IN OUT Useful.UpFree; DownF : IN OUT Useful.DownFree; FreeC : IN OUT Useful.ColumnFree; Col : IN OUT Useful.Columns; Tried : IN OUT integer; -- queens placed Tested: IN OUT integer; -- positions examined solutions : IN OUT ada.text_io.file_type ) IS BEGIN -- move forward a row at a time R := R + 1; FOR C IN Useful.OneToEight LOOP -- check each column position Tested := Tested+ 1; -- count positions checked IF FreeC(C) AND UpF(R+C) AND DownF(R-C) THEN -- not takable -- place queen Col(R) := C; FreeC(C) := false; UpF(R+C) := false; DownF(R-C) := false; Tried := Tried + 1; -- update count of queens placed IF R = 8 THEN -- found a solution, print it Writeboard (Placed => Tried, Examined => Tested, Positions => Col, outfile => solutions); ELSE -- add another queen ADDQueen (R => R, UpF => UpF, DownF => DownF, FreeC => FreeC, Col => Col, Tried => Tried, Tested => Tested, Solutions => Solutions); END IF; -- remove last queen placed FreeC(C) := true; UpF(R+C) := true; DownF(R-C) := true; END IF; END LOOP; R := R - 1; -- back up a row END AddQueen;