From 92f2c9f3090d3ffb6007972413c1120c57059f4f Mon Sep 17 00:00:00 2001 From: Brett Date: Thu, 20 Apr 2023 19:04:30 -0400 Subject: [PATCH] fix finding issue --- .../ca/cosc3p91/a4/util/network/Server.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Assignment 4/src/ca/cosc3p91/a4/util/network/Server.java b/Assignment 4/src/ca/cosc3p91/a4/util/network/Server.java index 87da8f5..8bc8f76 100644 --- a/Assignment 4/src/ca/cosc3p91/a4/util/network/Server.java +++ b/Assignment 4/src/ca/cosc3p91/a4/util/network/Server.java @@ -205,12 +205,20 @@ public class Server implements Runnable { break; } int pos = rand.nextInt(clients); - while (pos == clientID) + long findingClientID = clientID; + ConnectedClient foundClient = null; + int searchCount = 0; + while (findingClientID == clientID) { pos = rand.nextInt(clients); - Iterator> entries = server.clients.entrySet().iterator(); - for (int i = 0; i < pos; i++) - entries.next(); - exploringMap = entries.next().getValue().clientMap; + Iterator> entries = server.clients.entrySet().iterator(); + for (int i = 0; i < pos; i++) + entries.next(); + foundClient = entries.next().getValue(); + findingClientID = foundClient.clientID; + if(searchCount++ > 50) + break; + } + exploringMap = foundClient.clientMap; sendMapData(usingEngine.view.getVillageStateTable(exploringMap, "Other Village")); break; case PacketTable.GENERATE: