*********************************************************************** ** ** ** AI - Buy Property ** ** ** *********************************************************************** public void AI_buy (int position, player_id) { get cash; if (cash > property_value) { if (position < free_parking) { if (((cash - prop_cost) >= 100) || player owns other properties of that color || another player owns other properties of that color) buy; else if ((position > free_parking) && (position < go_to_jail)) if (((cash - prop_cost) >= 25) || player owns other properties of that color || another player owns other properties of that color) buy; else if ((position > go_to_jail) && ((cash - prop_cost) >= 0)) buy; } } } *********************************************************************** ** ** ** AI - Buy House or Hotel ** ** ** *********************************************************************** public void AI_buy_house_hotel (int player_id, int position) { if (property is monopoly) get property_value for that monopoly; if (num_houses == 4) { get cash; if (cash - hotel_cost > 0) buy_hotel(); num_hotel++; } if (num_houses < 4) { get cash; if (cash - house_cost > 0) { buy_house(); num_house++; } } } *********************************************************************** ** ** ** AI - In jail trying to get out ** ** ** *********************************************************************** public void AI_jailed (int player_id) { if (in_jail == TRUE) { if (get_out_of_jail_card > 0) { in_jail = FALSE; try = 0; } if ((cash > 50) || (try == 3)) { cash = cash - 50; in_jail = FALSE; try = 0; } else { if (try < 3) { roll(); if (roll() == doubles) { in_jail = FALSE; roll(); try = 0; } else try++; } if (try == 3) { do_mortgage(); cash = cash - 50; in_jail = FALSE; try = 0; } } } } *********************************************************************** ** ** ** AI - User Offers Trade to AI ** ** ** *********************************************************************** public void AI_they_trade (int player_id, int position, int amount) { if (position is monopoly) decline trade; else if (amount < property_value) decline trade; else if ((amount >= (property_value + 25)) && (position < free_parking)) trade; else if ((amount >= (property_value + 75)) && (position > free_parking)) trade; else decline trade; } *********************************************************************** ** ** ** AI - Offers Trade to User ** ** ** *********************************************************************** public void AI_we_trade (int player_id, int position) { get random number between 0-3; if (number == 1) { check for 50% of a monopoly; get cash; find position of property we need; check user for that position; for (random number between 1 - 3) if ((position_owner != NULL) && (cash - (property_value + (.15 * value)) > set_amount)) offer trade with property_value + 15%; } } *********************************************************************** ** ** ** AI - Lifting Mortgages ** ** ** *********************************************************************** public void AI_lift_mortgage (int amount) { access AI's mortgage record for (mortgaged properties) if ((cash - mortgage_amount) > set_amount) pay mortgage; } *********************************************************************** ** ** ** AI - Inherits User's Property and Must Decide When to Pay for it ** ** ** *********************************************************************** public void AI_inherit (int mortgage_amount) { if (cash > (prop_principal + 300)) pay principal; else cash = cash - (mortgage_amount * .10); } *********************************************************************** ** ** ** AI - Mortgaging Property ** ** ** *********************************************************************** public void AI_do_mortgage (int owed_amount) { if (prop_owned == 0 || property_not_mortgaged == 0) return; int total = 0; int property_position[28]; // owned by AI int house_position[28]; int hotel_position[28]; while (AI owns property && property not a monopoly) { if (mortgagevalue(position_of_property) >= owed_amount) mortgage(position_of_property); else { property_position[] = position_of_property; total = total + mortgagevalue(position_of_property); if (total >= owed_amount) { for ( all elements in property_position[] ) mortgage(position_of_property); } } } // end while while (AI owns property && property = monopoly) { Start at lowest properties and mortgage monopolys with no buildings if (price_of_house(position_of_property) * # of houses + total >= owed_amount) { sell_all_houses(position_of_property); for (all property_position[]) mortgage(position_of_property); } else if (price_of_hotel(position_of_property) + total >= owed_amount) { sell_hotel(position_of_property); for (all property_position[] && all house_position[]) { mortgage(position_of_property); sell_all_houses(position_of_property); } } Once all houses/hotels sold on particular monopoly, check to mortgage those properties before continuing to next monopoly. } //end while } //end function *********************************************************************** ** ** ** AI - Auction ** ** ** *********************************************************************** public int AI_auction (int position, int highest_bid)\ { if (cash > highest_bid + 20) { if (property completes monopoly) return highest_bid + 20; else if ((position > free_parking < go_to_jail) && highest bid <= 2*proprty_value) return highest_bid +5; else if ((position > go_to_jail < go) && highest_bid <= 2*property_value) return highest_bid + 10; } }