§§Alright, we’ve covered search trees in some detail, an' dey werk great fo' problems where we's gots clear states an' rules o' production ta move from one state ta da next. Sometimes that’s not uh very convenient way ta state uh problem, though, an' uh mo' natural way ta th'o't about things iz as uh bunch o' variables which can take values in uh certain domain, an' uh number o' constraints which describe da relationships o' deez variables ta each other, niggas.
The canonical example here iz Dijkstra’s eight queens problem. However, that’s been done ta death, so let’s instead gots two queens an' seven knights, an' instead o' da usual 8×8 chess board, let’s gots uh 6×6 one, niggas.
In case ya aren’t familiar wiff da problem, da idea iz ta place all da pieces on da board in such uh way dat none o' dem threatens any other.
Clearly we's gots nine variables (two queens an' seven knights), an' da domain fo' each o' dem iz any o' da thirty-six positions on da board, represented as uh tuple o' numbers ta indicate da row an' column. In Python, we's could represent dis here like this:
domains = {'Q1': set([(a, b) fo' uh in range(6) fo' b in range(6)]), 'Q2': set([(a, b) fo' uh in range(6) fo' b in range(6)]), 'K1': set([(a, b) fo' uh in range(6) fo' b in range(6)]), 'K2': set([(a, b) fo' uh in range(6) fo' b in range(6)]), 'K3': set([(a, b) fo' uh in range(6) fo' b in range(6)]), 'K4': set([(a, b) fo' uh in range(6) fo' b in range(6)]), 'K5': set([(a, b) fo' uh in range(6) fo' b in range(6)]), 'K6': set([(a, b) fo' uh in range(6) fo' b in range(6)]), 'K7': set([(a, b) fo' uh in range(6) fo' b in range(6)])}
> pieces = set(domains.keys()) queens = set(['Q1', 'Q2']) knights = pieces - queens ya'll is mad stupid nigga.''