Search in sources :

Example 11 with SOCSettlement

use of soc.game.SOCSettlement in project JSettlers2 by jdmonin.

the class SOCRobotBrain method placeFirstSettlement.

/**
 * place planned first settlement
 * @param firstSettlement  First settlement's node coordinate
 * @see #placeInitSettlement(int)
 */
protected void placeFirstSettlement(final int firstSettlement) {
    // D.ebugPrintln("BUILD REQUEST FOR SETTLEMENT AT "+Integer.toHexString(firstSettlement));
    pause(500);
    lastStartingPieceCoord = firstSettlement;
    client.putPiece(game, new SOCSettlement(ourPlayerData, firstSettlement, null));
    pause(1000);
}
Also used : SOCSettlement(soc.game.SOCSettlement)

Example 12 with SOCSettlement

use of soc.game.SOCSettlement in project JSettlers2 by jdmonin.

the class SOCRobotBrain method placeInitSettlement.

/**
 * Place planned initial settlement after first one.
 * @param initSettlement  Second or third settlement's node coordinate,
 *   from {@link OpeningBuildStrategy#planSecondSettlement()} or
 *   from {@link OpeningBuildStrategy#planThirdSettlement()};
 *   should not be -1
 * @see #placeFirstSettlement(int)
 */
protected void placeInitSettlement(final int initSettlement) {
    if (initSettlement == -1) {
        // This could mean that the server (incorrectly) asked us to
        // place another second settlement, after we've cleared the
        // potentialSettlements contents.
        System.err.println("robot assert failed: initSettlement -1, " + ourPlayerData.getName() + " leaving game " + game.getName());
        failedBuildingAttempts = 2 + (2 * MAX_DENIED_BUILDING_PER_TURN);
        waitingForGameState = false;
        return;
    }
    // D.ebugPrintln("BUILD REQUEST FOR SETTLEMENT AT "+Integer.toHexString(secondSettlement));
    pause(500);
    lastStartingPieceCoord = initSettlement;
    client.putPiece(game, new SOCSettlement(ourPlayerData, initSettlement, null));
    pause(1000);
}
Also used : SOCSettlement(soc.game.SOCSettlement)

Example 13 with SOCSettlement

use of soc.game.SOCSettlement in project JSettlers2 by jdmonin.

the class SOCRobotDM method getWinGameETABonus.

/**
 * add a bonus to the possible piece score based
 * on the change in win game ETA
 *
 * @param posPiece  the possible piece that we're scoring
 */
