public class BoardHelper
extends java.lang.Object
The majority of the methods in this class require a final parameter of Country[] countries. If the method calls for countries, do not attempt to pass in anything less than the entire board. Failure to do so will result in undefined behavior.
There are three groups of methods in this class: Those that return information about the state of the game, those that return information about the state of the board layout, and those that return paths between countries and/or continents.
Have fun.
Constructor and Description |
---|
BoardHelper() |
Modifier and Type | Method and Description |
---|---|
static boolean |
anyPlayerOwnsContinent(int continent,
Country[] countries)
Checks whether or not any player fully owns continent.
|
static int[] |
cheapestRouteFromOwnerToCont(int owner,
int continent,
Country[] countries)
This method will return an array of country-codes consisting of the
cheapest route between a country owned by owner and the
continent.
|
static Country |
closestCountryWithOwner(Country CC,
int owner,
Country[] countries)
Find the closest country to CC that is owned by owner.
|
static int |
closestCountryWithOwner(int CC,
int owner,
Country[] countries)
Find the closest country to CC that is owned by owner.
|
static int |
closestCountryWithOwner(java.util.List startingCountryList,
int owner,
Country[] countries)
Find the closest country to a country in startingCountryList that is owned by owner.
|
static Country[] |
easyCostBetweenCountries(Country CCF,
Country CCT,
Country[] countries)
This method finds the easyest path from country CCF (CCFrom) to
CCT (CCTo), that doesn't cross a country owned by CCF's owner.
|
static int[] |
easyCostBetweenCountries(int CCF,
int CCT,
Country[] countries)
This method finds the easyest path from country CCF (CCFrom) to
CCT (CCTo), that doesn't cross a country owned by CCF's owner.
|
static Country[] |
easyCostCountryWithOwner(Country CC,
int owner,
Country[] countries)
This method searches for the country owned by owner that has the
easiest path to get to country CC.
|
static int[] |
easyCostCountryWithOwner(int CC,
int owner,
Country[] countries)
This method searches for the country owned by owner that has the
easiest path to get to country CC.
|
static Country[] |
easyCostFromCountryToContinent(Country CCF,
int continent,
Country[] countries)
This method returns a Country[] containing a list from country CCF
to some country in continent, along the easiest path.
|
static int[] |
easyCostFromCountryToContinent(int CCF,
int continent,
Country[] countries)
This method returns an int[] containing a list from country CCF
to some country in continent, along the easiest path.
|
static Country[] |
friendlyPathBetweenCountries(Country CF,
Country CT,
Country[] countries)
This method finds the shortest path (in terms of countries) from
country CF (CFrom) to CT (CTo), that ONLY goes through
countries owned by CF's owner.
|
static int[] |
friendlyPathBetweenCountries(int CCF,
int CCT,
Country[] countries)
This method finds the shortest path (in terms of countries) from
country CCF (CCFrom) to CCT (CCTo), that ONLY goes through
countries owned by CCF's owner.
|
static int[] |
getAttackList(Country target,
Country[] countries)
Get the list of countries that can attack the target.
|
static int[] |
getContinentBorders(int continent,
Country[] countries)
This method returns an array of countryCodes of the border countries
of continent.
|
static int[] |
getContinentBordersBeyond(int continent,
Country[] countries)
This method returns an array of countryCodes of the border countries
outside the requested continent.
|
static int |
getContinentSize(int continent,
Country[] countries)
Returns the number of countries in continent.
|
static Country[] |
getCountriesCopy(Country[] countries)
Create a copy of the countries array, for simulation.
|
static int |
getCountryInContinent(int continent,
Country[] countries)
Returns the code of a country inside continent.
|
static int[] |
getDefensibleBorders(int continent,
Country[] countries)
Get the defensible borders of a continent - those that can be used to attack the continent.
|
static int[] |
getDefensibleBordersBeyond(int continent,
Country[] countries)
Get the countries beyond the defensible borders of a continent - those that can be used to attack the continent.
|
static int |
getEnemyArmiesInContinent(int player,
int continent,
Country[] countries)
this method calculates the number of armies owned by anyone who is NOT
player in continent.
|
static int |
getPlayerArmies(int player,
Country[] countries)
This method calculates the total number of armies owned by player.
|
static int |
getPlayerArmiesAdjoiningContinent(int ID,
int cont,
Country[] countries)
Get the number of armies owned by the player that are in countries that directly adjoin the given continent.
|
static int |
getPlayerArmiesInContinent(int player,
int continent,
Country[] countries)
This method calculates the number of armies owned by player in
continent.
|
static int |
getPlayerCountries(int player,
Country[] countries)
This method calculates the number of countries owned by player.
|
static Country |
getPlayersBiggestArmy(int player,
Country[] countries)
Returns the country owned by player with the most armies on it.
|
static Country |
getPlayersBiggestArmyWithEnemyNeighbor(int player,
Country[] countries)
Same as getPlayersBiggestArmy() except it will return the biggest army that has at least one enemy neighbor.
|
static int |
getSmallestEmptyCont(Country[] countries)
Returns the cont-code of the smallest continent that is totally empty, or
-1 if there are no unowned conts.
|
static int |
getSmallestOpenCont(Country[] countries)
Returns the cont-code of the smallest continent that has at least one
unowned country.
|
static int |
getSmallestPositiveEmptyCont(Country[] countries,
Board board)
This method is the same as getSmallestEmptyCont() except it only
considers continents that have bonus values of greater than zero.
|
static int |
getSmallestPositiveOpenCont(Country[] countries,
Board board)
This method is the same as getSmallestOpenCont() except it only considers
continents that have a bonus of greater than zero.
|
static int |
numberOfContinents(Country[] countries)
Returns the number of continents.
|
static boolean |
playerIsStillInTheGame(int player,
Country[] countries)
This method checks if player still owns any countries.
|
static boolean |
playerOwnsAnyContinent(int player,
Country[] countries)
This method simply determines if player owns any full continents.
|
static boolean |
playerOwnsAnyPositiveContinent(int player,
Country[] countries,
Board board)
The same as playerOwnsAnyContinent() except it only considers continents with positive bonuses.
|
static boolean |
playerOwnsContinent(int player,
int continent,
Country[] countries)
This method simply determines if player owns all the countries
that are part of continent.
|
static boolean |
playerOwnsContinentCountry(int player,
int continent,
Country[] countries)
This method simply determines if player owns ANY of the countries
that are part of continent.
|
public static boolean anyPlayerOwnsContinent(int continent, Country[] countries)
The first country in the continent is checked for its owner, and then every additional country within the continent is inspected to see if the same player owns them. If so, true is returned. The moment it finds a country that is owned by a player other than the one found in the first country, false is returned.
To find the countries in the continents, it uses a ContinentIterator.
Warning: In the event that continent is invalid, the value returned is true, which is not sane.
continent
- the continent interested incountries
- the boardCountry
,
CountryIterator
,
ContinentIterator
public static int[] cheapestRouteFromOwnerToCont(int owner, int continent, Country[] countries)
This method uses a self-sorting queueing mechanism to determine the easiest path (in terms of enemy armies in the way) between a country owned by owner and a country found in continent. Starting with each country in continent, it enqueues and follows every path outwards from their neighbors (and their neighbors, and so on), making note of the ownership of the neighbors and the number of armies, until it finds a path that terminates in any country owned by owner.
This method returns a list that contains the path. The list is simply an int array, each holding the next country code in line. Due to the method of enqueueing, the zero element of the array will be the country owned by owner that was found, while the last element of the array (the one with the highest value index) will be in continent.
Keep in mind that this method only takes into account the ownership of countries as it searches outwards, looking for any owned by owner.
If CCF is invalid, or if no paths are found, null is returned.
WARNING: This method will hard FAIL in maps that have one-way connections, like Arms Race.
owner
- the index of the interested playercontinent
- the index of the interested continentcountries
- the boardCountry
public static Country closestCountryWithOwner(Country CC, int owner, Country[] countries)
This method uses a self-sorting queueing mechanism to determine the closest country to CC that is owned by owner. Starting with CC, it enqueues and follows every path outwards from its neighbors (and their neighbors, and so on) until it finds a path that terminates in a country owned by the given owner. That Country object is returned. The actual path information is discarded. To capture the path, see easyCostCountryWithOwner.
If CC or owner is invalid, null is returned.
CC
- the interesting countryowner
- the index of the interesting playercountries
- the boardCountry
,
easyCostCountryWithOwner(com.sillysoft.lux.Country, int, com.sillysoft.lux.Country[])
public static int closestCountryWithOwner(int CC, int owner, Country[] countries)
This method uses a self-sorting queueing mechanism to determine the closest country to CC that is owned by owner. Starting with CC, it enqueues and follows every path outwards from its neighbors (and their neighbors, and so on) until it finds a path that terminates in a country owned by the given owner. The country code of that country is returned. The actual path information is discarded. To capture the path, see easyCostCountryWithOwner.
If CC is invalid, -1 is returned.
If owner is invalid, -2 is returned.
CC
- the country code of the interesting countryowner
- the index of the interesting playercountries
- the boardCountry
,
easyCostCountryWithOwner(com.sillysoft.lux.Country, int, com.sillysoft.lux.Country[])
public static int closestCountryWithOwner(java.util.List startingCountryList, int owner, Country[] countries)
This method uses a self-sorting queueing mechanism to determine the closest country to CC that is owned by owner. Starting with the countries in startingCountryList, it enqueues and follows every path outwards from their neighbors (and their neighbors, and so on) until it finds a path that terminates in a country owned by the given owner. The country code of that country is returned. The actual path information is discarded. To capture the path, see easyCostCountryWithOwner.
If CC is invalid, -1 is returned.
If owner is invalid, -2 is returned.
startingCountryList
- a List containing the counries to start searching fromowner
- the index of the interesting playercountries
- the boardCountry
,
easyCostCountryWithOwner(com.sillysoft.lux.Country, int, com.sillysoft.lux.Country[])
public static Country[] easyCostBetweenCountries(Country CCF, Country CCT, Country[] countries)
This method uses a self-sorting queueing mechanism to determine the easiest path (in terms of enemy armies) between CCF and CCT. Starting with CCF, it enqueues and follows every path outwards from its neighbors (and their neighbors, and so on), making note of the accumulation of enemy armies, until it finds a path that terminates in the desired country CCT
This method returns a list that contains the path. The list is simply an array of Country objects, each holding the next country in line. Due to the method of enqueueing, the zero element of the array will be country CCT that was found, while the last element of the array (the one with the highest value index) will be CCF.
Keep in mind that this method will take into account the ownership of intervening countries on the path returned. The path is guaranteed to detour around 'friendly' countries if possible.
If CCF is invalid, or if no paths are found because all paths are blocked by 'friendly' countries, null is returned.
CCF
- the country code of the from countryCCT
- the country code of the to countrycountries
- the boardCountry
,
closestCountryWithOwner(com.sillysoft.lux.Country, int, com.sillysoft.lux.Country[])
,
easyCostFromCountryToContinent(com.sillysoft.lux.Country, int, com.sillysoft.lux.Country[])
public static int[] easyCostBetweenCountries(int CCF, int CCT, Country[] countries)
This method uses a self-sorting queueing mechanism to determine the easiest path (in terms of enemy armies) between CCF and CCT. Starting with CCF, it enqueues and follows every path outwards from its neighbors (and their neighbors, and so on), making note of the accumulation of enemy armies, until it finds a path that terminates in the desired country CCT
This method returns a list that contains the path. The list is simply an int array, each holding the next country code in line. Due to the method of enqueueing, the zero element of the array will be country CCT, that was found, while the last element of the array (the one with the highest value index) will be CCF.
Keep in mind that this method will take into account the ownership of intervening countries on the path returned. The path is guaranteed to detour around 'friendly' countries if possible.
If CCF is invalid, or if no paths are found because all paths are blocked by 'friendly' countries, null is returned.
CCF
- the country code of the from countryCCT
- the country code of the to countrycountries
- the boardCountry
,
closestCountryWithOwner(com.sillysoft.lux.Country, int, com.sillysoft.lux.Country[])
,
easyCostFromCountryToContinent(com.sillysoft.lux.Country, int, com.sillysoft.lux.Country[])
public static Country[] easyCostCountryWithOwner(Country CC, int owner, Country[] countries)
This method uses a self-sorting queueing mechanism to determine the easiest path (in terms of enemy armies) between CC, and any one that is owned by owner. Starting with CC, it enqueues and follows every path outwards from its neighbors (and their neighbors, and so on), making note of the accumulation of enemy armies, until it finds a path that terminates in a country owned by the given owner.
This method returns a list that contains the path. The list is simply an array of Country objects, each holding the next country in line. Due to the method of enqueueing, the zero element of the array is the country with owner that was found, while the last element of the array will be CC.
If CC is owned by owner, an array of one length is returned, with CC at index [0].
If CC is invalid, or if no paths are found, null is returned.
Keep in mind that if you are trying to target a given player, and you own CC, this method does not take into account that you might also own one of the intervening countries on the path returned. Trying to attack a country that you own is not productive.
CC
- the country code of the interesting countryowner
- the index of the interesting playercountries
- the boardCountry
,
closestCountryWithOwner(com.sillysoft.lux.Country, int, com.sillysoft.lux.Country[])
public static int[] easyCostCountryWithOwner(int CC, int owner, Country[] countries)
This method uses a self-sorting queueing mechanism to determine the easiest path (in terms of enemy armies) between CC, and any one that is owned by owner. Starting with CC, it enqueues and follows every path outwards from its neighbors (and their neighbors, and so on), making note of the accumulation of enemy armies, until it finds a path that terminates in a country owned by the given owner.
This method returns a list that contains the path. The list is simply an int array, each holding the next country code in line. Due to the method of enqueueing, the zero element of the array is the country with owner that was found, while the last element of the array will be CC.
If CC is owned by owner, an array of one length is returned, with CC at index [0].
If CC is invalid, or if no paths are found, null is returned.
Keep in mind that if you are trying to target a given player, and you own CC, this method does not take into account that you might also own one of the intervening countries on the path returned. Trying to attack a country that you own is not productive.
CC
- the country code of the interesting countryowner
- the index of the interesting playercountries
- the boardCountry
,
closestCountryWithOwner(com.sillysoft.lux.Country, int, com.sillysoft.lux.Country[])
public static Country[] easyCostFromCountryToContinent(Country CCF, int continent, Country[] countries)
This method uses a self-sorting queueing mechanism to determine the easiest path (in terms of enemy armies) between CCF, and any one that is part of continent. Starting with CCF, it enqueues and follows every path outwards from its neighbors (and their neighbors, and so on), making note of the accumulation of enemy armies, until it finds a path that terminates in a country which is part of continent.
This method returns a list that contains the path. The list is simply an array of Country objects, each holding the next countryin line. Due to the method of enqueueing, the zero element of the array is the country in continent that was found, while the last element of the array (the one with the highest value index) will be CCF.
If CCF is part of continent, an array of length two is returned, with CC at index [1] and one of its neighbors at index [0].
If CCF is invalid, or if no paths are found, null is returned.
Keep in mind that this method will take into account the ownership of intervening countries on the path returned. The path is guaranteed to detour around 'friendly' countries.
CCF
- the country code of the interesting countrycontinent
- the index of the interesting continentcountries
- the boardCountry
,
closestCountryWithOwner(com.sillysoft.lux.Country, int, com.sillysoft.lux.Country[])
public static int[] easyCostFromCountryToContinent(int CCF, int continent, Country[] countries)
This method uses a self-sorting queueing mechanism to determine the easiest path (in terms of enemy armies) between CCF, and any one that is part of continent. Starting with CCF, it enqueues and follows every path outwards from its neighbors (and their neighbors, and so on), making note of the accumulation of enemy armies, until it finds a path that terminates in a country which is part of continent.
This method returns a list that contains the path. The list is simply an int array, each holding the next country code in line. Due to the method of enqueueing, the zero element of the array is the country in continent that was found, while the last element of the array (the one with the highest value index) will be CCF.
If CCF is part of continent, an array of length two is returned, with CC at index [1] and one of its neighbors at index [0].
If CCF is invalid, or if no paths are found, null is returned.
Keep in mind that this method will take into account the ownership of intervening countries on the path returned. The path is guaranteed to detour around 'friendly' countries.
CCF
- the country code of the interesting countrycontinent
- the index of the interesting continentcountries
- the boardCountry
,
closestCountryWithOwner(com.sillysoft.lux.Country, int, com.sillysoft.lux.Country[])
public static Country[] friendlyPathBetweenCountries(Country CF, Country CT, Country[] countries)
This method uses a self-sorting queueing mechanism to determine the shortest path (in terms of countries crossed) between CF and CT. Starting with CF, it enqueues and follows every path outwards from its neighbors (and their neighbors, and so on), making note of the ownership of the neighbors, until it finds a path that terminates in the desired country CT
This method returns a list that contains the path. The list is simply an array of Country objects, each holding the next country in line. The zero element of the array will be country CF, while the last element of the array (the one with the highest value index) will be CT.
Keep in mind that this method will take into account the ownership of intervening countries on the path returned. If a valid path is found, the path is guaranteed to only cross 'friendly' countries.
If CCF is invalid, or if no paths are found because all paths are blocked by 'enemy' countries, null is returned.
CF
- the from countryCT
- the to countrycountries
- the boardCountry
,
closestCountryWithOwner(com.sillysoft.lux.Country, int, com.sillysoft.lux.Country[])
,
easyCostFromCountryToContinent(com.sillysoft.lux.Country, int, com.sillysoft.lux.Country[])
public static int[] friendlyPathBetweenCountries(int CCF, int CCT, Country[] countries)
This method uses a self-sorting queueing mechanism to determine the shortest path (in terms of countries crossed) between CCF and CCT. Starting with CCF, it enqueues and follows every path outwards from its neighbors (and their neighbors, and so on), making note of the ownership of the neighbors, until it finds a path that terminates in the desired country CCT
This method returns a list that contains the path. The list is simply an int array, each holding the next country code in line. The zero element of the array will be country CCF, while the last element of the array (the one with the highest value index) will be CCT.
Keep in mind that this method will take into account the ownership of intervening countries on the path returned. The path is guaranteed to only cross 'friendly' countries if possible.
If CCF is invalid, or if no paths are found because all paths are blocked by 'enemy' countries, null is returned.
CCF
- the country code of the from countryCCT
- the country code of the to countrycountries
- the boardCountry
,
closestCountryWithOwner(com.sillysoft.lux.Country, int, com.sillysoft.lux.Country[])
,
easyCostFromCountryToContinent(com.sillysoft.lux.Country, int, com.sillysoft.lux.Country[])
public static int[] getAttackList(Country target, Country[] countries)
public static int[] getContinentBorders(int continent, Country[] countries)
This method first searches through all the countries looking for those which are part of continent. Once it has that list, it inspects each to determine what countries are adjacent. If any of the adjacent countries is part of a different continent, then the root country is added to a list of 'border' countries. Finally, it returns the list of border countries.
To find the countries in the continent, it uses a ContinentIterator.
In the event that continent is invalid, the value returned is a null list... or it throws a wobbly which is caught by the game engine, causing you to forfeit the remainder of the current phase.
continent
- the continent interested incountries
- the boardCountry
,
CountryIterator
,
ContinentIterator
public static int[] getContinentBordersBeyond(int continent, Country[] countries)
This method first searches through all the countries looking for those which are part of continent. Once it has that list, it inspects each to determine what countries are adjacent. If any of the adjacent countries is part of a different continent, then the adjacent country is added to a list of 'border' countries. Finally, it returns the list of border countries.
To find the countries in the continent, it uses a ContinentIterator.
In the event that continent is invalid, the value returned is a null list... or it throws a wobbly which is caught by the game engine, causing you to forfeit the remainder of the current phase.
Warning: This method has not been blessed. It was snuck in by the documentor.
continent
- the continent interested incountries
- the boardCountry
,
CountryIterator
,
ContinentIterator
public static int getContinentSize(int continent, Country[] countries)
This method first searches through all the countries looking for those which are part of continent. Once it has that list, it simply iterates over the list and increments a counter as it does so.
To find the countries in the continent, it uses a ContinentIterator.
In the event that continent is invalid, the value returned is zero.
continent
- the continent interested incountries
- the boardCountry
,
CountryIterator
,
ContinentIterator
public static Country[] getCountriesCopy(Country[] countries)
public static int getCountryInContinent(int continent, Country[] countries)
This method first searches through all the countries looking for those which are part of continent. Once it has that list, it simply iterates over the list and increments a counter as it does so.
To find the countries in the continent, it uses a ContinentIterator.
In the event that continent is invalid, the value returned is zero.
continent
- the continent interested incountries
- the boardCountry
,
CountryIterator
,
ContinentIterator
public static int[] getDefensibleBorders(int continent, Country[] countries)
public static int[] getDefensibleBordersBeyond(int continent, Country[] countries)
public static int getEnemyArmiesInContinent(int player, int continent, Country[] countries)
This method first searches through all the countries looking for those which are part of continent. Once it has that list, it inspects each to find out first if it is owned by player, and then adds the number of armies on it to a counter if not. The final value in the counter is what is returned.
To find the countries in the continent, it uses a ContinentIterator.
In the event that player is invalid, or is no longer in the game, the value returned is the total number of armies on the continent regardless of which player they belong to.
In the event that continent is invalid, the value returned is zero.
player
- the player interested incontinent
- the continent interested incountries
- the boardCountry
,
CountryIterator
,
ContinentIterator
public static int getPlayerArmies(int player, Country[] countries)
This method first searches through all the countries looking for those which are owned by player. Once it has that list, it inspects each to find out how many armies are on, and adds them together for a grand total.
To find the countries owned by player, it simply iterates over the entire board (ie, each Country in countries). It does not use a PlayerIterator.
In the event that player is invalid, or is no longer in the game, the value returned is zero.
player
- the player interested incountries
- the boardCountry
public static int getPlayerArmiesAdjoiningContinent(int ID, int cont, Country[] countries)
public static int getPlayerArmiesInContinent(int player, int continent, Country[] countries)
This method first searches through all the countries looking for those which are part of continent. Once it has that list, it inspects each to find out first if it is owned by player, and then adds the number of armies on it to a counter if so. The final value in the counter is what is returned.
To find the countries in the continent, it uses a ContinentIterator.
In the event that player is invalid, or is no longer in the game, the value returned is zero.
In the event that continent is invalid, the value returned is zero.
player
- the player interested incontinent
- the continent interested incountries
- the boardCountry
,
CountryIterator
,
ContinentIterator
public static int getPlayerCountries(int player, Country[] countries)
This method first searches through all the countries looking for those which are owned by player. As it finds them, it increments a value, which, when finished, is returned to the caller.
To find the countries owned by player, it simply iterates over the entire board (ie, each Country in countries). It does not use a PlayerIterator.
In the event that player is invalid, or is no longer in the game, the value returned is zero.
player
- the player interested incountries
- the boardCountry
,
CountryIterator
,
PlayerIterator
public static Country getPlayersBiggestArmy(int player, Country[] countries)
This method first searches through all the countries looking for those which are owned by player. Once it has that list, it inspects each to find out how many armies are on, and makes a note of whichever has the most.
To find the countries owned by player, it uses a PlayerIterator.
In the event that player is invalid, or is no longer in the game, the value returned is null.
player
- the player interested incountries
- the boardCountryIterator
,
PlayerIterator
public static Country getPlayersBiggestArmyWithEnemyNeighbor(int player, Country[] countries)
public static int getSmallestEmptyCont(Country[] countries)
This method first searches through all the continents and makes a note of the number of countries in each. The index of the one with the smallest number of countries, and which is totally unowned (ie, each country is owned by -1, the default at-map-creation-time non-player), is returned.
The method iterates over the entire board one continent at a time, checking for 'full' ownership by player -1. If none are found to be owned by the non-player, than -1 is returned.
countries
- the boardCountry
,
playerOwnsContinent(int, int, com.sillysoft.lux.Country[])
,
getContinentSize(int, com.sillysoft.lux.Country[])
public static int getSmallestOpenCont(Country[] countries)
This method first searches through all the continents and makes a note of the number of countries in each. The index of the one with the smallest number of countries, and which has at least one country owned by -1 (ie,the default at-map-creation-time non-player), is returned.
The method iterates over the entire board one continent at a time, checking for 'any' ownership by player -1. If the entire board is found to be owned by active players, than -1 is returned.
countries
- the boardCountry
,
playerOwnsContinentCountry(int, int, com.sillysoft.lux.Country[])
,
getContinentSize(int, com.sillysoft.lux.Country[])
public static int getSmallestPositiveEmptyCont(Country[] countries, Board board)
public static int getSmallestPositiveOpenCont(Country[] countries, Board board)
public static int numberOfContinents(Country[] countries)
This method first increments a counter, looking for a null return value from ContinentIterator. The value returned is the counter, less one.
countries
- the boardCountry
,
CountryIterator
,
ContinentIterator
public static boolean playerIsStillInTheGame(int player, Country[] countries)
This method first searches through all the countries looking for those which are owned by player. If it finds one, it immediatly stops looking and returns true. If no country is found with player as the owner, then it returns false.
To find a country owned by player, it simply iterates over the entire board (ie, each Country in countries). It does not use any type of Iterator.
In the event that player is invalid, or is no longer in the game, the value returned is the total number of armies on the continent regardless of which player they belong to.
In the event that player is invalid, or is no longer in the game, the value returned is false.
This method could be used to determine if any countries are unchosen during the initial selection process by passing in a -1 as the player. The use of the resulting information is dubious, at best, and other routines exist that are better suited to this use.
player
- the player interested incountries
- the boardCountry
,
playerOwnsContinentCountry(int, int, com.sillysoft.lux.Country[])
,
getSmallestOpenCont(com.sillysoft.lux.Country[])
,
getSmallestEmptyCont(com.sillysoft.lux.Country[])
public static boolean playerOwnsAnyContinent(int player, Country[] countries)
For each continent on the board, this method searches through all the countries in it, looking for any that are not owned by player. If it determines that a given continent is not fully owned by player, it moves on to the next. If at any time it determines that player owns a full continent, it returns true. If it runs through all the continents without finding one owned by player, it returns false.
To find the countries in the continents, it uses a ContinentIterator. It also uses this ContinentIterator to determine when there are no more continents to be checked.
In the event that player is invalid, or is no longer in the game, the value returned is false.
player
- the player interested incountries
- the boardCountry
,
CountryIterator
,
ContinentIterator
public static boolean playerOwnsAnyPositiveContinent(int player, Country[] countries, Board board)
public static boolean playerOwnsContinent(int player, int continent, Country[] countries)
This method first searches through all the countries looking for those which are part of continent. Once it has that list, it inspects each to find out first if it is not owned by player. If it finds any that are not, it returns false. If all the countries are successfully checked, then it returns true.
To find the countries in the continent, it uses a ContinentIterator.
In the event that player is invalid, or is no longer in the game, the value returned is the total number of armies on the continent regardless of which player they belong to.
In the event that player is invalid, or is no longer in the game, the value returned is false, which is sane.
Warning: In the event that continent is invalid, the value returned is true, which is not sane.
player
- the player interested incontinent
- the continent interested incountries
- the boardCountry
,
CountryIterator
,
ContinentIterator
public static boolean playerOwnsContinentCountry(int player, int continent, Country[] countries)
Each country in the continent is checked for its owner. If any country is owned by player, then true is returned. If all countries are checked and none are found to be owned by player, false is returned.
To find the countries in the continents, it uses a ContinentIterator.
In the event that either player or continent is invalid, or the player is no longer in the game, the value returned is false.
player
- the player interested incontinent
- the continent interested incountries
- the boardCountry
,
CountryIterator
,
ContinentIterator