C# Project - Chair of Software...

24
C# Project Assignment 1

Transcript of C# Project - Chair of Software...

C# Project

Assignment 1

Outline

Overview

of Chess

The Forsyth

notation

Requirements

of

the assignment

Computing the

next states

Evaluation

Function

MinMax

Conclusion

Questions?

Overview of Chess

tMvWlVmTOoOoOoOo+ + + +

+ + + + + + + +

+ + + + pPpPpPpPRnBqKbNr

Goal: checkmate your opponent's King

� Board: 8x8 squares

� Two players: White, Black

� 32 pieces (16w, 16b)

� ¦ Rock

� n Knight

� ¥ Bishop

� £ Queen

� ¢ King

� § Pawn

The Pawn

tMvWlVmTOoOoOoOo+ + + +

+ + + + + + + +

+ + + + pPpPpPpP

RnBqKbNr

+*+*+*+*+*+*P*+*+*+*

+*+*+*VoO*+*P*+*+*+*

Normal Move AttackInitial Move

+*+*+*+p+*+*+*+*+*+*

+*+*+*PoO*+*+*+*+*+*

The Rock

W + + + + + + + + + + +

+ + + + + + + +

+r+ +n+v+ + + +

+ + + +

R + + + + + + + + + + +

+ + + + + + + +

+ + +n+v+ + + +

+ + + +

The Knight

+ + + + + + + + + + + +

+ + V + + +o+ +

+ + +n+v+ + + +

+ + + +

+ + + + + + + + + + + +

+ + N + + +o+ +

+ + + +v+ + + +

+ + + +

The Bishop

+ + + + + + + + + + + +

+ + B + + + + +

+ + + +O + + +

+ + + +

+ + + + + + + + + + + +

+ + + + + + + +

+ + + +B + + +

+ + + +

The Queen

+ + + + + + + + + + + +

+ + Q + + + + +

+ + + ++ + + +

+ + + +

The King

+ + + + + + + + + + + +

+ + K + + + + +

+ + + ++ + + +

+ + + +

Goal of Chess: checkmate

+ + + + +l+ + + + +p+ +

+ + + + + +v+ O

+ N + Op+ + + K

T + + +

The Forsyth notation

� ¦ r

�n n

�¥ b

�£ q

�¢ k

� § p

+ + + + +l+ + + + +p+ +

+ + + + + +v+ O

+ N + Op+ + + K

T + + +

8;1K6;

4p3;8;

4B2P;

2n3Pp;7k;

R7.

Requirements of the assignment

Forsyth

Previous StateForsyth

Next StateYour Tool

• Play for the whites

• Legal Move

• MinMax

• Computation time reasonable

Recommended Model for Chess

+ + + + +l+ + + + +p+ +

+ + + + + +v+ O

+ N + Op+ + + K

+ + + +

State of the game

Next-State Computation

+ + + + +l+ + + + +p+ +

+ + + + + +v+ O

+ N + Op+ + + +

+ + K +

+ + + + +l+ + + + +p+ +

+ + + + + +n+ O

+ + + Op+ + + +

+ + K +

+ + + + +l+ + + + +p+ +

+ + + + + +n+ O

+ + + Op+ + + +

+ + K +

+ + + + +l+ + + + +p+ +

+ + + + + +n+ O

+ + + Op+ + + +

+ + K +

+ + + + +l+ + + + +p+ +

+ + + + + +n+ O

+ + + Op+ + + +

+ + K +

Evaluation Function

+ + + + +l+ + + + +p+ +

+ + + + + +n+ O

+ + + Op+ + + +

+ + K +

+ + + + +l+ + + + +p+ +

+ + + + + +v+ O

+ N + Op+ + + +

+ + K +

+ + + + +l+ + + + +p+ +

+ + + + r+ +v+ O+ N + Op+ + + +

+ + K +

¢ Infinity£ 9

¦ 5

0 3 5

n 3 ¥ 3

§ 1

Tree RepresentationScore Player 2:

0

1

-1

3

-2

1Player 1 Player 2

MinMax: minimizing the maximal lost

int minmax(node, depth)

{

if (node.IsTerminal || depth == 0)

return evaluate(node);

if (node.WePlay)

{

int e = MAXINT;

foreach child of node

e = min(e, minmax(child, depth-1)

return e

} else // It's the turn of the opponent

{

int e = MININT;

foreach child of node

e = max(e, minmax(child, depth-1))

return e

}

}

MinMax

0

-1

-2

1

Score Player 2:

0

1

-1

3

-2

1Player 1 Player 2

MinMax

0

-1

-2

1

Score Player 2:

0

1

-1

3

-2

1Player 1 Player 2

0

1

MinMax

0

0

-1

-2

1

Score Player 2:

0

1

-1

3

-2

1Player 1 Player 2

0

1

Improvements

�Exploration depth: deeper = better

Huge state space:

�Alpha-beta algorithm

�+ promising childs first

�Pruning techniques

� It’s your job to google.

Conclusion

Forsyth

File

+v+ O+ N ++ + +

+ + K

+v+ O+ N ++ + +

+ + K

+v+ O+ N ++ + +

+ + K

+v+ O+ N ++ + +

+ + K

+v+ O+ N ++ + +

+ + K

+v+ O+ N ++ + +

+ + K

+v+ O+ N +W + +

+ + K

+v+ O+ N ++ +¥+

+ + K

MinMax

Questions?