Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

64
Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    230
  • download

    2

Transcript of Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Page 1: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5

Page 2: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Strategy

• We choose a greedy algorithm strategy that had a focus on defence as opposed to offense.

• We felt that by focussing on defence and blocking moves that are considered threats, a slow steady offense would get five in a row more efficiently.

Page 3: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Application

• To implement this, we view an 11x11 grid with the center square being the opponent’s last move. We then scan the grid and assign a “danger priority” to each space based on its proximity to other moves the opponent has made. The highest priority is then made into a move.

Page 4: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Program in Use

• In application, our program begins well but its implementation does not always convey the proper priority for a few spaces on the grid, mainly in diagonal lines. This flaw often lead to losses.

Page 5: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Best Move

• Often, especially in the case of horizontal or vertical lines, our program will let them be created until it views 3 in a row, then block it successively on both sides, preventing a win.

X X XOXO

Page 6: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

A TIE IS NOT A LOSS

Paul Adamiak T02

Aruna Meiyeppen T01

Page 7: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Strategy

• Check to see if we can win• Check to see if opponent can win• Check if we can make 4 in a row• Check if opponent can make 4 in a row• Make next best move

root

…Possible moves

Page 8: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Strategy Success

• The strategy didn’t work as well as hoped– Able to always beat a human user, rarely another

program• Defensive move is determined by a linear search of the

board.– Handles a random threat which may not be the most

threatening

Chosen threat

Most threatening

Page 9: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Favourite Move

• Filling space in between two threats

Fill space

Page 10: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

CPSC335 – Assignment 5

By:John Stuart

Zach High-Leggett

Tutorial #1

Page 11: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Strategy:

Our strategy was a greedy algorithm which checks the board to see whether the best case scenario (being able to win) or the worst case scenario (the opponent is about to win). If either of these exist, the algorithm plays the winning move, or blocks the opponent.Otherwise, the algorithm just tries to form a line of five squares with a hierarchy of which types of moves have precedence.

Page 12: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Successes and Failures

Successes: We won a single game, wherein we got 4 in a row, then were blocked, blocked our opponent's 4-in-a-row, then got five in a row.. Woot.

