ICPlayer


Inherits From:
NSObject
Conforms To:
ICPlayerProtocol
NSCoding
Declared In:
ICPlayer.h


Class Description

ICPlayer is an abstract superclass that represents a player in iConquer.

All players are identified in the game by a unique name and color.

The countries array stores a list of all the countries the player owns. The cards array stores a list of all the cards in the player's hand.

You can implement computer strategies by subclassing ICComputerPlayer class, which is itself a subclass of ICPlayer. All methods in the Game Play section below must be overridden by your subclass. These methods define your player's strategies for picking countires, placing armies, attacking, and fortifying.


Method Types

Player Info
- initWithName:andColor:
- name
- color
Game Play - Subclasses must override these methods
- pickCountry
- assignInitialArmies
- assignArmiesFromIncome
- assignArmiesFromConquer
- advanceArmiesFrom:to:
- fortifyArmiesFrom:
- attack
- fortify
Countries
- countries
- destinationCountries
Cards
- cards
- pickCardsToTurnIn
- bestCardsToTurnIn
- takeCard:
- takeCardsFrom:
- turnInCards:
- hasWonThisTurn
Statistics
- income
- armies
- countriesCount
- cardsCount
- type
- victories
- defeats
- takeVictory:
- takeDefeat:
- country:wasAttackedBy:
Accessors
- game
- gameController
- otherPlayers
- isComputer
- unallocatedArmies
- unallocatedInitialArmies

Instance Methods

advanceArmiesFrom:to:

- (void)advanceArmiesFrom:(ICCountry *)attackingCountry to:(ICCountry *)conqueredCountry

Allows the player to decide how to advance armies after winning a battle.

Computer players must override this method, placing armies in either attackingCountry or conqueredCountry until unallocatedArmies is zero. Always invoke the superclass. For example:     
    
    [super advanceArmiesFrom: attackingCountry to: conqueredCountry];
    [self allocateArmiesRandomly];


armies

- (int)armies

The total number of armies owned, for display in the statistics.


assignArmiesFromConquer

- (void)assignArmiesFromConquer

Tells the player to assign armies because they have eliminated a player and acquired at least five cards.

Computer players must override this method, placing armies in any of the player's countries until unallocatedArmies is zero. Always invoke the superclass. For example:     
    
    [super assignArmiesFromConquer];
    [self allocateArmiesRandomly];


assignArmiesFromIncome

- (void)assignArmiesFromIncome

Tells the player to assign armies from their income at the beginning of the turn. This is the player's signal that it is now their turn to play.

Computer players must override this method, placing armies in any of the player's countries until unallocatedArmies is zero. Always invoke the superclass. For example:     
    
    [super assignArmiesFromIncome];
    [self turnInCardsIfPossible]; // optional
    [self allocateArmiesRandomly];


assignInitialArmies

- (void)assignInitialArmies

Tells the player to place initial armies at the beginning of the game. This message will be sent to each player four times, and each time they will be given five armies (for a total of twenty initial armies).

Computer players must override this method, placing armies in any of the player's countries until unallocatedArmies is zero. Always invoke the superclass. For example:     
    
    [super assignInitialArmies];
    [self allocateArmiesRandomly]; // defined in ICComputerPlayer
    [game updateStatistics]; // always update statistics last


attack

- (void)attack

Sent to computer players when they should attack.

Computer players must override this method. The player should try to conquer one country, and should return if successful. This message will be sent repeatedly by the game timer, allowing the player to conquer as many countries as they can. When the player is finished attacking, send the fortify message to game.


bestCardsToTurnIn

- (NSArray *)bestCardsToTurnIn

Returns the best cards that this player can turn in. When picking cards of a given suit, prefers cards whose countries are owned by the player so they can get extra armies. Will only use wild cards when necessary, so they can be used later.


cards

- (NSMutableArray *)cards

The player's cards.


cardsCount

- (int)cardsCount

The number of cards, for display in the statistics.


color

- (NSColor *)color

The player's color.


countries

- (NSMutableArray *)countries

The countries owned by the current player.


countriesCount

- (int)countriesCount

The number of countries owned, for display in the statistics.


country:wasAttackedBy:

- (void)country:(ICCountry *)victimCountry wasAttackedBy:(ICCountry *)attackingCountry

