diff options
Diffstat (limited to 'src/main/scala/Server/Clients.scala')
-rw-r--r-- | src/main/scala/Server/Clients.scala | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/main/scala/Server/Clients.scala b/src/main/scala/Server/Clients.scala index 786a09a..6487446 100644 --- a/src/main/scala/Server/Clients.scala +++ b/src/main/scala/Server/Clients.scala @@ -1,6 +1,7 @@ package o1game.Server import scala.util.Try +import scala.util.Random class Clients(maxClients: Int): private val clients: Array[Option[Client]] = Array.fill(maxClients)(None) @@ -28,6 +29,13 @@ class Clients(maxClients: Int): /** Applies the function `f` to all the clients for its side effects. */ def foreach(f: Client => Any): Unit = this.clients.flatten.foreach(f) + /** Executes the function `f` for all clients in a pseudorandom order. */ + def inRandomOrder(f: Client => Any): Unit = + Random.shuffle(this + .clients + .flatten) + .foreach(f) + /** Returns true if the predicate `f` stands for all clients, * false otherwise * |