Algorithms and Data Structures
Algorithms and Data Structures
Algorithms and Data Structures
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
N.Wirth. <strong>Algorithms</strong> <strong>and</strong> <strong>Data</strong> <strong>Structures</strong>. Oberon version 111<br />
procedure TryNextMove. On a board that is infinite in all directions, each position x, y has a number<br />
c<strong>and</strong>idate moves u, v, which at this point there is no need to specify (see fig. 3.7). The predicate to choose<br />
an acceptable move can be expressed as the logical conjunction of the conditions that the new field lies on<br />
the board, i.e. 0 ≤ u < n <strong>and</strong> 0 ≤ v < n, <strong>and</strong> that it had not been visited previously, i.e., h uv = 0. One further<br />
detail must not be overlooked: A variable h uv does exist only if both u <strong>and</strong> v lie within the index range 0 ...<br />
n-1. Consequently, the Boolean expression, substituted for acceptable in the general schema, is valid only<br />
if its first four constituent terms are true. It is therefore relevant that the term h uv = 0 appears last. As a<br />
result, the selection of the next acceptable c<strong>and</strong>idate move is expressed by the familiar scheme of linear<br />
search (only formulated now in terms of the repeat loop instead of while, which in this case is possible <strong>and</strong><br />
convenient). To signal that there are now further c<strong>and</strong>idate moves, the variable eos can be used. Let us<br />
formulate the operation as a procedure Next, explicitly specifying the relevant variables as parameters:<br />
PROCEDURE Next (VAR eos: BOOLEAN; VAR u, v: INTEGER);<br />
BEGIN<br />
(*~eos*)<br />
REPEAT select the next c<strong>and</strong>idate move u, v<br />
UNTIL (no more c<strong>and</strong>idates) OR<br />
((0