- Inherits From:
- NSObject
- Conforms To:
- ICPlayerProtocol
- NSCoding
- Declared In:
- ICPlayer.h
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.
Player InfoGame Play - Subclasses must override these methods
- - initWithName:andColor:
- - name
- - color
Countries
- - pickCountry
- - assignInitialArmies
- - assignArmiesFromIncome
- - assignArmiesFromConquer
- - advanceArmiesFrom:to:
- - fortifyArmiesFrom:
- - attack
- - fortify
Cards
- - countries
- - destinationCountries
Statistics
- - cards
- - pickCardsToTurnIn
- - bestCardsToTurnIn
- - takeCard:
- - takeCardsFrom:
- - turnInCards:
- - hasWonThisTurn
Accessors
- - income
- - armies
- - countriesCount
- - cardsCount
- - type
- - victories
- - defeats
- - takeVictory:
- - takeDefeat:
- - country:wasAttackedBy:
- - game
- - gameController
- - otherPlayers
- - isComputer
- - unallocatedArmies
- - unallocatedInitialArmies
- (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];
- (int)armies
The total number of armies owned, for display in the statistics.
- (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];
- (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];
- (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
- (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.
- (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.
- (NSMutableArray *)cards
The player's cards.
- (int)cardsCount
The number of cards, for display in the statistics.
- (NSColor *)color
The player's color.
- (NSMutableArray *)countries
The countries owned by the current player.
- (int)countriesCount
The number of countries owned, for display in the statistics.
- (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.
- (int)defeats
The number of times the player has lost a country, for display in the statistics.
- (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]
).
- (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];
- (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];
- (ICGame *)game
The game object, which controls the game state.
- (id <ICGameControllerProtocol>)gameController
The game controller object, which handles the interface.
- (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.
- (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.
- (id)initWithName:(NSString *)newName andColor:(NSColor *)newColor
Initializes the player with the given name and color.
- (BOOL)isComputer
Returns whether the player is a computer player. You should not override this method.
- (NSString *)name
The player's name.
- (NSMutableArray *)otherPlayers
Returns all the players in the game except the current player.
- (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]];
- (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];
- (void)takeCard:(ICCard *)card
Adds card to the player's cards.
- (void)takeCardsFrom:(ICPlayer *)loser
Takes all the cards from loser. Called when the player conquers the last country belonging to loser.
- (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.
- (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.
- (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.
- (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.
- (int)unallocatedArmies
The number of armies that the player should place right now.
- (int)unallocatedInitialArmies
The number of armies that the player has left to place at the beginning of the game.
- (int)victories
The number of times the player has conquered a country, for display in the statistics.