- Finish "throwing throwables", show them the program.
- Correction to `simple' hash hack (in slides now) -- wrap at end (++ top, -- bottom).
- Correction to series for insertion & selection sort: (also now in slides)
- Amounts to:

for n do

for 1, 2, 3, 4...n-1 do (average value (n-1)/2) - This is equiv to the arithmetic series (1+2+3+4+...n-1) == n*(n+1)/2

- n*(n+1)/2 = 1/2*n
^{2}+ 1/2*n which means its O(n^{2}) -- n^{2}dominates

- We'll start out by thinking about a simple game.
- Games aren't what intelligence was developed for.
- But they are a representation of the kinds of reasoning & competitions we do in social domains.
- Often used traditionally in AI, somewhat controversial now (more about this at the end.)
- Good intuition pumps.
- Tic-tac-toe (noughts & crosses)
- Initial board is empty.
- First player can choose one of 9 places to go.
- Next player can choose one of 8 places to go
- Game can't take more than 9 steps.
- Object is to get three characters in a row --- many games no one wins.
- Web pages with pictures: http://www.ics.uci.edu/~eppstein/180a/970417.html, http://www.gamasutra.com/features/20000626/brockington_pfv.htm

- Complexity is vaguely exponential!
- Think about chess -- that's really exponential...
- Most AI problems are in NP
- Non-polynomial --- essentially computationally intractable to find (best/optimal) solution.
- But if you do find solution, can prove it in polynomial time (this makes NP different from EXP).
- Worse class of problems is when you can't recognize when you've happened to find a solution!
- Empirically, many problems we work on seem similar
- How long would it have taken you to invent quick sort?
- How long did it take you to understand that it would work?
- The answer to question 1 might actually be shorter than you think, or sometimes even shorter than question 2, see section on expertise below.
- If a problem is polynomial or easier, can usually write a conventional algorithm to solve the problem.

- Depth first search looks all the way down a tree's branches until it finds a solution.

- start at the root
- look for your answer
- if not found
- for each child
- depth first search
- Breadth first search looks across the tree at one depth, and then on to the next level
- breadth-first-search (list) // initially list only contains the root
- for each thing in the list
- look for the answer
- if not found
- append item's children to the end of list
- Depth first search is faster, because it doesn't store as much state. But you can't know if you have the best answer (least amount of steps) unless you look at the whole tree!
- Breadth first search guarantees the shortest answer, but is impossible in cases like chess --- requires more memory than particles in the universe.
- But depth first has another problem --- may enter an infinite loop!
- e.g. in chess -- can move a rook back & forth forever.
- This is when you need AI --- when no algorithm can solve the problem.
- Someone who missed lecture asked for a diagram for this. Rather than draw one myself, here's one from Ralph Morelli's AI Lecture notes:
Consider the following graph:

**Depth First Search**examines the nodes in the following order:A, B, E, K, S, L, T, F, M, C, G, N, H, O, P, U, D, I, Q, R, S, T, U

**Breadth First Search**examines the nodes in the following order:A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U

- Want ways to prune the tree -- make there be less branches.

- If you are playing an opponent, assume that each player will avoid losing games, ignore those branches.
- This is called "mini-max search" because you alternately minimize
& maximize your own expected outcome as you go through the tree.

- Estimate the value of branches & go down the ones that look most profitable
- Estimates are based on heuristics, rules that are often but not always right.
- E.g. you might guess that the shortest way across town on the map is the fastest, but really the fastest way depends on traffic, width of streets, tourists, shops etc.
- In chess, a common heuristic is to count how many pieces you have left, giving extra value to more powerful pieces.
- A* search is kind of like breadth first search, but you keep sorting the list, & keep going down the shortest / cheapest path you've found so far.
- A*-search (list) // initially list only contains the root
- for the cheapest thing in the list
- check if you have the solution, if so use it

- take item off list, remembering the cost associated with it,
- estimate cost of all children, summing their cost with parent's cost.
- sort children into list
- If you can guarantee that your heuristic never underestimates the
cost of performing the action (overestimating is OK) then this will find
the optimal solution.

- A* search is used in almost all VR computer games for navigation: choosing how to get to a goal location.

- One way to solve the problem of combinatorics is to have the search run in parallel.
- Every time you have multiple options, have one thread take each option.
- Think of people exploring tunnels in Scooby Doo.

- If you could get enough threads, & you had some way to let all of them know when one of them found a solution, then you could turn all NP problems into P problems.
- Not something you can do on one PC -- threads share the same processor, no big win.
- Even massively parallel computers usually only have 1,000 processors, don't get you that far in chess.
- Solutions people are currently working on:
- Quantum computing :
- particles can be in many places at one time
- weird! but has really been done for a small number of bits.
- Biological computing:
- use genetics to create and & or gates in bacteria.
- Takes maybe 48 hours for one operation, BUT can be done billions of times in a single test tube.
- Again, people are really working on this (for example, Ron Weiss).
- Evolution / memetics:
- If a few members of a species or a culture find a good / winning solution, the entire species or culture may eventually adopt that solution.
- This works much faster in memetics (ideas) then genetics (requires waiting for children to grow up.)
- Trying to come up with good design rules is like memetics.

- This is why sometimes programmers can chance on the right answer to a question even sooner than they can understand how to solve the question.
- Languages like java are designed to give you a heavily pruned search space.
- Using good technique makes it likely you will find good answers!
- Using very limited search of known good strategies is the key to several other kinds of AI:
- Expert Systems
- Production Rule Systems (see ACT-R, Soar)

- Reactive AI (that's my web page on the subject!)

- A lot of what we do (with our brains as well as our computers) can be thought of as search.
- Games are a "toy domain", but can help us understand why search is hard, and how we might be solving other problems.
- Real brains probably solve many things in parallel, but they are still combating combinatorics.

2 March 2004