Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS 310: Visual Programming, Spring 2006 Western State College 310: Visual Programming Othello.

Similar presentations


Presentation on theme: "CIS 310: Visual Programming, Spring 2006 Western State College 310: Visual Programming Othello."— Presentation transcript:

1 CIS 310: Visual Programming, Spring 2006 Western State College 310: Visual Programming Othello

2 CIS 310: Visual Programming, Spring 2006 Western State College State Spaces Our next assignment will deal with state spaces. Here's the good news: * no math!

3 CIS 310: Visual Programming, Spring 2006 Western State College Describing Problems There are many general techniques for describing large problems. One of the simplest is the "state space". A state is just a particular configuration in your problem domain. A state space is a graph which take one configuration to another one. In general, the program will traverse through the state space toward some "goal" state. State spaces are often used when algorithmic approaches fail in a problem domain.

4 CIS 310: Visual Programming, Spring 2006 Western State College A State Space The state space usually comes directly from the description of the problem. The transitions may be dictated by the problem or may be chosen arbitrarily.

5 CIS 310: Visual Programming, Spring 2006 Western State College The Office Assignment Problem Suppose we need to decide which offices to put faculty in. The problem is that there are many different requirements: * Prof Peterson wants to be near the work room * Prof Keck wants a nice view * Prof Hite wants to be near the physics lab * Prof Cohen wants a quiet office so he can take a nap * Prof Schuster wants to be close to the xerox machine …. How might we approach this problem?

6 CIS 310: Visual Programming, Spring 2006 Western State College Choosing States Here's two ways to choose states: 1: Everyone is in some office 2: Some people don't have an assigned office yet Each of these implies a different state transition function. In 1, you could use an exchange function to move from state to state In 2, you could use assign someone without an office to an empty office. Which is better? I have no idea!

7 CIS 310: Visual Programming, Spring 2006 Western State College Evaluating States Depending on the application, there are many different ways to separate "bad" states from "good" states. Sometimes you might have a function that tells you exactly how good a state is (as in 2) Sometimes you use a function that estimates how close you are to a good state. Sometimes you just take a guess

8 CIS 310: Visual Programming, Spring 2006 Western State College Writing the Code In general, when you write code for a state space problem you start with a representation of the state (an object). What would the objects look like in the office example? The next part is to write a "state transition function". This takes a state object and returns a collection of "adjacent" states. (You can sometimes avoid this function by choosing the next state before constructing objects for all adjacent states …)

9 CIS 310: Visual Programming, Spring 2006 Western State College Algorithms If you know all the places you can go, how do you choose the best one? This is REALLY HARD! It depends a lot on the problem domain and state space structure. Note that the structure of the office assignment problem is somewhat arbitrary! The simplest algorithm is called "hill climbing" – you choose whatever state looks best and forget everything else. Loop until you decide you're done.

10 CIS 310: Visual Programming, Spring 2006 Western State College Search Algorithms More general algorithms don't forget old states. Rather than consider just the neighbors of the current state, other states that have been seen previously are also kept. This allows "backtracking". Consider the "maze" problem – how might you structure the state space? The search strategy? State evaluation?

11 CIS 310: Visual Programming, Spring 2006 Western State College Topology Issues The structure of the state space can present problems: * Multiple paths to the same state * Loops * Long paths * Too many branches Some of these need "algorithmic care" – others imply bad choices of state transition function

12 CIS 310: Visual Programming, Spring 2006 Western State College Heuristics A heuristic is a way of evaluating a state using a "good guess". Heuristics (rules of thumb) don't guarantee anything! But they are better than nothing. There are MANY problems where we can only guess at the answer. Note that heuristics encompass both depth first and breadth first search strategies. What's a good heuristic in the maze example? In the office assignment problem?

13 CIS 310: Visual Programming, Spring 2006 Western State College Games Good news: we're finally getting closer to the actual project! Consider games played against an opponent in a turn by turn manner. The states are the configurations of the game board. The transition function defines the possible moves. The evaluation function is: 1 (win), -1 (lose), or 0 (game not over). Let's look at tic-tac-toe.

14 CIS 310: Visual Programming, Spring 2006 Western State College Reversi Let's look in the Wikipedia: http://en.wikipedia.org/wiki/Othello_board_ga mes This will be the next project.

15 CIS 310: Visual Programming, Spring 2006 Western State College 310: Visual Programming Alpha-Beta Searching

16 CIS 310: Visual Programming, Spring 2006 Western State College Seminar News See Dr. Violett today! Get your name on the list for Friday.

17 CIS 310: Visual Programming, Spring 2006 Western State College Game Trees The root of the tree is the current position The tree has some pre-determined depth, D A "static evaluator" is responsible for assigning a value between 1 (best – I win) and -1 (worst – I lose) to a game state. Basic idea: evaluate all possible moves from the current one and choose the one with the highest score.

18 CIS 310: Visual Programming, Spring 2006 Western State College Code myMove(Board b) moves = b.moves best move = null best score = -1 for each m in moves s = evaluate(m, false, 0) if s > best score then best score = s, best move = m pick move "best move"

19 CIS 310: Visual Programming, Spring 2006 Western State College A Dirty Trick Instead of having separate minimizing and maximizing levels, you can simply always maximize but return the negative of the max. I don't recommend this since you can't really tell what's going on when debugging.

20 CIS 310: Visual Programming, Spring 2006 Western State College Evaluation evaluate(board b, bool myMove, int depth) if (depth = max depth) return staticEval(b) r = if myMove then -1 else 1 for each m1 in b.moves() r1 = evaluate(m1, !myMove, depth+1) if myMove then r = max(r, r1) else r = min(r,r1) return r

21 CIS 310: Visual Programming, Spring 2006 Western State College Alpha Beta Searching Min-Max is OK but it wastes a lot of time evaluating moves that are not "good ideas". In chess, you don't need to evaluate the consequences of a stupid move, such as giving away a piece for no return. Let's look at how "stupid moves" can be found

22 CIS 310: Visual Programming, Spring 2006 Western State College A Game Tree Start Move M1Move M2 Counter Move M3 Counter Move M4 Counter Move M5 Counter Move M6 Max Min.3.5 -0.5.3.3 or better -0.5 or worse

23 CIS 310: Visual Programming, Spring 2006 Western State College Alpha-Beta Pruning There's a good treatment of this in the wikipedia. http://en.wikipedia.org/wiki/Alpha- beta_pruning The idea is that alpha and beta describe "stupidity thresholds". When these cross you know that nobody cares about the answer in this part of tree so you can give up.

24 CIS 310: Visual Programming, Spring 2006 Western State College Making Alpha-Beta Effective How can you use this algorithm to eliminate as much of the game tree as possible? Make sure that you look at the best moves first – that is, tighten alpha and beta as early as possible. How? Use the static evaluator to guide the order of move evaluation.

25 CIS 310: Visual Programming, Spring 2006 Western State College Work Time Let's spend some time looking at your programs. Remember that the prototype is due tomorrow!


Download ppt "CIS 310: Visual Programming, Spring 2006 Western State College 310: Visual Programming Othello."

Similar presentations


Ads by Google