CONNECT FOUR
TOPIC 03v2 – CONNECT FOUR AI

 

GUIDE TO CREATING OuterRandomAI01

 

 

DESCRIPTION

 

In this guide, you will create your own version of RandomAI01.  Instead of choosing a random column between 0 and 6, OuterRandomAI01 chooses one of the two outer columns.  So, it chooses either 0 or 6.

 

REFLECTION

 

Do you think this AI will be better than RandomAI01?  Let’s build it and then find out!

 

STEP 1

 

In your Java Project that contains your Connect Four files, create a class called OuterRandomAI01 and make it implement the AIAgent interface.

public class OuterRandomAI01 implements AIAgent

{

}


STEP 2

 

You need to add the methods specified in the AIAgent interface.  To do this, you can right-click on the OuterRandomAI01 and choose Add unimplemented methods.  Remove all of the auto-generated stuff inside the methods.

 

public class OuterRandomAI01 implements AIAgent

{

     @Override

     public int playMove(Game g, int playerNumber)

     {

     }

 

     @Override

     public String getName()

     {

     }

 

     @Override

     public String getWinQuote(double winPercentage)

     {

     }

 

     @Override

     public String getAuthor()

     {

     }

 

     @Override

     public void justWon()

     {

     }

 

     @Override

     public void justLost()

     {

     }

 

     @Override

     public void justTied()

     {

     }

}

 

STEP 3

The real work goes into the playMove method but let’s get the other six methods our of the way because they are quick to deal with.

a) In the getName() method, add the line:
       return "OuterRandomAI01";

b) In the getWinQuote(double winPercentage) method, add the line:
           return "Living on the edge!";

c) In the getAuthor() method, add the line:

           return "Mr. Campeau";

 

d) Leave the justWon(), justLost() and justTied() methods empty.

 

public class OuterRandomAI01 implements AIAgent

{

     @Override

     public int playMove(Game g, int playerNumber)

     {

     }

 

     @Override

     public String getName()

     {

           return "OuterRandomAI01";

     }

 

     @Override

     public String getWinQuote(double winPercentage)

     {

           return "Living on the edge!";

     }

 

     @Override

     public String getAuthor()

     {

           return "Mr. Campeau";

     }

 

     @Override

     public void justWon()

     {

     }

 

     @Override

     public void justLost()

     {

     }

 

     @Override

     public void justTied()

     {

     }

}

 

STEP 4

 

We are now ready to implement the important method, playMove. 

This AI will choose column 0 half of the time and column 6 the other half of the time.  Write the code to make this happen.

 

public class OuterRandomAI01 implements AIAgent

{

     @Override

     public int playMove(Game g, int playerNumber)

     {

           if (Math.random() < 0.50)

                return 0;

           else

                return 6;

     }

 

     @Override

     public String getName()

     {

           return "OuterRandomAI01";

     }

 

     @Override

     public String getWinQuote(double winPercentage)

     {

           return "Living on the edge!";

     }

 

     @Override

     public String getAuthor()

     {

           return "Mr. Campeau";

     }

 

     @Override

     public void justWon()

     {

     }

 

     @Override

     public void justLost()

     {

     }

 

     @Override

     public void justTied()

     {

     }

}

 

STEP 5 - TESTING

 

We are done creating our OuterRandomAI01 program!  Already!

Now we should test it out. 

a) In Tester, run a game that includes your OuterRandomAI01 agent and make it play against a human.  Analyze that is it in fact choosing the correct columns.

 

b) In Tester, run a game between OuterRandomAI01 and RandomAI01. 

c) In Tester, run a series between OuterRandomAI01 and RandomAI01.

 

STEP 6 – ANALYZE YOUR NEW AIAGENT (OPTIONAL)

 

Run a series of 10000 games between RandomAI01 and OuterRandomAI01.  What percentage of games did OuterRandomAI01 win?  (Feel free to add this in a comment at the top of your code like there is for the other provided AIAgents.)

 

STEP 7 – CONSIDER IMPROVEMENTS

 

Can you think of an obvious flaw that this AIAgent has?  If you aren’t sure, just play a few games as a human against it and just play a defensive game.  You will win everytime.

If you decide to improve this code, you have to decide if you want to change the existing one in the current class, or maybe create a new class called OuterRandomAI02.