|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object
|
+--au.com.solidsoftware.multimahjong.mmc.game.Player
|
+--au.com.solidsoftware.multimahjong.mmc.co.ComputerOpponent
SRS : CO level 2.0 + 1 Level 3 requirement (4.5.10)
This class is the brain of Computer Opponent (CO). That is to determine what kind of move Computer Opponent should make. If CO makes a move, what tile(s) associated with that move.
All the moves that CO can make are encapsulated into 3 public methods:
| Field Summary | |
private java.util.Vector |
allCombSet
contains ALL possible combinations in CO' concealedhand |
private java.util.Vector |
allGroupSet
A group is a set of combinations that are mutual exclusive (can't be kept in concaled hand at the same time). |
private AITile[] |
concealedHand
concealedHand of CO. |
private java.util.Vector |
conSinSet
From attribute allGroupSet above, pick discard tile that generate less number of singles |
private static int |
FALSE
|
private java.util.Vector |
halfSinSet
contains all half (i.e. |
private static int |
MAXORDINARYSUITS
Number of ordinary suits |
private static int |
MAXTILENUMBER
Biggest number that an ordinary tile can have |
private static int |
MAXTILES
Maximum number of tiles in Chinese Mahjong |
private int |
playerId
each player has an unique Id which can be 0, 1, 2, 3 |
private java.lang.String |
playerName
name of player |
private boolean |
selected
any tile has been selected for a move |
private static int |
TRUE
|
private java.util.Vector |
unSinSet
contains all unconditional (i.e. |
| Fields inherited from class au.com.solidsoftware.multimahjong.mmc.game.Player |
CHOW2DOWN,
CHOW2SIDES,
CHOW2UP,
DECLARED_KONG,
DISCARD,
EAST,
EITHER_MOVE,
EXTEND_PUNG,
icon,
isFishing,
KONG,
MAHJONG,
name,
NO_MOVE,
NORTH,
NOT_ROBBED,
payout,
PICKUP,
playArea,
playerHand,
playerId,
PUNG,
ROBBED_KONG,
score,
selectedTile,
SOUTH,
standingHand,
userGUI,
WEST,
wind,
WONT_ROB |
| Constructor Summary | |
ComputerOpponent(java.lang.String name,
javax.swing.ImageIcon icon,
int score,
int playerId)
inits its base class Human. |
|
| Method Summary | |
private void |
allPossibleCombsForCombSet()
Uses result in the FIRST PASS. |
private boolean |
areTheyMu(AITile[] comb1,
AITile[] comb2)
Checks for mutual exclusive combinations. |
private java.util.Vector |
depthFirstFilter(AITile[] headNode,
java.util.Vector curGroupClone)
Picks the most optimal arrangement for mutual exclusive combinations. |
int |
determineCanRob(Tile selectedTile)
Tries to find if player can rob the kong. |
private boolean |
finalChecking(Tile tile,
Tile[] humanConcealedHand)
Checks whether a tile exists in concealed hand or not. |
private AITile[] |
fromHumantoAIConcealedHand(Tile[] humanConcealedHand)
Converts human style concealedHand to CO style concealedHand. |
private void |
getAllCombSet()
Detects all possible combinations in concaledHand. |
private void |
getAllGroupSet()
Bases on pre-genrated allCombSet to detect group of exclusive combinations. |
private java.util.Vector |
getAllMuCombFor(AITile[] comb,
java.util.Vector allCombSetClone)
Gets all mutual exclusive combinations of a given combination. |
private void |
getCombFor(int curPos)
Compares a tile with the remaining tiles in concaledHand and see whether that tile can combine with any tile or not. |
private void |
getConSinSet()
Extracts an optimum tile for discard from allGroupSet. |
private java.util.Vector |
getConSinTilesFromGroup(java.util.Vector curGroup)
Genrates all possible arrangements of mutual combinations in a group. |
int |
getDiscard(boolean playerFishing,
Moves currentMove)
Analyses computer opponent' concealed hand and selects the most optimal tile for discard. |
private void |
getHalfSinSet()
Detects all half (50%) single tiles in concealed hand. |
private void |
getMinConSinsForConSinSet()
Bases on result of FIRST PASS of conSinSet, keep optial conditional singles and remove non-optimal singles from conSinSet. |
int |
getPlayerSelection(Tile lastDiscard,
int next)
Tries to steal other player' tile. |
private void |
getUnSinSet()
Detects all unconditional (100%) single tiles in concealed hand . |
private void |
insertStack(java.util.Vector stack,
AITile[] node)
Adds new element to the head of stack. |
private void |
insertStackPath(java.util.Vector stackPath,
java.util.Vector path)
Adds new element to the head of stack. |
private int |
isContainedIn(AITile tile,
AITile[] comb)
Checks whether a tile is contained in a combination or not. |
private AITile[] |
isDuplicated(AITile examedTile,
java.util.Vector allCombSetClone)
Compares a given tile with tiles in all combinations in allCombSetClone. |
private boolean |
isHalfSingle(AITile tile)
Compares a tile with the remaining tiles in concaledHand and see whether that tile can combine with any tile or not. |
private boolean |
isNodeInPath(AITile[] node,
java.util.Vector path)
Checks whether a node (combination) is covered by a path (arrangement) |
private boolean |
isSingle(AITile tile)
Compares a tile with the remaining tiles in concaledHand and see whether that tile can combine with any tile or not. |
private int |
tilesNotCoveredByPath(java.util.Vector path,
java.util.Vector conSins,
java.util.Vector curGroupClone)
Checks whether any tile in a group not covered by the given path (given arrangement). |
private AITile[] |
vectorToArray(java.util.Vector combList)
Convert Vector list of combinations to array list of combinations. |
| Methods inherited from class au.com.solidsoftware.multimahjong.mmc.game.Player |
checkFishing,
checkKong,
checkMahjong,
checkPung2Kong,
declareKong,
discard,
findKong,
findPung2Kong,
getIcon,
getId,
getName,
getScore,
getWind,
initPlayer,
insertTile,
insertTile,
isStandingHand,
mahjong,
notStandingHand,
robbedKong,
runChow,
runKong,
runMahjong,
runPung,
runPung2Kong,
setIcon,
setMove,
setName,
setPlayArea,
setPlayArea,
setScore,
setSelection,
setWind |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
private static final int FALSE
private static final int TRUE
private static final int MAXTILES
private static final int MAXORDINARYSUITS
private static final int MAXTILENUMBER
private java.util.Vector unSinSet
private java.util.Vector halfSinSet
private java.util.Vector allCombSet
private java.util.Vector allGroupSet
private java.util.Vector conSinSet
private AITile[] concealedHand
private int playerId
private java.lang.String playerName
private boolean selected
| Constructor Detail |
public ComputerOpponent(java.lang.String name,
javax.swing.ImageIcon icon,
int score,
int playerId)
| Method Detail |
private AITile[] fromHumantoAIConcealedHand(Tile[] humanConcealedHand)
humanConcealedHand - Concealed hand withoud Id
public int getDiscard(boolean playerFishing,
Moves currentMove)
playerFishing - True if a player is fishing, otherwise false.currentMove - Storage for players selected move.
private boolean finalChecking(Tile tile,
Tile[] humanConcealedHand)
tile - Selected tile for discardhumanConcealedHand - Concealed hand without Idpublic int determineCanRob(Tile selectedTile)
selectedTile - Tile chosen to be revealed as a kong.
public int getPlayerSelection(Tile lastDiscard,
int next)
lastDiscard - The most recent discarded tile from other playernext - Flag that indicates whether this player can draw
tile from Wall (i.e. only true when it is CO' turn).private void getUnSinSet()
none - private boolean isSingle(AITile tile)
tile - Examed tile that has a unique Idprivate void getHalfSinSet()
none - private boolean isHalfSingle(AITile tile)
tile - Examed tile that has a unique Idprivate void getAllCombSet()
none - private void getCombFor(int curPos)
curPos - Position of the tile that is to get combinations for.private void allPossibleCombsForCombSet()
none -
private int isContainedIn(AITile tile,
AITile[] comb)
tile - Tile to be checkedcomb - Combination that is used for checkingprivate void getAllGroupSet()
none -
private java.util.Vector getAllMuCombFor(AITile[] comb,
java.util.Vector allCombSetClone)
comb - Combination that is to get all of its mutual exclsuive
combination.allCombsetClone - Clone of class attribute allCombSet
private AITile[] isDuplicated(AITile examedTile,
java.util.Vector allCombSetClone)
examedTile - Tile to examallCombsetClone - Clone of class attribute allCombSet
private boolean areTheyMu(AITile[] comb1,
AITile[] comb2)
comb1 - Combination 1comb2 - Combination 2private void getConSinSet()
none - private void getMinConSinsForConSinSet()
none - private java.util.Vector getConSinTilesFromGroup(java.util.Vector curGroup)
curGroup - Current group to be examed
private java.util.Vector depthFirstFilter(AITile[] headNode,
java.util.Vector curGroupClone)
headNode - HeadNode of tree. This tree contains all possible
arrangements while keeping the headNode.curGroupClone - Clone of pre-computed allGroupet
private int tilesNotCoveredByPath(java.util.Vector path,
java.util.Vector conSins,
java.util.Vector curGroupClone)
path - Is a arrangement of non-mutual exlcusive combinationsconSins - Conditional singlescurGroupClone - Clone of pre-computed allGroupetprivate AITile[] vectorToArray(java.util.Vector combList)
combList - A vector of combinations
private boolean isNodeInPath(AITile[] node,
java.util.Vector path)
node - Is a combination of tilespath - Is a arrangement of non-mutual exlcusive combinations
private void insertStack(java.util.Vector stack,
AITile[] node)
stack - Contains nodes that are not yet process by deep firstnode - Is a combination of tiles
private void insertStackPath(java.util.Vector stackPath,
java.util.Vector path)
stackPath - Contains paths that should not be re-processed by
deep first search.path - Is a arrangement of non-mutual exlcusive combinations
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||