SlideShare a Scribd company logo
Teaching a Computer To Play Blackjack

Introduction

One of the main specializations that make up the larger subject that is Computer Science is Artificial
Intelligence and Machine Learning. Originally Artificial Intelligence was efforts into trying to make a
computer that competed with a human. In chess, in conversations, in problem solving. Now
researchers and computer scientists often take a different focus – letting the computer do what its best
at.

The computer is much better than a human at seeing patterns in complex situations and making
decisions about how to act in the future. For this assignment you are going to teach the computer about
a very simple pattern – a strategy for winning at BlackJack.

The Game of BlackJack

In the game of BlackJack (which is played at almost all casinos around the world), each player plays
individually against the dealer (or the house). The idea of the game is to get as close to 21 points
without going over. The points are determined by the cards that you draw where a number card is
worth its face value, a face card (K, Q, J) is worth 10 and an Ace is worth either a 1 or 11 (you decide).
You can find out more about the game of BlackJack at http://en.wikipedia.org/wiki/Blackjack

The Learning Aspect/Fuzzy Logic

We are going to be using a concept called Fuzzy Logic to help the computer decide whether to hit or
stay. In most logic situations you have two choices – true or false. In a fuzzy logic situation you may
want to take a chance every now and then and say true, but other times you might want to say false.
How do you think this applies to this card game?

Your program will maintain an array of values that represent the probabilities that a player should hit at
a given hand value. (ie. In weights[15] will be the probability of hitting when you draw a 15 in your
hand) Obviously you should “learn” eventually that you always want to hit at 10 and never want to hit
at 21, with a range of values in between. This array (because it contains probabilities) with contain
double values between 0 and 1. Your program should start with all values being equal to .5 (so that you
have a 50/50 chance of hitting or staying to begin with no matter what hand is drawn). Remember your
computer needs to learn, you are not allowed to tell it any information other than whether it won or lost
and what values it had in its hand to help it learn.

When you hit and do not bust, you should be more likely to hit again at that value – so increase the
probability in some way at that hand value. When you hit and bust, you should be less likely to hit
again at that value – and therefore your program should decrease the value of the weight at that point.

Your Program

Your assignment is to write a computer program that will help the computer learn to play blackjack.
You will then run the program a number of times to train the computer to determine if it should hit or
stay given a particular card value.

Some basic assumptions:
   In our simulation the dealer plays by basic casino rules – they will always stay when their cards
       total 17.
      Our deck will always be reshuffled on every round and contains many decks of cards – for ease
       of calculation you may assume that any card value has an equal weight of being drawn at any
       time.
      You are only playing against the dealer, there are no other players in the game to worry about.
      Suit of the card does not matter in any way.
      Ties go to the player.
      Your decision to hit or stay should be solely based upon the value of the cards in your hand – do
       not worry about what the dealer might have.

While these assumptions are not exactly what a person would encounter playing in a casino, they are
here to simplify the number of variables you need to worry about in your program. You may however
be asked to think about these situations later.

You are going to be given a card class that represents the value of each card and whether or not it is an
ace. (Jack = 11, Queen = 12, King = 13, Ace = 1 Note that these are not the blackjack values, but
instead just a representational value of the card)

You will also be given a LearnBlackJack class where you will need to fill in the following methods:
    getValue – This method takes an ArrayList of cards and calculates the value of the hand
      according to the rules above.
    playGame – This method plays one hand of BlackJack and returns true if the player did not bust
      (go over 21) This method also updates your weights array to increase the probability of hitting
      at a given hand if the computer hit and did not bust, and decreases the probability of hitting at a
      given hand if the computer hit and got a number over 21.



Thought Questions:
   1. Describe fuzzy logic. In what situation in your life do you use fuzzy logic to decide between
      two outcomes? Why is a fuzzy approach better than a strictly boolean one in that situation?

   2. In the simulation you are writing you only care about whether or not you go over 21, not
      whether you beat the dealer. How would you use the information about the dealer's hand to
      change your weights (or should you)? Why or why not?

   3. Netflix is a company in the united states that allows people to rent movies over the internet.
      One of the advantages of Netflix is that they recommend movies to people based upon other
      movies that they have rated (on a scale of 1 to 5). Netflix has offered $1 Million to anyone who
      can make a significant improvement to their rating score (in simple terms – they want to be able
      to guess how many stars you will give a movie based on your other reviews, and the reviews of
      all other people in the system). Obviously this is a complex problem (and people are working
      hard to solve it – the contest has been going on for 2 years already and no one has beaten the
      improvement number for the money). Using what you have seen/learned in this assignment –
      how would you even start? How might you adjust an array of movie weights given what the
      person rated before, and how others have rated the move?

More Related Content