protected float getWinGameETABonus(final SOCPossiblePiece posPiece) {
    HashMap<Integer, SOCPlayerTracker> trackersCopy = null;
    SOCSettlement tmpSet = null;
    SOCCity tmpCity = null;
    // road or ship
    SOCRoad tmpRoad = null;
    float bonus = 0;
    D.ebugPrintln("--- before [start] ---");
    // SOCPlayerTracker.playerTrackersDebug(playerTrackers);
    D.ebugPrintln("our player numbers = " + ourPlayerData.getNumbers());
    D.ebugPrintln("--- before [end] ---");
    switch(posPiece.getType()) {
        case SOCPossiblePiece.SETTLEMENT:
            tmpSet = new SOCSettlement(ourPlayerData, posPiece.getCoordinates(), null);
            trackersCopy = SOCPlayerTracker.tryPutPiece(tmpSet, game, playerTrackers);
            break;
        case SOCPossiblePiece.CITY:
            trackersCopy = SOCPlayerTracker.copyPlayerTrackers(playerTrackers);
            tmpCity = new SOCCity(ourPlayerData, posPiece.getCoordinates(), null);
            game.putTempPiece(tmpCity);
            SOCPlayerTracker trackerCopy = trackersCopy.get(Integer.valueOf(ourPlayerNumber));
            if (trackerCopy != null) {
                trackerCopy.addOurNewCity(tmpCity);
            }
            break;
        case SOCPossiblePiece.ROAD:
            tmpRoad = new SOCRoad(ourPlayerData, posPiece.getCoordinates(), null);
            trackersCopy = SOCPlayerTracker.tryPutPiece(tmpRoad, game, playerTrackers);
            break;
        case SOCPossiblePiece.SHIP:
            tmpRoad = new SOCShip(ourPlayerData, posPiece.getCoordinates(), null);
            trackersCopy = SOCPlayerTracker.tryPutPiece(tmpRoad, game, playerTrackers);
            break;
    }
    // trackersCopyIter = trackersCopy.iterator();
    // while (trackersCopyIter.hasNext()) {
    // SOCPlayerTracker trackerCopy = (SOCPlayerTracker)trackersCopyIter.next();
    // trackerCopy.updateThreats(trackersCopy);
    // }
    D.ebugPrintln("--- after [start] ---");
    // SOCPlayerTracker.playerTrackersDebug(trackersCopy);
    SOCPlayerTracker.updateWinGameETAs(trackersCopy);
    float WGETABonus = calcWGETABonus(playerTrackers, trackersCopy);
    D.ebugPrintln("$$$ win game ETA bonus : +" + WGETABonus);
    bonus = WGETABonus;
    D.ebugPrintln("our player numbers = " + ourPlayerData.getNumbers());
    D.ebugPrintln("--- after [end] ---");
    switch(posPiece.getType()) {
        case SOCPossiblePiece.SETTLEMENT:
            SOCPlayerTracker.undoTryPutPiece(tmpSet, game);
            break;
        case SOCPossiblePiece.CITY:
            game.undoPutTempPiece(tmpCity);
            break;
        // fall through to ROAD
        case SOCPossiblePiece.SHIP:
        case SOCPossiblePiece.ROAD:
            SOCPlayerTracker.undoTryPutPiece(tmpRoad, game);
            break;
    }
    D.ebugPrintln("our player numbers = " + ourPlayerData.getNumbers());
    D.ebugPrintln("--- cleanup done ---");
    return bonus;
}
Also used : SOCSettlement(soc.game.SOCSettlement) SOCCity(soc.game.SOCCity) SOCShip(soc.game.SOCShip) SOCRoad(soc.game.SOCRoad)

Example 14 with SOCSettlement

use of soc.game.SOCSettlement in project JSettlers2 by jdmonin.

the class SOCRobotDM method scorePossibleSettlements.

/**
 * Score possible settlements for for the smart game strategy ({@link #SMART_STRATEGY}),
 * from {@link #ourPlayerTracker}{@link SOCPlayerTracker#getPossibleSettlements() .getPossibleSettlements()}
 * into {@link #threatenedSettlements} and {@link #goodSettlements};
 * calculate those settlements' {@link SOCPossiblePiece#getScore()}s.
 * Ignores possible settlements that require roads or ships.
 *
 * @see #scoreSettlementsForDumb(int, SOCBuildingSpeedEstimate)
 */
