an ai game project
DESCRIPTION
An AI Game Project. Background. Fivel is a unique hybrid of a NxM game and a sliding puzzle. The goals in making this project were: Create an original game experience. Create a challenging AI player using optimized calculations. - PowerPoint PPT PresentationTRANSCRIPT
An AI Game Project
Background• Fivel is a unique hybrid of a NxM game and a sliding puzzle.
• The goals in making this project 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.
The GameEach turn, a player puts a piece in an
empty slot, and slides a tile to an empty
place.
The GameEach turn, a player puts a piece in an
empty slot, and slides a tile to an empty
place.
The GameEach turn, a player puts a piece in an
empty slot, and slides a tile to an empty
place.
The GameEach turn, a player puts a piece in an
empty slot, and slides a tile to an empty
place.
The GameEach turn, a player puts a piece in an
empty slot, and slides a tile to an empty
place.
The GameThe first player to place 5 pieces in a
row, column or diagonal at the end of
his turn, wins.
The GameThe first player to place 5 pieces in a
row, column or diagonal at the end of
his turn, wins.
The GameThe first player to place 5 pieces in a
row, column or diagonal at the end of
his turn, wins.
The GameThe first player to place 5 pieces in a
row, column or diagonal at the end of
his turn, wins.
Development
Flash/AS3 • PROS: • Allows to create great presentations and GUI’s easily and
fast (vector graphics = win).• WWW Accessibility.
• CONS: • AS3 is considerably slow.• Flash is very problematic with deep-recursions (15 seconds
limit and render-halting due to its single-threaded nature).
• Problem: Good presentation VS. Strong and reliable computation.
• Problem: Good presentation VS. Strong and reliable computation.
Java • PROS: • Fast and reliable for deep recursions - exactly what is
needed for minimax search.• Everybody knows to develop in Java!
• CONS: • Harder to achieve the visual look we were looking for.• Graphical programming in Java is relatively complicated.• Java is not popular for web gaming since the early 2000’s.
Development
HTMLWrapper
JavaScriptInterface
Flex/AS3 FrontendGUI
Java BackendData Structure, Logic and AI
ArchitectureConclusion: Combine them!
Data Structure• The board is based on simple
data structures called “Fivlets”.
• 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
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
• Iterataions over all Fivlets [O(1)] in order to check for winning conditions and base the heuristics upon their state.
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 a difficulty level through the GUI. We supply 4 different levels of difficulty which are different from each other by a few factors:
• MAXIMUM SEARCH DEPTH - The search depth the automated player will use after a few turns.
• AGGRESSION and DEFENSE RATES - Used in the heuristic scoring. Determine how much importance the player will pay for playing aggressively or defensively.
AI and Heuristics• The difficulty levels in Fivel are:
Search DepthIncrease
Maximum Depth
DefenseRate
Aggression Rate
Difficulty Level
Starts at 1 and doesn’t increase.
1 1.75 2 Beginner
Starts at 1 and increases to 2 after a few turns.
2 1.5 2 Experienced
Starts at 2 and increases to 3 after a few turns.
3 1.5 2 Tough
Starts at 2, and increases immediately to 3.
3 1.5 2.5 Godlike
AI and Heuristics• Fivel’s branching factor is high - Bounded by 128.
32 (slots) x 4 (moveable tiles) = 128
• Thus, the search algorithm works reasonably only with a maximum search depth of 3:
• Search depth 3 returns an optimal move in approximately 7-8 seconds.
• In comparison, search depth 4 returns an optimal move in approximately 5 minutes - not reasonable for a game played against a human opponent…
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 when generating moves during the search.
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 Board
For each Slot in Fivlet
If Slot is Mine then mine += 1
Else if Slot is Opponent then opp += 1
If mine == 5 then score = BIG_CONST
Else if opp == 5 then score = -BIG_CONST
Else if mine == 0 and opp > 0 then score -= -opp^AGG
Else if opp == 0 and mine > 0 then score += mine^DEF
Return score
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 Board
For each Slot in Fivlet
If Slot is Mine then mine += 1
Else if Slot is Opponent then opp += 1
If mine == 5 then score = BIG_CONST
Else if opp == 5 then score = -BIG_CONST
Else if mine == 0 and opp > 0 then score -= -opp^AGG
Else if opp == 0 and mine > 0 then score += mine^DEF
Return score
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 Board
For each Slot in Fivlet
If Slot is Mine then mine += 1
Else if Slot is Opponent then opp += 1
If mine == 5 then score = BIG_CONST
Else if opp == 5 then score = -BIG_CONST
Else if mine == 0 and opp > 0 then score -= -opp^AGG
Else if opp == 0 and mine > 0 then score += mine^DEF
Return score
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 Board
For each Slot in Fivlet
If Slot is Mine then mine += 1
Else if Slot is Opponent then opp += 1
If mine == 5 then score = BIG_CONST
Else if opp == 5 then score = -BIG_CONST
Else if mine == 0 and opp > 0 then score -= -opp^AGG
Else if opp == 0 and mine > 0 then score += mine^DEF
Return score
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 Board
For each Slot in Fivlet
If Slot is Mine then mine += 1
Else if Slot is Opponent then opp += 1
If mine == 5 then score = BIG_CONST
Else if opp == 5 then score = -BIG_CONST
Else if mine == 0 and opp > 0 then score -= -opp^AGG
Else if opp == 0 and mine > 0 then score += mine^DEF
Return score
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 Board
For each Slot in Fivlet
If Slot is Mine then mine += 1
Else if Slot is Opponent then opp += 1
If mine == 5 then score = BIG_CONST
Else if opp == 5 then score = -BIG_CONST
Else if mine == 0 and opp > 0 then score -= -opp^AGG
Else if opp == 0 and mine > 0 then score += mine^DEF
Return score
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 Board
For each Slot in Fivlet
If Slot is Mine then mine += 1
Else if Slot is Opponent then opp += 1
If mine == 5 then score = BIG_CONST
Else if opp == 5 then score = -BIG_CONST
Else if mine == 0 and opp > 0 then score -= -opp^AGG
Else if opp == 0 and mine > 0 then score += mine^DEF
Return score
AI and Heuristics• AGG and DEFF? AGG is normally greater than DEF since playing
aggressively (striving for full Fivlets) has better priority than playing defensively (preventing opponent’s Full Fivlets).
For each Fivlet in Board
For each Slot in Fivlet
If Slot is Mine then mine += 1
Else if Slot is Opponent then opp += 1
If mine == 5 then score = BIG_CONST
Else if opp == 5 then score = -BIG_CONST
Else if mine == 0 and opp > 0 then score -= -opp^AGG
Else if opp == 0 and mine > 0 then score += mine^DEF
Return score
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
AI Analysis
Game Length(Mutual Turns)
Results Number of Games Tested*
Match Type
20 Victories %100Draw 0%
1 CPU (Beginner)VS.
CPU (Beginner)
20 Weaker CPU won 40%Stronger CPU won 60%
Draw 0%
1 CPU (Beginner)VS.
CPU (Experienced)
20 Weaker CPU won 40%Stronger CPU won 60%
Draw 0%
1 CPU (Beginner) VS.
CPU (Tough)
20 Weaker CPU won 40%Stronger CPU won 60%
Draw 0%
1 CPU (Beginner)VS.
CPU (Godlike)
Beginner
* Tested only 1 game due to exact results in all CPU vs. CPU games (due to the lack of a random factor).
AI Analysis
Game Length(Mutual Turns)
Results Number of Games Tested*
Match Type
20 Victories 100%Draw 0%
1 CPU (Experienced)VS.
CPU (Experienced)
20 Weaker CPU won 40%Stronger CPU won 60%
Draw 0%
1 CPU (Experienced) VS.
CPU (Tough)
20 Weaker CPU won 40%Stronger CPU won 60%
Draw 0%
1 CPU (Experienced)VS.
CPU (Godlike)
Experienced
* Tested only 1 game due to exact results in all CPU vs. CPU games (due to the lack of a random factor).
AI Analysis
Game Length(Mutual Turns)
Results Number of Games Tested*
Match Type
20 Victories 100%Draw 0%
1 CPU (Tough) VS.
CPU (Tough)
20 Weaker CPU won 40%Stronger CPU won 60%
Draw 0%
1 CPU (Tough)VS.
CPU (Godlike)
Tough
* Tested only 1 game due to exact results in all CPU vs. CPU games (due to the lack of a random factor).
AI Analysis
Game Length(Mutual Turns)
Results Number of Games Tested*
Match Type
20 Victories 100%Draw 0%
1 CPU (Godlike)VS.
CPU (Godlike)
Godlike
* Tested only 1 game due to exact results in all CPU vs. CPU games (due to the lack of a random factor).
Enjoy the Game!
woot?