PPT
Learning Through Gaming
PDF
FreeMobileHacks
PDF
Game Balance 2: Sustained Uncertainty
PDF
Game theory for a better world
PPTX
Taking a Gamble with Functional Domain Modeling
PDF
BrainWars Playing Strategies for All BrainWars Players
PDF
Game Theory - An Introduction (2009)
PPT
Game Tree ( Oyun Ağaçları )
Learning Through Gaming
FreeMobileHacks
Game Balance 2: Sustained Uncertainty
Game theory for a better world
Taking a Gamble with Functional Domain Modeling
BrainWars Playing Strategies for All BrainWars Players
Game Theory - An Introduction (2009)
Game Tree ( Oyun Ağaçları )

What's hot (9)

PPT
The cannoneer of_ragville_final_presentation
PPTX
Adversarial search
PPTX
Minimax
PDF
The Pixel Lab 2015 | Extending story through play - Nick Fortugno
PPTX
Game Theory Strategic Decision Making
DOC
A sample Lab report on a game.
PDF
Advanced gambling strategy for blackjack
PPTX
Gameplay
PPT
Game Playing in Artificial Intelligence
The cannoneer of_ragville_final_presentation
Adversarial search
Minimax
The Pixel Lab 2015 | Extending story through play - Nick Fortugno
Game Theory Strategic Decision Making
A sample Lab report on a game.
Advanced gambling strategy for blackjack
Gameplay
Game Playing in Artificial Intelligence
Ad

Similar to Teaching a Computer To Play Blackjack.doc (20)

PDF
1532 0545-2001-02-01-0050
DOCX
Game apps to win money
PDF
Casino paper 2
PPT
Casino Mathematics
PDF
Playing blackjack for beginners
PPTX
How to write an 8 sentence paragraph
PDF
Dice of Debt - game rules
PDF
Little book of programming challenges
PPTX
Blackjack dominance
PPTX
Designing balance (takeaway version)
PPTX
Slide 1
DOCX
Lecture OverviewSolving the prisoner’s dilemmaInstrumental r.docx
PPTX
Games for education
PDF
9.4 la answers
PPTX
(3) research
PPT
Instructions to Product Poker
PDF
25 tips to build Tutorials on Board Game Arena
PPT
Bit powerpoint
PPTX
Recreational mathematics for MichMATYC 10 10
PPT
20131105 concepts of game design
1532 0545-2001-02-01-0050
Game apps to win money
Casino paper 2
Casino Mathematics
Playing blackjack for beginners
How to write an 8 sentence paragraph
Dice of Debt - game rules
Little book of programming challenges
Blackjack dominance
Designing balance (takeaway version)
Slide 1
Lecture OverviewSolving the prisoner’s dilemmaInstrumental r.docx
Games for education
9.4 la answers
(3) research
Instructions to Product Poker
25 tips to build Tutorials on Board Game Arena
Bit powerpoint
Recreational mathematics for MichMATYC 10 10
20131105 concepts of game design
Ad

More from butest (20)

PDF
EL MODELO DE NEGOCIO DE YOUTUBE
DOC
1. MPEG I.B.P frame之不同
PDF
LESSONS FROM THE MICHAEL JACKSON TRIAL
PPT
Timeline: The Life of Michael Jackson
DOCX
Popular Reading Last Updated April 1, 2010 Adams, Lorraine The ...
PDF
LESSONS FROM THE MICHAEL JACKSON TRIAL
PPTX
Com 380, Summer II
PPT
PPT
DOCX
The MYnstrel Free Press Volume 2: Economic Struggles, Meet Jazz
DOC
MICHAEL JACKSON.doc
PPTX
Social Networks: Twitter Facebook SL - Slide 1
PPT
Facebook
DOCX
Executive Summary Hare Chevrolet is a General Motors dealership ...
DOC
Welcome to the Dougherty County Public Library's Facebook and ...
DOC
NEWS ANNOUNCEMENT
DOC
C-2100 Ultra Zoom.doc
DOC
MAC Printing on ITS Printers.doc.doc
DOC
Mac OS X Guide.doc
DOC
hier
DOC
WEB DESIGN!
EL MODELO DE NEGOCIO DE YOUTUBE
1. MPEG I.B.P frame之不同
LESSONS FROM THE MICHAEL JACKSON TRIAL
Timeline: The Life of Michael Jackson
Popular Reading Last Updated April 1, 2010 Adams, Lorraine The ...
LESSONS FROM THE MICHAEL JACKSON TRIAL
Com 380, Summer II
PPT
The MYnstrel Free Press Volume 2: Economic Struggles, Meet Jazz
MICHAEL JACKSON.doc
Social Networks: Twitter Facebook SL - Slide 1
Facebook
Executive Summary Hare Chevrolet is a General Motors dealership ...
Welcome to the Dougherty County Public Library's Facebook and ...
NEWS ANNOUNCEMENT
C-2100 Ultra Zoom.doc
MAC Printing on ITS Printers.doc.doc
Mac OS X Guide.doc
hier
WEB DESIGN!