protected void scorePossibleSettlements(final int settlementETA, final int leadersCurrentWGETA) {
    D.ebugPrintln("****** scorePossibleSettlements");
    // int ourCurrentWGETA = ourPlayerTracker.getWinGameETA();
    /*
    boolean goingToPlayRB = false;
    if (! ourPlayerData.hasPlayedDevCard() &&
	ourPlayerData.getNumPieces(SOCPlayingPiece.ROAD) >= 2 &&
	ourPlayerData.getInventory().getAmount(SOCInventory.OLD, SOCDevCardConstants.ROADS) > 0) {
      goingToPlayRB = true;
    }
    */
    Iterator<SOCPossibleSettlement> posSetsIter = ourPlayerTracker.getPossibleSettlements().values().iterator();
    while (posSetsIter.hasNext()) {
        SOCPossibleSettlement posSet = posSetsIter.next();
        D.ebugPrintln("*** scoring possible settlement at " + Integer.toHexString(posSet.getCoordinates()));
        if (!threatenedSettlements.contains(posSet)) {
            threatenedSettlements.add(posSet);
        } else if (!goodSettlements.contains(posSet)) {
            goodSettlements.add(posSet);
        }
        // 
        if (posSet.getNecessaryRoads().isEmpty()) {
            D.ebugPrintln("*** no roads needed");
            // 
            // no roads needed
            // 
            // 
            // get wgeta score
            // 
            SOCBoard board = game.getBoard();
            SOCSettlement tmpSet = new SOCSettlement(ourPlayerData, posSet.getCoordinates(), board);
            if ((brain != null) && (brain.getDRecorder().isOn())) {
                brain.getDRecorder().startRecording("SETTLEMENT" + posSet.getCoordinates());
                brain.getDRecorder().record("Estimate value of settlement at " + board.nodeCoordToString(posSet.getCoordinates()));
            }
            HashMap<Integer, SOCPlayerTracker> trackersCopy = SOCPlayerTracker.tryPutPiece(tmpSet, game, playerTrackers);
            SOCPlayerTracker.updateWinGameETAs(trackersCopy);
            float wgetaScore = calcWGETABonus(playerTrackers, trackersCopy);
            D.ebugPrintln("***  wgetaScore = " + wgetaScore);
            D.ebugPrintln("*** ETA for settlement = " + settlementETA);
            if ((brain != null) && (brain.getDRecorder().isOn())) {
                brain.getDRecorder().record("ETA = " + settlementETA);
            }
            float etaBonus = getETABonus(settlementETA, leadersCurrentWGETA, wgetaScore);
            D.ebugPrintln("etaBonus = " + etaBonus);
            // posSet.addToScore(wgetaScore);
            posSet.addToScore(etaBonus);
            if ((brain != null) && (brain.getDRecorder().isOn())) {
                brain.getDRecorder().record("WGETA score = " + df1.format(wgetaScore));
                brain.getDRecorder().record("Total settlement score = " + df1.format(etaBonus));
                brain.getDRecorder().stopRecording();
            }
            SOCPlayerTracker.undoTryPutPiece(tmpSet, game);
        }
    }
}
Also used : SOCSettlement(soc.game.SOCSettlement) SOCBoard(soc.game.SOCBoard)

Example 15 with SOCSettlement

use of soc.game.SOCSettlement in project JSettlers2 by jdmonin.

the class SOCPlayerInterface method updateAtPutPiece.

/**
 * Handle updates after putting a piece on the board,
 * or moving a ship that was already placed.
 * Place or move the piece within our {@link SOCGame}
 * and visually on our {@link SOCBoardPanel}.
 *
 * @param mesPn  The piece's player number
 * @param coord  The piece's coordinate.  If <tt>isMove</tt>, the coordinate to move <em>from</em>.
 * @param pieceType  Piece type, like {@link SOCPlayingPiece#CITY}
 * @param isMove   If true, it's a move, not a new placement; valid only for ships.
 * @param moveToCoord  If <tt>isMove</tt>, the coordinate to move <em>to</em>.  Otherwise ignored.
 *
 * @see #updateAtPiecesChanged()
 * @since 2.0.00
 */