Failures, Epic: We have not actually managed to win more than a single game (not including our opponent's disconnecting from the server).

Page 13: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Our Best Move

Page 14: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

CPSC 335 -- Assignment 5: Tic-Tac-Toe

Jonathan HudsonTutorial 02

Page 15: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Strategy

Implemented a alpha-beta tree with pruning Reasons

Supposed to allow lengthy look ahead Which should give an advantage to decision making Evaluation of both best opponent and current players own

moves Evaluation of board is based upon number

of pieces in a five row without obstructing enemy pieces multiplied by weightings Sum of x1's*w1+x2's*w2+x3's*w3+x4's*w4+x5's*w5 Idea was that with lookahead can determine where

own player and enemy player has future wins possible

Page 16: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Performance Both the 5 second limit and length of time to evaluate a

board severly hampered strategy 5 seconds limited the depth of the tree such that the lookahead depth

of tree was 2 Attempts to hash evaluation values to increase depth failed since

needed custom hash table to keep them unique, (was able to hash and store but to many collisions such that incorrect evals were being returned for later queries making search control dumber resulting in many losses Monday on failed attempt)

Even with only the adjacent moves possibilities for a board being evaluated the longer a game runs the more states for the tree and as a result the tree starts to time out before checking all solutions

Greedy strategies can beat it since they can more completely evaluate a board, rather than the tree which loses a lot of time evaluating unecessary options and as a result tree didn't get to use its lookahead advantage in general, which made it as good as a mediocre greedy strategy (over 50% time spent evaluating multiple boards – easily improvable with an efficient precalculation of board evals and hash storage of them)

Page 17: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Best Move

Not easy to find a best move as all decisions are made by the algorithm there is no hard-coded human intelligence provided

The most obvious best move I guess is a result of the lookahead ability

Without some special evaluation of the board lookahead determines place to block beneficial to future moves

Page 18: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

CPSC 335 A5 PresentationCPSC 335 A5 PresentationTeam 12

Vladislav Lavrovsky and Kent ThachekTeam 12

Vladislav Lavrovsky and Kent Thachek

Page 19: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

=

StrategyStrategy

32x32 Board2^(32^2) = 2^1024 =

No TREES!

(2^1024)*16*1024 = (2^1024)*(2^14) = 2^10382^1038 / 2^40 (terabytes)= Almost Infinity

How to prune????

101,803,785,120,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000 Terabytes of States!

Greedy Algorithm With Heuristic Search

Why?

Because there is a very large game-space.

Page 20: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

StrategyStrategy

Do not lose!Games are won and lost in a 5x5 window!1. Look at all subsets of windows on the board.2. Score each axis (12 in total) for each player.3. Compare all max scores in all reference frames for both players.4. Logic for precedence of moves.

Page 21: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

StrategyStrategy

2,0

0,0

0,0

0,0

0,00,10,04,00,0

0,1

0,0

0,1

786

.

Page 22: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

StrategyStrategy

.

1

Win!

Page 23: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Sweet Moves!Sweet Moves!

. . . . . . . . . . . . . . . . . . .

. . . . . . . . . 1 . . . 1 . . . . . . . . . . . . . . . 1 . 1 2 . . . . . . . . . . . . . . . 1 1 . 2 . . . . . . . . . . . . . . . . 1 2 2 2 1 . . . . . . . . . . . . . . . . 2 2 1 . . . . . . . . . . . . . . . . 1 . . 2 . . . . . . . . . . . . . . . . . . . 2 2 . . . . . . . . . . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . 1 . . . . . . . . . . .

. . . . . . . . 1 . 1 . . . . . . . . .

. . . . . . . 1 1 . 2 . . . . . . . . .

. . . . . . . 1 2 2 2 1 . . . . . . . .

. . . . . . . . 2 2 1 . . . . . . . . .

. . . . . . . 1 . . 2 . . . . . . . . .

. . . . . . . . . . 2 2 . . . . . . . .

. . . . . . . . . . . . 1 . . . . . . .

. . . . . . . . . . . . . . . . . . . .

Game ~780VS Team 13

13 wastesa move!Shazam!

Page 24: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

ImprovementsImprovements

B

A

Move A

Move B

ScoreA = 3ScoreB = 3

Additive ScoreA = 6Additive ScoreB = 3

Move at A!

A is a more optimalmove, blocks fork!But scores are equal so both moves are possible.

Page 25: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Cpsc 335 Assignment 5

David Teierle, Mark Dryden

Page 26: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Game strategy

We decided to use a greedy method for choosing our moves. It allows us to efficiently determine the state of the game board and make a move accordingly. The idea behind this method is a scoring of sorts.

We run both the defensive and offensive algorithms at the same time, and whichever one returns the

greatest score is the move we make.

Page 27: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

The plan

David determined that the game could be won rather easily by creating a condition where two lines

converge. This would make 2 opportunities to win, while the opponent can only block one of these

opportunities. Our algorithm was designed based on this idea.

As such, our defence only starts when the opponent has 3 or more in a row, at that point we block their

attempts.

Page 28: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Scoring method

Free move: We can make a 3 in a

row or a 4 in a row Double free:

We can make two 3 or 4 in a row lines with one move

Offence 1 in row = 1 2 in row = 2 3 in row = 6 Free move = 7 Double free = 8 Win right now = 10

Defence Under 3 in a row

score = 0 3 in a row = 5 3 in a row that we

have already blocked = 0

Block now, or loose the game = 9

Page 29: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Defending against our algorithm

In theory the only way to defend against our algorithm would be to block every single move, which means that the opponent would have no

offence. This would surly lead to a draw, at which point the player who made the first move would

win. This results in a worst case win to lose ratio of 50%, which is not that bad.

Page 30: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Results

Server got boned before we could finish...... We didn't really have any best move!All our moves were pure gold...

Page 31: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

CPSC 335Assignment #5

Dave Robinson (T01)Daniel Drzimotta (T02)

Page 32: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Strategy Description

•Utility Function

- Iterates through all of our symbols placed

- Checks for both runs and forks

•Min-Max Tree

- Recursively build up a game tree with a max depth of 4

Page 33: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Strategy Evaluation• Its hard to evaluate a not so functioning algorithm

• The min-max algorithm is considered the standard method for such 2 player games. Where it is limited, is the amount of moves ahead you can search. Using alpha beta pruning or negMax would of allowed us to create a deeper tree to search through without increasing the number to nodes to the point where the sun would explode before we found a move.

• Another place where we could of improved is increasing the number of possible moves we found for each node on the tree. Currently the program would take the opponents move and then find all the moves that were up to 2 spaces from it. This was another way to reduce the amount of nodes that were needed to search through. In theory this would of allowed a greater depth then finding all moves in a 32x32 playing board.

Page 34: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Best Move

Page 35: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

CPSC 335

Jaeyun NohMichael Bierkos

Tutorial 2

Page 36: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Strategy used and why

• Greedy Algorithm!• No time, too many assignments. Exam

tomorrow• Because we hate tracing bugs in trees…

Page 37: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Did the strategy work?

• Well,

Page 38: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Show your best move

• Well…

Page 39: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Greedy Algorithm1 1 1

2 2 2

3 3 3

4 4 4

5 5 5

1 2 3 4 5 X 5 4 3 2 1

5 5 5

4 4 4

3 3 3

2 2 2

1 1 1

Page 40: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Greedy Algorithm1 1 1

2 2 2

3 3 3

4 4 4

5 5 5

1 2 3 4 5 X O

5 5 5

4 4 4

3 3 3

2 2 2

1 1 1

Page 41: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Greedy Algorithm1 1 1

2 3 2

3 6 3

4 8 4

5 10 5

1 2 3 4 5 X O

5 X 5

4 5 10 5 4

3 4 8 4 3

2 3 6 3 2

1 2 3 2 1

1 1 1

Page 42: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Greedy Algorithm1 1 1

2 2 2

3 3 3

4 4 4

5 5 5

X O 5 4 3 2 1

X 5 5

4 4

3 3

2 2

1 1

Page 43: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Greedy Algorithm1 1 1 1 1 1

2 2 3 2 2 2

3 3 6 3 3 3

4 4 8 4 4 4

5 15 10 5

1 2 3 4 5 X O 5 4 3 2 1

5 X 10 5

4 5 10 9 4 4

3 4 8 3 4 3 3

2 3 6 2 3 2 2

1 2 3 1 2 1 1

1 1 1

Page 44: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Greedy Algorithm

O

X O

X

Page 45: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

CPSC 335

Assignment #5

Chad Walpole

Jeff Salcedo

T02

Page 46: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Strategy

X

O

X X

X X O

X O

O

X

X is our Last Move

Row Right: returns -1

Diagonal RD: returns 0

Col Down: returns -1

Diagonal LD: returns 1

Row Left: returns 1

Diagonal LU: returns -1

Col Up: returns 1

Diagonal RU: returns 2

Mark Next Spot:

Diagonal Right UP

Page 47: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Placement

X

X X

X X X

X X X X

X O X X X

X O X X X

Move 1:

Move 2:

Move 3:

Move 4:

Blocked!

If we get blocked then we move our marker (X) to our last move (X).

And continue marking to the right.

Page 48: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Strategy Performance

• Worked well because we always leave a gap between our marks.

• Finally got it working LAST NIGHT!

• No animation….sorry

Page 49: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Jill AinsworthTim Green

Page 50: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Our StrategyGreedy AlgorithmOnly those spots that are adjacent to a move

that has already been madeEvaluate how good each of these moves isChoose the best oneIf there is more than one “best move” choose

one of the best ones randomly

Page 51: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Did it work?Umm, not so much. In all of our test cases, it worked well, but in

practice, our strategy failed to perform. Solution: we should have done more testing. Our test cases did not cover a broad enough

base of possible game states. Integration testing was a problem

Against others: mostly lossesAgainst ourselves: 100% win!

Page 52: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Our best moveDue to connection issues, we could not get

sufficient actual data, so we look at theoretical stuff.

How we evaluate a move:For each potential move, count nearby markers

and potential line-length in each direction for each player

Combine results into single score for that position

Make move that scores highest

Page 53: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Evaluating a move...

Page 54: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Evaluating a move...

Page 55: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Evaluating a move...

5,1

9,19,1

1,0

Page 56: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Evaluating a move...

5,1

5,05,09,4

Page 57: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Evaluating a move...

Page 58: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Evaluating a move...

Page 59: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Our best moveDue to connection issues, we could not get

sufficient actual data, so we look at theoretical stuff.

How we evaluate a move:For each potential move, count nearby markers

and potential line-length in each direction for each player

Combine results into single score for that position

Make move that scores highest

Page 60: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Steven LangeShawn FreemanApril 18, 2008Tutorial 1

Page 61: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Strategy

Our algorithm is a greedy algorithm that calculates for each square the utility value it could provide to each player.

It then adjusts the choices based on a level of aggression so that it does not prioritize defense when it can easily win.

The algorithm uses an iterative approach as a recursive approach would slow it down due to the overhead that recursion incurs.

Page 62: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Results

Our greedy algorithm was greedier than we expected.

We expected to lose more often against anyone who was using a depth first search.

Our algorithm made faster decisions than we expected.

Overall, we did better than expected.

Page 63: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Animated

Final

Best Move

Page 64: Ravneet Grewal & Joe Strathern CPSC 335 Assignment 5.

Questions?