# CS 1571: Homework 2

## Search, Constraints, Games

Assigned: October 2, 2017

Due: October 16, 2017

#### 1. Hill Climbing Search (25 pts)

Suppose you are in an initial state where you have a stack of alphabet blocks, where B is the bottom black, A is the top block, and the full order of the blocks from bottom to top is B, C, D, E, F, G, H, A. The goal state is to have an alphabetized stack, such that A is the bottom block and H is on the top (e.g., the full order is A, B, C, D, E, F, G, H). To get from one state to another, you can move a block off the top of a stack to either the table, or to the top of another stack.

Let heuristic function H1 count +N for every block that sits on a correct stack of N things, and count -N for every block that sits on an incorrect stack of N things. The goal state has the value +28, and the initial state has the value -28.

Let heuristic function H2 count +1 for every block that sits on the correct thing, and count -1 for every block that sits on an incorrect thing. The goal state has the value +8, and the inital state has the value +4.

Assume you are doing Hill Climbing Search. Explain which heuristic is better. HINT: You should only have to expand a few nodes to answer this question.

#### 2. Constraint Satisfaction Problems (50 pts)

Federal Express needs to deliver five packages a,b,c,d, and e at one of four times, 1,2,3, or 4. Let A represent the time at which a is delivered, B represent the time at which b is delivered, etc. The initial possible values for each delivery is the set {1, 2, 3, 4}. The following constraints need to be met:

(B ≠ 3) ^ (C ≠ 2) ^ (A ≠ B) ^ (B ≠ C) ^ (C < D) ^ (A = D)^ (E < A) ^ (E < B) ^ (E < C) ^ (E < D) ^ (B ≠ D)

(a) Apply backtracking search to the problem. Draw the search tree, labeling the nodes with current variable assignments and the order in which the nodes are visited. Consider the variables in the order A,B,C,D,E and the values in the order 1,2,3,4. Stop after 10 nodes have been added to the tree.

(b) Give an example where the use of each of the following would have been beneficial:

- Most constrained variable
- Most constraining variable
- Least constraining value

  (c) Apply forward-checking search to the problem. Use the order mentioned in part (a). Fill in the table with the appropriate values:

  Current assignment being considered | Domain A | Domain B | Domain C | Domain D | Domain E

  (d) Is there an example where the use of arc consistency would have been beneficial?

  #### 3. Adversarial Search (25 pts)

  Consider a sliding block puzzle with the following initial configuration:
  WWEBB
  1 2 3 4 5
  There are two white checkers belonging to player 1, two black checkers belonging to player 2, and an empty cell. The game ends when a player moves all of his checkers to the opposite side of the board. Player 1 moves first. If player 1 wins, 1 point is awarded to player 1 and -1 points are awarded to player 2 and vice versa. The legal moves for a player are:

- Move a tile to an adjacent empty cell
- Hop over one or two other tiles into an empty cell

  If a player cannot make a move, the turn is forfeited and the other player may make another move. Player 1 can only move to the right and player 2 can only move to the left.

  (a) Draw the complete game tree with the following conventions:

- Represent each state as a pair (x1x2, y1y2), where each xi is a position with a white checker and each yi is a position with a black checker (with the numbers used in the diagram above). Label the edges of the game tree with the player to makes the move.
- Put terminal states in a thick, square box with the utility function value for player 1 inside.

  (b) Now label each node with its backed-up minimax value for player 1.

  (c) Give a solution path that rational players would play.