Skip to content

Commit

Permalink
Longest Route: Fix issue #95: SOCGame.putPieceCommon: Recalc player's…
Browse files Browse the repository at this point in the history
… longest route when building a new coastal settlement to connect their roads to ships; add to release-testing; savegame artifact reletest-longest-joinships + author, comment, unlock p2 seat to allow takeover
  • Loading branch information
jdmonin committed May 2, 2021
1 parent 17756b5 commit c82d387
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
16 changes: 11 additions & 5 deletions doc/Release-Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,20 @@ When preparing to release a new version, testing should include:
- Build settlement to split another player's Longest Route, giving a 3rd player the new Longest Route.
(Skip this situation if testing for "move a ship".)
If this ends the game, 3rd player should win only when their turn begins.
To save time, you can test with server Savegame feature enabled:
Copy src/test/resources/resources/savegame/reletest-longest-3p.game.json and reletest-longest-3p-sea.game.json
to your server's configured savegame directory, then run `*LOADGAME* reletest-longest-3p`
or `*LOADGAME* reletest-longest-3p-sea`
To save time, you can test with server Savegame feature enabled:
- Copy src/test/resources/resources/savegame/reletest-longest-3p.game.json and reletest-longest-3p-sea.game.json to your server's configured savegame directory
- Run `*LOADGAME* reletest-longest-3p` or `*LOADGAME* reletest-longest-3p-sea` debug command in any other game window
- Piece types to test each situation with:
- Build roads only
- Build a route that has roads and ships (through a coastal settlement)
- Move a ship to gain Longest Route
- Take Longest Route by building a coastal settlement to connect roads to ships
- Copy src/test/resources/resources/savegame/reletest-longest-joinships.game.json to your server's configured savegame directory
- Run `*LOADGAME* reletest-longest-joinships` debug command in any other game window
- Optional: Use client 2.4.00 or older as players or observers
- Those versions don't recalculate longest route in this situation, but server 2.4.50 and newer should tell them it's changed
- Build a coastal settlement
- Should take Longest Route from other player
- Can win by gaining Longest Road/Route
- To set up for each test, can use debug command `*FREEPLACE* 1` to quickly build pieces until you have 8 VP;
be careful to not gain longest route before the test begins
Expand Down Expand Up @@ -405,7 +411,7 @@ When preparing to release a new version, testing should include:
- Join with 1.x client
- Should see marked seat as unlocked, locked as locked
- Should be able to take over bot by sitting at "marked" seat
- When testing new server with client 2.4.50 or newer, and older client:
- When testing new server with client 2.4.50 or newer, and older client in same game:
- All clients in game (players and observers) should see expected results in player hand panels and game text area for:
- Soldier dev card
- Give Soldier cards to client players:
Expand Down
2 changes: 2 additions & 0 deletions doc/Versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ JARs for recent JSettlers versions can be downloaded from
## `2.4.50` (build JM20201xxx)
- Currently being developed
- Gameplay:
- Recalc Longest Route when building coastal settlement to connect a player's roads to ships
(thanks kotc for reporting issue #95)
- When a trade is offered to bots and humans, bots wait longer before responding.
Was 3 seconds, is now 8, changeable with server property `jsettlers.bot.human.pause`
(thank you Lee Passey)
Expand Down
34 changes: 29 additions & 5 deletions src/main/java/soc/game/SOCGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -3810,28 +3810,45 @@ else if ((pp instanceof SOCSettlement) && isInitialPlacement())
*/
if (pieceType != SOCPlayingPiece.CITY)
{
final int placingPN = ppPlayer.getPlayerNumber();

if (pp instanceof SOCRoutePiece)
{
/**
* the affected player is the one who build the road or ship
*/
updateLongestRoad(ppPlayer.getPlayerNumber());
updateLongestRoad(placingPN);
}
else if (pieceType == SOCPlayingPiece.SETTLEMENT)
{
/**
* this is a settlement, check if it cut anyone else's road or trade route
* or (on sea boards) if this connects a player's own roads to their ships
*/
int[] roads = new int[maxPlayers];
boolean ownRoad = false, ownShip = false;

for (final int adjEdge : board.getAdjacentEdgesToNode(coord))
{
/**
* look for other players' roads and ships adjacent to this node
* check all roads and ships adjacent to this node
*/
for (SOCRoutePiece road : board.getRoadsAndShips())
if (adjEdge == road.getCoordinates())
roads[road.getPlayerNumber()]++;
{
if (adjEdge != road.getCoordinates())
continue;

final int roadPN = road.getPlayerNumber();
roads[roadPN]++;

if (roadPN == placingPN)
{
if (road.isRoadNotShip())
ownRoad = true;
else
ownShip = true;
}
}
}

/**
Expand All @@ -3841,7 +3858,7 @@ else if (pieceType == SOCPlayingPiece.SETTLEMENT)
*/
for (int i = 0; i < maxPlayers; i++)
{
if ((i != ppPlayer.getPlayerNumber()) && (roads[i] == 2))
if ((i != placingPN) && (roads[i] == 2))
{
updateLongestRoad(i);

Expand All @@ -3851,6 +3868,13 @@ else if (pieceType == SOCPlayingPiece.SETTLEMENT)
break;
}
}

/**
* if placing player has connected their own roads and ships
* at this new coastal settlement, recalculate their longest route
*/
if (ownRoad && ownShip)
updateLongestRoad(placingPN);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/resources/version.info
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ project.versionnum=2450
# should be a version released more than a year ago.
project.versionnumMaxNoWarn=2000
project.copyright=2001-2004 Robb Thomas, portions (C) 2007-2021 Jeremy D Monin and contributors
project.buildnum=JM20210411
project.buildnum=JM20210501
project.jre.min.major=1
project.jre.min.minor=7
project.jre.min.edit=0
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"savedByVersion": 2450,
"gameMinVersion": 2000,
"gameName": "reletest-longest-joinships",
"comments": "when player 3 builds a coastal settlement to connect roads to ships, should gain longest route from player 2 (checked in server v2.4.50 and newer; github issue 95)",
"author": "Jeremy D Monin 2021",
"gameOptions": "BC\u003dt4,N7\u003df7,PL\u003d3,RD\u003df,SBL\u003dt,VP\u003dt11",
"gameDurationSeconds": 215,
"gameState": 20,
Expand Down Expand Up @@ -380,7 +382,7 @@
"playerSeatLocks": [
"CLEAR_ON_RESET",
"UNLOCKED",
"LOCKED",
"UNLOCKED",
"UNLOCKED"
],
"playerSeats": [
Expand Down

0 comments on commit c82d387

Please sign in to comment.