Choose a player at random - fixed that it wrongly choose same player (example: Scrambleverse, close #12679, close #13526);

Inniaz, the Gale Force - fixed that it wrongly choose left/right player (close #13526);
This commit is contained in:
Oleg Agafonov 2025-04-10 12:36:39 +04:00
parent 4ffb0ff014
commit dcdf0ca4a5
2 changed files with 32 additions and 2 deletions

View file

@ -115,6 +115,36 @@ public class PlayersListAndOrderTest extends CardTestMultiPlayerBase {
execute();
}
@Test
public void test_Game_PlayerListMustHaveAccessByIndex() {
// make sure CircularList return same data by index, see #13526
PlayerList players = new PlayerList();
players.add(playerA.getId());
players.add(playerB.getId());
players.add(playerC.getId());
players.add(playerD.getId());
Assert.assertEquals("last added player must be current", players.get(0), playerD.getId());
List<UUID> staticList = new ArrayList<>(players);
// normal
Assert.assertEquals(players.get(0), staticList.get(0));
Assert.assertEquals(players.get(1), staticList.get(1));
Assert.assertEquals(players.get(2), staticList.get(2));
Assert.assertEquals(players.get(3), staticList.get(3));
Assert.assertEquals(players.get(2), staticList.get(2)); // make sure no depends on calls order
// make sure CircularList keeps inner structure
players.setCurrent(playerC.getId());
Assert.assertEquals(players.get(0), staticList.get(0));
Assert.assertEquals(players.get(1), staticList.get(1));
Assert.assertEquals(players.get(2), staticList.get(2));
Assert.assertEquals(players.get(3), staticList.get(3));
Assert.assertEquals(players.get(2), staticList.get(2)); // make sure no depends on calls order
Assert.assertNull("must return null on non existing item", players.get(999));
}
@Test
public void test_Game_GetPlayerList() {
// game.getPlayerList() - APNAP order, for cards usage

View file

@ -82,8 +82,8 @@ public class CircularList<E> implements List<E>, Iterable<E>, Serializable {
*/
@Override
public E get(int index) {
if (list.size() > this.index) {
return list.get(this.index);
if (list.size() > index) {
return list.get(index);
}
return null;
}