public void updateAtPutPiece(final int mesPn, final int coord, final int pieceType, final boolean isMove, final int moveToCoord) {
    // TODO consider more effic way for flushBoardLayoutAndRepaint, without the =null
    final SOCPlayer pl = (pieceType != SOCPlayingPiece.VILLAGE) ? game.getPlayer(mesPn) : null;
    final SOCPlayer oldLongestRoadPlayer = game.getPlayerWithLongestRoad();
    final SOCHandPanel mesHp = (pieceType != SOCPlayingPiece.VILLAGE) ? getPlayerHandPanel(mesPn) : null;
    final boolean[] debugShowPotentials = boardPanel.debugShowPotentials;
    final SOCPlayingPiece pp;
    switch(pieceType) {
        case SOCPlayingPiece.ROAD:
            pp = new SOCRoad(pl, coord, null);
            game.putPiece(pp);
            mesHp.updateValue(PlayerClientListener.UpdateType.Road);
            if (debugShowPotentials[4] || debugShowPotentials[5] || debugShowPotentials[7])
                boardPanel.flushBoardLayoutAndRepaint();
            break;
        case SOCPlayingPiece.SETTLEMENT:
            pp = new SOCSettlement(pl, coord, null);
            game.putPiece(pp);
            mesHp.updateValue(PlayerClientListener.UpdateType.Settlement);
            /**
             * if this is the second initial settlement, then update the resource display
             */
            mesHp.updateValue(PlayerClientListener.UpdateType.ResourceTotalAndDetails);
            if (debugShowPotentials[4] || debugShowPotentials[5] || debugShowPotentials[7] || debugShowPotentials[6])
                boardPanel.flushBoardLayoutAndRepaint();
            break;
        case SOCPlayingPiece.CITY:
            pp = new SOCCity(pl, coord, null);
            game.putPiece(pp);
            mesHp.updateValue(PlayerClientListener.UpdateType.Settlement);
            mesHp.updateValue(PlayerClientListener.UpdateType.City);
            if (debugShowPotentials[4] || debugShowPotentials[5] || debugShowPotentials[7] || debugShowPotentials[6])
                boardPanel.flushBoardLayoutAndRepaint();
            break;
        case SOCPlayingPiece.SHIP:
            pp = new SOCShip(pl, coord, null);
            if (!isMove) {
                game.putPiece(pp);
                mesHp.updateValue(PlayerClientListener.UpdateType.Ship);
            } else {
                game.moveShip((SOCShip) pp, moveToCoord);
                if (mesHp == clientHand)
                    // just in case; it probably wasn't enabled
                    mesHp.disableBankUndoButton();
            }
            if (debugShowPotentials[4] || debugShowPotentials[5] || debugShowPotentials[7])
                boardPanel.flushBoardLayoutAndRepaint();
            break;
        case SOCPlayingPiece.VILLAGE:
            // no need to refresh boardPanel after receiving each village
            pp = new SOCVillage(coord, game.getBoard());
            game.putPiece(pp);
            // <--- Early return: Piece is part of board initial layout, not player info ---
            return;
        case SOCPlayingPiece.FORTRESS:
            pp = new SOCFortress(pl, coord, game.getBoard());
            game.putPiece(pp);
            // <--- Early return: Piece is part of board initial layout, not added during game ---
            return;
        default:
            chatPrintDebug("* Unknown piece type " + pieceType + " at coord 0x" + Integer.toHexString(coord));
            // <--- Early return ---
            return;
    }
    mesHp.updateValue(PlayerClientListener.UpdateType.VictoryPoints);
    boardPanel.repaint();
    buildingPanel.updateButtonStatus();
    if (game.isDebugFreePlacement() && game.isInitialPlacement())
        // update here, since gamestate doesn't change to trigger update
        boardPanel.updateMode();
    if (hasCalledBegan && (game.getGameState() >= SOCGame.START1A))
        playSound(SOUND_PUT_PIECE);
    /**
     * Check for and announce change in longest road; update all players' victory points.
     */
    SOCPlayer newLongestRoadPlayer = game.getPlayerWithLongestRoad();
    if (newLongestRoadPlayer != oldLongestRoadPlayer) {
        updateLongestLargest(true, oldLongestRoadPlayer, newLongestRoadPlayer);
    }
}
Also used : SOCSettlement(soc.game.SOCSettlement) SOCVillage(soc.game.SOCVillage) SOCCity(soc.game.SOCCity) SOCPlayingPiece(soc.game.SOCPlayingPiece) SOCShip(soc.game.SOCShip) SOCPlayer(soc.game.SOCPlayer) SOCFortress(soc.game.SOCFortress) SOCRoad(soc.game.SOCRoad)

Aggregations

SOCSettlement (soc.game.SOCSettlement)18 SOCPlayer (soc.game.SOCPlayer)11 SOCShip (soc.game.SOCShip)11 SOCCity (soc.game.SOCCity)10 SOCRoad (soc.game.SOCRoad)10 SOCFortress (soc.game.SOCFortress)4 SOCPlayingPiece (soc.game.SOCPlayingPiece)3 SOCBoardLarge (soc.game.SOCBoardLarge)2 SOCVillage (soc.game.SOCVillage)2 Graphics2D (java.awt.Graphics2D)1 Image (java.awt.Image)1 BufferedImage (java.awt.image.BufferedImage)1 SOCBoard (soc.game.SOCBoard)1 SOCGame (soc.game.SOCGame)1 SOCInventoryItem (soc.game.SOCInventoryItem)1