a fast thinking connect four machine!

21
A Fast Thinking Connect Four Machine! 6.846 Final Project Presented by Tina

Upload: jase

Post on 22-Feb-2016

49 views

Category:

Documents


0 download

DESCRIPTION

A Fast Thinking Connect Four Machine!. 6.846 Final Project Presented by Tina Wen. Goal. Write a fast connect k game on m by n grid from scratch. Small m and n: exhaustive search. n. Big m and n: search to a good depth. k. m. Basic Idea. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: A Fast Thinking Connect Four Machine!

A Fast Thinking Connect Four Machine!

6.846 Final ProjectPresented by Tina Wen

Page 2: A Fast Thinking Connect Four Machine!

GoalWrite a fast connect k game on m by n grid from scratch

m

nk

Small m and n: exhaustive search

Big m and n: search to a good depth

Page 3: A Fast Thinking Connect Four Machine!

Basic Idea

Negamax search (recursively call expand and combine)

ME: MAX

OPPO: MIN

2 4 1 5 4 2 1 7 9 2 0 3 4 5 2 1 3 5 7 8 4 6 5 4 3 2 1

ROOT

OPPO: MIN

4

4 5 9 3 5 5 8 6 3

4 33

ME: MAX

Page 4: A Fast Thinking Connect Four Machine!

Approaches1. Sequential exhaustive search

2. One dynamic queue in shared memory (TSP)

3. Master-Slave Message Passing

Tile 0

tile1

tile2

tile3

tile4

3

5 2

6

0

COMBINE

Page 5: A Fast Thinking Connect Four Machine!

Approaches4. Master-Slave Individually allocated shared memory

(no mutex)tile0 Where to write to to distribute work?

Where to get the results?

tile1

From which tile Ready? Result

1 0

2 0

Where to get work

Ready? work

0

Where to return work?

To which tile Pointer

1

2

tile2Where to get work

Ready? work

0

Where to return work?

Page 6: A Fast Thinking Connect Four Machine!

Heuristic• Search for 4 in a row in 4 different orientations

• Count only rows that consist of one color and space (either red or black == 0)

Out of 4: # for black

# for red

• If one color has 4 in a row, then score = (infinity + spaces)

Else score +=

If we are red

2 2

Page 7: A Fast Thinking Connect Four Machine!

score

9 + 4 + 1 = 14

9 + 4 + 4 = 17

9 + 4 +1 = 14

1234

score += 2 2

9 + 9 + 4 = 22

Heuristic

Page 8: A Fast Thinking Connect Four Machine!

Performance Comparison (connect 3)Performance of connect 3 on 4x4 grid

Num

ber o

f cy

cles

Number of processors (P)Purple: sequential no pruning

Page 9: A Fast Thinking Connect Four Machine!

Performance Comparison (connect 3)Performance of connect 3 on 4x4 grid

Num

ber o

f cy

cles

Number of processors (P)

0.83

Purple: sequential no pruningRed: dynamic queue

Page 10: A Fast Thinking Connect Four Machine!

Performance Comparison (connect 3)Performance of connect 3 on 4x4 grid

Num

ber o

f cy

cles

Number of processors (P)Purple: sequential no pruningUpper Red: dynamic queueLower Red: message passing

Page 11: A Fast Thinking Connect Four Machine!

Performance of connect 3 on 4x4 gridN

umbe

r of

cycl

es

Number of processors (P)

Performance Comparison (connect 3)

5.05

0.83

Purple: sequential no pruningUpper Red: dynamic queueLower Red: message passingBlue: individually allocated shared memory

Page 12: A Fast Thinking Connect Four Machine!

Performance of connect 4 on 4x4 gridN

umbe

r of

cycl

es

Number of processors (P)

Performance Comparison (connect 4)

Purple: sequential no pruning

Page 13: A Fast Thinking Connect Four Machine!

Performance of connect 4 on 4x4 gridN

umbe

r of

cycl

es

Number of processors (P)

Performance Comparison (connect 4)

1.15

Purple: sequential no pruningRed: dynamic queue

Page 14: A Fast Thinking Connect Four Machine!

Performance of connect 4 on 4x4 gridN

umbe

r of

cycl

es

Number of processors (P)

Performance Comparison (connect 4)

9.59

1.15

Purple: sequential no pruningUpper Red: dynamic queueLower Red: message passing

Page 15: A Fast Thinking Connect Four Machine!

Performance of connect 4 on 4x4 gridN

umbe

r of

cycl

es

Performance Comparison (connect 4)

Number of processors (P)Purple: sequential no pruningUpper Red: dynamic queueLower Red: message passingBlue: individually allocated shared memory

Page 16: A Fast Thinking Connect Four Machine!

Performance of connect 4 on 4x4 gridN

umbe

r of

cycl

es

Number of processors (P)

Performance Comparison (connect 4)

9.87

9.59

Blue: individually allocated shared memoryRed: message passing

Page 17: A Fast Thinking Connect Four Machine!

Load Balancing

Number of processors (P)

Load

bal

anci

ng sp

read

Better balanced

Worse balanced

90 billion cycles

177 billion cycles

114 billion cycles

4 children7 children

Page 18: A Fast Thinking Connect Four Machine!

Sequential Pruning

2

5

ME: MAX

OPPO: MIN

ME: MAX

<=2

>=5

Number of cycles Sequential pruning Individually allocated shared memory (min)

3x3 connect 3 0.157 billion 3 billion

3x3 connect 4 0.162 billion 23 billion

Page 19: A Fast Thinking Connect Four Machine!

Final Version

Tile 0 Other tiles: sequential pruning

Pros: Take advantage of both dynamic queue for load balancing and pruningCons: Can’t do pruning between processors

Number of cycles Sequential pruning Individually allocated shared memory (min)

Final Version (min)

3x3 connect 3 0.157 billion 3 billion (P=50) 0.069 billion (P=20)

3x3 connect 4 0.162 billion 23 billion (P=50) 0.14 billion(P=20)

Page 20: A Fast Thinking Connect Four Machine!

Interactive Mode

Page 21: A Fast Thinking Connect Four Machine!

Conclusion

My connect four• searches fast • has a good heuristic

By using • Pruning • Master slave structure• Individually allocated shared memory

COME TRY IT!