Top Banner
An AI Game Project
32

An AI Game Project

Feb 24, 2016

Download

Documents

raheem

An AI Game Project. Background. Fivel is a unique combiation of a NxM game and a sliding puzzle. The goals in making this projects were: Create an original game experience. Create a challenging AI player using optimized calculations. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: An AI Game Project

An AI Game Project

Page 2: An AI Game Project

Background• Fivel is a unique combiation of a NxM game and a sliding puzzle.

• The goals in making this projects were:

• Create an original game experience. • Create a challenging AI player using optimized calculations.• Achieve an attractive visual look (cute and funny woodland

creatures).• Accessibility – Easy-to-use UI.• The Future? The ability to export the game to the web

upon completion.

Page 3: An AI Game Project

The GameEach turn, a player puts a piece in an

empty slot, and slides a tile to an empty

place.

Page 4: An AI Game Project

The GameEach turn, a player puts a piece in an

empty slot, and slides a tile to an empty

place.

Page 5: An AI Game Project

The GameEach turn, a player puts a piece in an

empty slot, and slides a tile to an empty

place.

Page 6: An AI Game Project

The GameEach turn, a player puts a piece in an

empty slot, and slides a tile to an empty

place.

Page 7: An AI Game Project

The GameEach turn, a player puts a piece in an

empty slot, and slides a tile to an empty

place.

Page 8: An AI Game Project

The GameThe first player to place 5 pieces in a

row, column or diagonal at the end of

his turn, wins.

Page 9: An AI Game Project

The GameThe first player to place 5 pieces in a

row, column or diagonal at the end of

his turn, wins.

Page 10: An AI Game Project

The GameThe first player to place 5 pieces in a

row, column or diagonal at the end of

his turn, wins.

Page 11: An AI Game Project

The GameThe first player to place 5 pieces in a

row, column or diagonal at the end of

his turn, wins.

Page 12: An AI Game Project

Development

Flash/AS3 • PROS: • Allows to create great presentations and UI’s easily and

fast.• Accessibility.

• CONS: • AS3 is considerably slow.• Flash has a problems with deep-recursions (15 seconds

limit and rendering halting without the use of chunking).

• Problem: Good presentation VS. Strong and reliable computation.

Page 13: An AI Game Project

• Problem: Good presentation VS. Strong and reliable computation.

Java • PROS: • Fast and reliable for deep recursions.• Everybody knows Java!

• CONS: • Harder to achieve the visual look we were looking for.• Graphical programming in JAVA is relatively complicated.

Development

Page 14: An AI Game Project

HTMLWrapper

JavaScriptInterface

Flex/AS3 FrontendGUI

Java BackendData Structure, Logic and AI

Architecture

Page 15: An AI Game Project

Data Structure• The board is based on

“Fivlets” (“Winning Fives”).

• These are sets of indices that form a winning row, column or diagonal.

• The board statically stores all the 32 Fivlets in the game.

Example for Row Fivlets

Page 16: An AI Game Project

Data Structure• Each Fivlet knows the status of

the 5 slots it contains.

• This structure allows to perform various calculations faster than other methods.

• Moves are easy to perform (bounded by number of Fivlets the modified slots are in).

Example for Column and Diagonal Fivlets

• Iterate over all Fivlets [O(1)] in order to check for winning conditions and base the heuristics upon their state.

Page 17: An AI Game Project

AI and Heuristics• Automatic players in Fivel use α&β pruning algorithm to

search for an optimal move.

• The depth of the search is determined by the user when choosing difficulty through the GUI. We supply 4 different levels of difficulty:

Beginner – Depth 2 Experienced – Depth 3.Tough – Depth 4 Godlike – Depth 5.

Page 18: An AI Game Project

AI and Heuristics• As the search algorithm deepens, Move objects are generated

and performed on the data structure. Each Move objects has an Undo method in order to restore the board.

• These operations are low-cost due to the use of Fivlets.

• Although moves in Fivel consist actually of two different operations (piece placement and then tile sliding), they are considered as a single move in the game logic.

Page 19: An AI Game Project

AI and Heuristics• When a terminal board node is reached (either a board at an

end state or when the algorithm reached its designated depth) it is rated according to the following algorithm:

For each Fivlet in BoardFor each Slot in Fivlet

If Slot is Mine then mine += 1Else if Slot is Opponent then opp += 1

If mine == 5 then score = BIG_CONSTElse if opp == 5 then score = -BIG_CONSTElse if mine == 0 and opp > 0 then score -= -opp^NElse if opp == 0 and mine > 0 then score += mine^M

Return score

Page 20: An AI Game Project

AI and Heuristics• Basically, the algorithm iterates over all Fivlets and rates each

one. Eventually it sums up all the scores and returns it as the board’s heuristic score.

For each Fivlet in BoardFor each Slot in Fivlet

If Slot is Mine then mine += 1Else if Slot is Opponent then opp += 1

If mine == 5 then score = BIG_CONSTElse if opp == 5 then score = -BIG_CONSTElse if mine == 0 and opp > 0 then score -= -opp^NElse if opp == 0 and mine > 0 then score += mine^M

Return score

Page 21: An AI Game Project

AI and Heuristics• The algorithm counts how many pieces the current player and

his opponent placed in each Fivlet. Empty (no piece) or Void (no tile) slots are not counted and treated the same.

For each Fivlet in BoardFor each Slot in Fivlet

If Slot is Mine then mine += 1Else if Slot is Opponent then opp += 1

