Team-Tan's Lab Manual

From Software Engineering

Jump to: navigation, search

<html><head><title>AIMonopd Lab Manual</title></head>

<body>

Contents

[edit] Introduction

Welcome to the AI Monopoly lab. In this lab you will be able to write a small Java based script that will make the decisions in playing a game of Monopoly, or in short, an AI for a game of Monopoly. It may pay to refresh yourself on <a href="http://www.google.com/search?q=monopoly+rules"> the rules of Monopoly</a> and a basic understanding of the game's structure is assumed from this point onwards. There are two major sections to this lab manual, the API you will use to get information about the current game's status and the framework that your script has to interact within to properly interact with the aimonopd client. To over-generalize the API section covers the input your AI script will have access to and the Framework defines how it will output. The framework will include a series of functions you need to implement. These reflect decisions that must be made such as how to react to an auction or what to do in jail. The API includes not only the data of the game surroundings but additionally holds the key to doing more independent actions (such as building a house or hotel or starting a trade).

[edit] Getting Started

First off you will have to download the aimonopd client from <a href="MonopdAiClient.jar">here</a>. Now start a new project as shown here:

<img src="howto/1.png">

Click through the next menu until the project is setup.  Now take the JAR you downloaded and drag it into the src folder in the project as shown here:

<img src="howto/2.png">
Then right click the JAR and select Build Path -> Add to Build Path as shown here

<img src="howto/3.png">
Next you'll want to do File -> New... and select Class.

<img src="howto/4.png">
From here you will want to tell Eclipse that you want to impliment the <a href="edu/bsu/monopoly/scripts/MonopdAI.html"> MonopdAI</a> interface and you want to use the edu.bsu.monopd.scripts package as shown here:

<img src="howto/5.png">

From here you can start filling in the functions as you see fit.

[edit] API

In the functions you will be writing (detailed in the Framework section) you will be passed classes that contain what you need to know about the current game to make your decisions.

[edit] GameStatus

The <a href="index.html?edu/bsu/monopoly/game/GameStatus.html"> GameStatus</a> class contains a series of helpful sub-classes that will hold most of the information you need to access. Of note is the Board that stores the information about the property and current ownership, the PlayerManager which stores information on other players, the location method which returns where you are at and the currentPlayer method which will return the Player class that describes you.

[edit] PlayerManager

The <a href="index.html?edu/bsu/monopoly/game/player/PlayerManager.html">PlayerManager</a> class contains a list of players stored in a list. You can get a specific Player by using the get method passing the Playerid in an integer format. Also if you already have a player you can get his ID by passing the Player variable to the get method. Calling the <a href="edu/bsu/monopoly/game/player/PlayerManager.html#size()">size method</a> will return an integer telling you how many players there are. By using the built in Iterator you can traverse the entire collection of players.

[edit] Player

The <a href="index.html?edu/bsu/monopoly/game/player/Player.html">Player</a> class contains the information you might need to know about a specific player. The cashOnHand function will tell you how much money the player has sitting in front of them. The id function gives you their playerID which is helpful for referencing things in the PlayerManager and on the Board. The location method will give you a numerical representation of where they are on the board. The name method will return what the player's display name is. The ownedProperty method will return a PropertyList telling you what properties the player in question owns. Sometimes you will have a Player named "me" passed to you, in this case you can use it to easily get information about your current cash on hand and owned property.

[edit] Board

The <a href="index.html?edu/bsu/monopoly/game/board/Board.html">Board</a> class contains the BoardSpaces that make up the board of a Monopoly game. By using the boardSpace method and passing it an ID you can get the BoardSpace class for that specific spot on the board. By using the iterator you can parse through the entire board.

[edit] BoardSpace

The <a href="index.html?edu/bsu/monopoly/game/board/BoardSpace.html">BoardSpace</a> class contains every piece of information about a single space on the board. By calling the id method you can easily get the estate's ID number. By calling the name method you can get the space's name. The price method, unsurprisingly, returns a price. The owner method returns the Player class for the player that currently owns the space. The estateGroup method returns what EstateGroup the space is a part of. The mortgaged method will return a boolean that is true if the space has been mortgaged and false if it has not.

[edit] EstateGroup

The <a href="index.html?edu/bsu/monopoly/game/board/EstateGroup.html">EstateGroup</a> class models the "color" groups on a Monopoly board. By iterating through this class you can gather information on just a single property group.

[edit] PropertyList

The <a href="index.html?edu/bsu/monopoly/game/board/PropertyList.html">PropertyList</a> class contains a list of properties. You can traverse this list using the iterator.

[edit] Estate

The <a href="index.html?edu/bsu/monopoly/game/board/Estate.html">Estate</a> class is helpful in case you want to test if a BoardSpace is an Estate by using the instanceof comparison.

[edit] NonProperty

The <a href="index.html?edu/bsu/monopoly/game/board/NonProperty.html">NonProperty</a> class is helpful in case you want to test if a BoardSpace is not property by using the instanceof comparison.

[edit] Property

The <a href="index.html?edu/bsu/monopoly/game/board/Property.html">Property</a> class is helpful in case you want to test if a BoardSpace is a property by using the instanceof comparison.

[edit] Railroad

The <a href="index.html?edu/bsu/monopoly/game/board/Railroad.html">Railroad</a> class is helpful in case you want to test if a BoardSpace is a railroad by using the instanceof comparison.