This message is sent whenever one of the player's countries is attacked (each time the dice are rolled). ICPlayer has an empty implementation. Subclasses can override this method to keep track of how many times they are attacked. By contrast, takeDefeat: is called whenever the player loses a country.


defeats

- (int)defeats

The number of times the player has lost a country, for display in the statistics.


destinationCountries

- (NSMutableArray *)destinationCountries

The countries in which the player may place armies. When placing armies at the beginning of a game or turn, this value is set to all the player's countries. When fortifying, it is set to the current country and its adjacent countries. And when advancing after an attack, it is set to the attacking and conquered countries.

This array is set on your behalf by ICPlayer's assignInitialArmies, assignArmiesFromIncome, assignArmiesFromConquer, advanceArmiesFrom:to:, and fortifyArmiesFrom: methods. Subclass implementations of these methods must begin with a call to super (for example, [super assignInitialArmies]).


fortify

- (void)fortify

Sent to computer players when they should fortify.

Computer players must override this method. The player may fortify armies from any of its countries. For example:     
    
    [super fortify];
    [self fortifyVulnerableCountries];
    [game done];


fortifyArmiesFrom:

- (void)fortifyArmiesFrom:(ICCountry *)country

Called when a player decides to fortify armies from a country. Computer players may receive this message from the ICComputerPlayer method fortifyVulnerableCountries.

Computer players must override this method, placing armies in country or any of its neighbors until unallocatedArmies is zero. Always invoke the superclass. For example:     
    
    [super fortifyArmiesFrom: country];
    [self allocateArmiesRandomly];


game

- (ICGame *)game

The game object, which controls the game state.


gameController

- (id <ICGameControllerProtocol>)gameController

The game controller object, which handles the interface.


hasWonThisTurn

- (BOOL)hasWonThisTurn

Returns whether the player has won this turn. This method is used to determine whether the player should receive a card at the end of the turn.


income

- (int)income

The number of armies that the player gets at the beginning of each turn. Starts with 3 or the number of owned countries divided by three, whichever is higher. Then, each whole continent owned provides an additional bonus.


initWithName:andColor:

- (id)initWithName:(NSString *)newName andColor:(NSColor *)newColor

Initializes the player with the given name and color.


isComputer

- (BOOL)isComputer

Returns whether the player is a computer player. You should not override this method.


name

- (NSString *)name

The player's name.


otherPlayers

- (NSMutableArray *)otherPlayers

Returns all the players in the game except the current player.


pickCardsToTurnIn

- (void)pickCardsToTurnIn

Called when a player will turn in cards.

Computer players may override this method. The default implementation in ICComputerPlayer turns in the best possible cards:     
    
    [self turnInCards: [self bestCardsToTurnIn]];


pickCountry

- (void)pickCountry

Tells the player to pick a country.

Computer players must override this method, sending the pick message to one country in [game unallocatedCountries]. For example:     
    
    [[[game unallocatedCountries] randomObject] pick];


takeCard:

- (void)takeCard:(ICCard *)card

Adds card to the player's cards.


takeCardsFrom:

- (void)takeCardsFrom:(ICPlayer *)loser

Takes all the cards from loser. Called when the player conquers the last country belonging to loser.


takeDefeat:

- (void)takeDefeat:(ICCountry *)country

Called after the player loses country to another player. Increments the number of defeats. When this method is called, country has already been transferred to the winning player.


takeVictory:

- (void)takeVictory:(ICCountry *)country

Called after the player conquers country. Increments the number of victories, and notes that the player has won this turn. When this method is called, country still belongs to the losing player.


turnInCards:

- (void)turnInCards:(NSArray *)cards

Turns in someCards in exchange for a number of armies. Called when it's the player's turn and they have five or more cards. Also called by ICComputerPlayer's turnInCardsIfPossible, which can be called when placing armies from income.


type

- (NSString *)type

The localized name of the player type, for display in the statistics. Returns the !CFBundleName value from the player bundle's InfoPlist.strings file.


unallocatedArmies

- (int)unallocatedArmies

The number of armies that the player should place right now.


unallocatedInitialArmies

- (int)unallocatedInitialArmies

The number of armies that the player has left to place at the beginning of the game.


victories

- (int)victories

The number of times the player has conquered a country, for display in the statistics.


Version 1.1 Copyright ©2003 by KavaSoft. All Rights Reserved.