If mine == 5 then score = BIG_CONSTElse if opp == 5 then score = -BIG_CONSTElse if mine == 0 and opp > 0 then score -= -opp^NElse if opp == 0 and mine > 0 then score += mine^M

Return score

Page 22: An AI Game Project

AI and Heuristics• The Fivlet score is now calculated according to various cases: if

The current player has a full Fivlet, the Fivlet is rated with a high score.

For each Fivlet in BoardFor each Slot in Fivlet

If Slot is Mine then mine += 1Else if Slot is Opponent then opp += 1

If mine == 5 then score = BIG_CONSTElse if opp == 5 then score = -BIG_CONSTElse if mine == 0 and opp > 0 then score -= -opp^NElse if opp == 0 and mine > 0 then score += mine^M

Return score

Page 23: An AI Game Project

AI and Heuristics• Similarly, if the opponent of the current player has a full Fivlet,

the Fivlet is rated with a negative high score.

For each Fivlet in BoardFor each Slot in Fivlet

If Slot is Mine then mine += 1Else if Slot is Opponent then opp += 1

If mine == 5 then score = BIG_CONSTElse if opp == 5 then score = -BIG_CONSTElse if mine == 0 and opp > 0 then score -= -opp^NElse if opp == 0 and mine > 0 then score += mine^M

Return score

Page 24: An AI Game Project

AI and Heuristics• If a player has pieces in a Fivlet without an interference from

his opponent, the Fivlet is exponentially scored based on the number of pieces in that Fivlet.

For each Fivlet in BoardFor each Slot in Fivlet

If Slot is Mine then mine += 1Else if Slot is Opponent then opp += 1

If mine == 5 then score = BIG_CONSTElse if opp == 5 then score = -BIG_CONSTElse if mine == 0 and opp > 0 then score -= -opp^NElse if opp == 0 and mine > 0 then score += mine^M

Return score

Page 25: An AI Game Project

AI and Heuristics• Why BIG_CONST and not INFINITY?

If more than one Fivlet is full (which is obviously better than one), the board’s score will still be INFINITY (INF + INF = INF).

For each Fivlet in BoardFor each Slot in Fivlet

If Slot is Mine then mine += 1Else if Slot is Opponent then opp += 1

If mine == 5 then score = BIG_CONSTElse if opp == 5 then score = -BIG_CONSTElse if mine == 0 and opp > 0 then score -= -opp^NElse if opp == 0 and mine > 0 then score += mine^M

Return score

Page 26: An AI Game Project

AI and Heuristics• M and N? M is greater than N since playing aggressively

(striving for full Fivlets) has better priority than playing defensively (stopping the opponent from achieving full Fivlets).

For each Fivlet in BoardFor each Slot in Fivlet

If Slot is Mine then mine += 1Else if Slot is Opponent then opp += 1

If mine == 5 then score = BIG_CONSTElse if opp == 5 then score = -BIG_CONSTElse if mine == 0 and opp > 0 then score -= -opp^NElse if opp == 0 and mine > 0 then score += mine^M

Return score

Page 27: An AI Game Project

AI Analysis

Average Game Length(Mutual Turns)

Results Number of Games Tested

Match Type

20 Victories 50%Draw 0%

20 Human VS.

Human

20 Human won 40%CPU won 60%

Draw 0%

20 Human VS.

CPU (Beginner)

20 Human won 40%CPU won 60%

Draw 0%

20 Human VS.

CPU (Experienced)

20 Human won 40%CPU won 60%

Draw 0%

20 Human VS.

CPU (Tough)

20 Human won 40%CPU won 60%

Draw 0%

20 Human VS.

CPU (Godlike)

Human

Page 28: An AI Game Project

AI Analysis

Average Game Length(Mutual Turns)

Results Number of Games Tested

Match Type

20 Victories %100Draw 0%

20 CPU (Beginner)VS.

CPU (Beginner)

20 Weaker CPU won 40%Stronger CPU won 60%

Draw 0%

20 CPU (Beginner)VS.

CPU (Experienced)

20 Weaker CPU won 40%Stronger CPU won 60%

Draw 0%

20 CPU (Beginner) VS.

CPU (Tough)

20 Weaker CPU won 40%Stronger CPU won 60%

Draw 0%

20 CPU (Beginner)VS.

CPU (Godlike)

Beginner

Page 29: An AI Game Project

AI Analysis

Average Game Length(Mutual Turns)

Results Number of Games Tested

Match Type

20 Victories 100%Draw 0%

20 CPU (Experienced)VS.

CPU (Experienced)

20 Weaker CPU won 40%Stronger CPU won 60%

Draw 0%

20 CPU (Experienced) VS.

CPU (Tough)

20 Weaker CPU won 40%Stronger CPU won 60%

Draw 0%

20 CPU (Experienced)VS.

CPU (Godlike)

Experienced

Page 30: An AI Game Project

AI Analysis

Average Game Length(Mutual Turns)

Results Number of Games Tested

Match Type

20 Victories 100%Draw 0%

20 CPU (Tough) VS.

CPU (Tough)

20 Weaker CPU won 40%Stronger CPU won 60%

Draw 0%

20 CPU (Tough)VS.

CPU (Godlike)

Tough

Page 31: An AI Game Project

AI Analysis

Average Game Length(Mutual Turns)

Results Number of Games Tested

Match Type

20 Victories 100%Draw 0%

20 CPU (Godlike)VS.

CPU (Godlike)

Godlike

Page 32: An AI Game Project

Enjoy the Game!

woot?