Teaching a Computer To Play Blackjack.doc

  • 1. Teaching a Computer To Play Blackjack Introduction One of the main specializations that make up the larger subject that is Computer Science is Artificial Intelligence and Machine Learning. Originally Artificial Intelligence was efforts into trying to make a computer that competed with a human. In chess, in conversations, in problem solving. Now researchers and computer scientists often take a different focus – letting the computer do what its best at. The computer is much better than a human at seeing patterns in complex situations and making decisions about how to act in the future. For this assignment you are going to teach the computer about a very simple pattern – a strategy for winning at BlackJack. The Game of BlackJack In the game of BlackJack (which is played at almost all casinos around the world), each player plays individually against the dealer (or the house). The idea of the game is to get as close to 21 points without going over. The points are determined by the cards that you draw where a number card is worth its face value, a face card (K, Q, J) is worth 10 and an Ace is worth either a 1 or 11 (you decide). You can find out more about the game of BlackJack at http://en.wikipedia.org/wiki/Blackjack The Learning Aspect/Fuzzy Logic We are going to be using a concept called Fuzzy Logic to help the computer decide whether to hit or stay. In most logic situations you have two choices – true or false. In a fuzzy logic situation you may want to take a chance every now and then and say true, but other times you might want to say false. How do you think this applies to this card game? Your program will maintain an array of values that represent the probabilities that a player should hit at a given hand value. (ie. In weights[15] will be the probability of hitting when you draw a 15 in your hand) Obviously you should “learn” eventually that you always want to hit at 10 and never want to hit at 21, with a range of values in between. This array (because it contains probabilities) with contain double values between 0 and 1. Your program should start with all values being equal to .5 (so that you have a 50/50 chance of hitting or staying to begin with no matter what hand is drawn). Remember your computer needs to learn, you are not allowed to tell it any information other than whether it won or lost and what values it had in its hand to help it learn. When you hit and do not bust, you should be more likely to hit again at that value – so increase the probability in some way at that hand value. When you hit and bust, you should be less likely to hit again at that value – and therefore your program should decrease the value of the weight at that point. Your Program Your assignment is to write a computer program that will help the computer learn to play blackjack. You will then run the program a number of times to train the computer to determine if it should hit or stay given a particular card value. Some basic assumptions:
  • 2. In our simulation the dealer plays by basic casino rules – they will always stay when their cards total 17.  Our deck will always be reshuffled on every round and contains many decks of cards – for ease of calculation you may assume that any card value has an equal weight of being drawn at any time.  You are only playing against the dealer, there are no other players in the game to worry about.  Suit of the card does not matter in any way.  Ties go to the player.  Your decision to hit or stay should be solely based upon the value of the cards in your hand – do not worry about what the dealer might have. While these assumptions are not exactly what a person would encounter playing in a casino, they are here to simplify the number of variables you need to worry about in your program. You may however be asked to think about these situations later. You are going to be given a card class that represents the value of each card and whether or not it is an ace. (Jack = 11, Queen = 12, King = 13, Ace = 1 Note that these are not the blackjack values, but instead just a representational value of the card) You will also be given a LearnBlackJack class where you will need to fill in the following methods:  getValue – This method takes an ArrayList of cards and calculates the value of the hand according to the rules above.  playGame – This method plays one hand of BlackJack and returns true if the player did not bust (go over 21) This method also updates your weights array to increase the probability of hitting at a given hand if the computer hit and did not bust, and decreases the probability of hitting at a given hand if the computer hit and got a number over 21. Thought Questions: 1. Describe fuzzy logic. In what situation in your life do you use fuzzy logic to decide between two outcomes? Why is a fuzzy approach better than a strictly boolean one in that situation? 2. In the simulation you are writing you only care about whether or not you go over 21, not whether you beat the dealer. How would you use the information about the dealer's hand to change your weights (or should you)? Why or why not? 3. Netflix is a company in the united states that allows people to rent movies over the internet. One of the advantages of Netflix is that they recommend movies to people based upon other movies that they have rated (on a scale of 1 to 5). Netflix has offered $1 Million to anyone who can make a significant improvement to their rating score (in simple terms – they want to be able to guess how many stars you will give a movie based on your other reviews, and the reviews of all other people in the system). Obviously this is a complex problem (and people are working hard to solve it – the contest has been going on for 2 years already and no one has beaten the improvement number for the money). Using what you have seen/learned in this assignment – how would you even start? How might you adjust an array of movie weights given what the person rated before, and how others have rated the move?