Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Artificial Intelligence and Machine Learning Fundamentals

You're reading from   Artificial Intelligence and Machine Learning Fundamentals Develop real-world applications powered by the latest AI advances

Arrow left icon
Product type Paperback
Published in Dec 2018
Publisher
ISBN-13 9781789801651
Length 330 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Zsolt Nagy Zsolt Nagy
Author Profile Icon Zsolt Nagy
Zsolt Nagy
Arrow right icon
View More author details
Toc

Chapter 2: AI with Search Techniques and Games

Activity 2: Teach the agent realize situations when it defends against losses

Follow these steps to complete the activity:

  1. Create a function player_can_win such that it takes all moves from the board using the all_moves_from_board function and iterates over it using a variable next_move. On each iteration, it checks if the game can be won by the sign, then it return true else false.
    def player_can_win(board, sign):
        next_moves = all_moves_from_board(board, sign)
        for next_move in next_moves:
            if game_won_by(next_move) == sign:
                return True
        return False
  2. We will extend the AI move such that it prefers making safe moves. A move is safe if the opponent cannot win the game in the next step.
    def ai_move(board):
        new_boards...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image