






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Today: Backtracking searches, game trees.
Coming Up: Graph Structures: DSIJ, Chapter 12
Public Service Announcement: The Student Advocate’s Office is ef- fectively a campus public defender—an executive, non-partisan office of the student government offering representation, help, and advice to any student or student group involved in a dispute with the University. For assistance with residency applications and appeals, financial aid ap- plications, withdrawals and enrollment, grade appeals, cheating accusa- tions, sexual assault, discrimination, and other University grievances, see their web page at advocate.berkeley.edu.
/** Append to PATH a sequence of knight moves starting at ROW, COL
boolean findPath (boolean[][] b, int row, int col, int endRow, int endCol, List path) { if (L.size () == 64) return isKnightMove (row, col, endRow, endCol); for (r, c = all possible moves from (row, col)) { if (! b[r][c]) { b[r][c] = true; // Mark the square path.add (new Move (r, c)); if (findPath (b, r, c, endRow, endCol, path)) return true; b[r][c] = false; // Backtrack out of the move. path.remove (path.size ()-1); } } return false; }
My move
Opponent’s move
My move
Opponent’s move
class TreeIterator extends Thread { Tree root; Mailbox r; TreeIterator (Tree T, Mailbox r) { this.root = T; this.dest = r; } public void run () { traverse (root); r.deposit (End marker); } void traverse (Tree t) { if (t == null) return; traverse (t.left); r.deposit (t.label); traverse (t.right); } }
void treeProcessor (Tree T) { Mailbox m = new QueuedMailbox (); new TreeIterator (T, m).start (); while (true) { Object x = m.receive (); if (x is end marker) break; do something with x; } }