[edit] Utility

The <a href="index.html?edu/bsu/monopoly/game/board/Utility.html">Utility</a> class is helpful in case you want to test if a BoardSpace is a utility by using the instanceof comparison.

[edit] Framework

Your AI script will be called on as a class from the aimonopd client. To properly respond to these calls you have to implement the <a href="aimonpd/index.html?edu/bsu/monopoly/scripts/MonopdAi.html">MonopdAI</a> interface. Each function call represents a particular point in time that the AI can either make a decision or take independent action. These functions are as follows :

Command preRollTurn(GameStatus status, Player me);
IncomeTax payTax(GameStatus status);
PropertyAction buyOrAuctionProperty(GameStatus status,Player me);
void notMyTurn(GameStatus gameStatus, Player me);
JailAction  inTheClink(GameStatus status);
Bid auctionHouse(Auction a, GameStatus status, Player me);
TradeType trade(GameStatus status, Trade trade, Player me);

[edit] preRollTurn

The preRollTurn function handles any action you may want to take before rolling your dice at the start of the turn. This includes building houses, initiating trades or fiddling with mortgages. When you return out of this block you will roll the dice. This function is called at the start of your turn before dice are rolled.

[edit] payTax

The payTax function handles the decision required if you land on the Income Tax square, whether you want to pay a portion of your current net wealth or a flat fee. This function is called when after rolling or a chance card you land on Income Tax. Once you determine which you want you select it by returning either

return IncomeTax.FLAT_TAX;
return IncomeTax.PROPORTIONAL_TAX;

[edit] buyOrAuctionProperty

The buyOrAuctionProperty function controls the decision made when you land on a space of if you want to buy the property or send it to the auction block. This function is called when you land on an unowned property. To return a buy or auction you simply :

return PropertyAction.BUY;
return PropertyAction.AUCTION;

[edit] notMyTurn

The notMyTurn function is called anytime an action is made outside the scope of your turn. This function could be used to evaluate the playing field for trades or other such actions.

[edit] inTheClink

The inTheClink function is called when you start your turn in Jail. From here you can decide to either

return JailAction.ATTEMPT_TO_ROLL_DOUBLES; 
return JailAction.PAY; 
return JailAction.USE_CARD;

[edit] auctionHouse

The auctionHouse function is called when an auction update is seen. You will have three variables passed to you. The GameStatus passed will give you general details about the game and the Player me is, as you might expect, a class that holds information on your status in the game. The <a href="edu/bsu/monopoly/game/actions/Auction.html">Auction</a> you get passed will provide you information on the current auction, including the high bid and highest bidder. To pass back your reaction to the auction you return a <a href="edu/bsu/monopoly/game/actions/Bid.html">Bid</a>. If you just return a new Bid it will increment the maximum bid by one and bid that. Alternately you can check the <a href="edu/bsu/monopoly/game/actions/Bid.html#Bid(int)">second bid constructor</a> to bid a certain amount over the current maximum bid. Example code follows

return new Bid(); //This returns a new bid, incrementing the old high bid by one.
return new Bid(50); //This returns a bid for $50 over the current maximum bid

[edit] trade

Trade is called when you recieve a trade update. It passes to you a GameStatus, the details of the trade stored in the <a href="edu/bsu/monopoly/game/trade/Trade.html">Trade</a> class, a <a href="edu/bsu/monopoly/game/player/TradePlayer.html">TradePlayer</a> representing yourself and a <a href="edu/bsu/monopoly/game/trade/TradePlayerList.html"> TradePlayerList</a> storing other players. There are several important points to remember when working on your Trade logic. The first is the function will get called in response to your own trade updates so make sure and check trade.lastTradeMine() before doing any logic. Secondly you will want to familiarize yourself with the functions in the Trade class because due to the nature of trades in Monopoly it is a bit more complex than some of the other structures you've had to work with. Note that TradeTerm, as an interface, is implemented by both PropertyTrade and CashTrade. A single Trade can represent multiple trades between two or more players so you will need to find a way to parse through the TradeTerms and determine if you want to accept, reject or modify the offer.

[edit] Using the Client

This section will cover how to use the client to connect to a server, load an AI and play the game.

Welcome to the MonopdAI client
<img src="howto/6.png">

The first thing you'll want to do is to connect to a server. Click the Connect dialog and this window pops up
<img src="howto/7.png">

From here you can pick from a pre-existing list of servers, add your own server or search. Additionally you need to input the port (default is 1234) and what name you want to appear as. Next you'll see the main window.
<img src="howto/8.png">

Now you need to figure out if you are going to create the game or join an already existing game. When creating a game go to this window and select the game type. The default that everyone is used to is "city".
<img src="howto/9.png">

Next a window will appear with other options for the game. Select which ones you want and continue onwards.
<img src="howto/10.png">

When joining an already existing game click "Join Game..." This will show a list of what games are currently open.
<img src="howto/11.png">

From here you load an AI. Click the "Load AI..." button and navitgate to the AI script file. This will also compile it and it is at this time that any compilation errors will appear.
<img src="howto/12.png">

Now if you created the game, once you see all the players are in the game click "Start Game" and the game will start. You can see the current money stores of each player beside their names in the name list, as shown here.
<img src="howto/13.png">

Congratulations, you've started your first game of monopd with the aimonopd client. Now have fun and good luck at making the best script you can! </body></html>

Personal tools