From 239571e3408a3187953bef1dd5d516461bad0e31 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Thu, 7 Nov 2024 22:52:25 +0200 Subject: Added turns, time limits and turn order randomization (feature/bug?) --- src/main/scala/Server/Clients.scala | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/main/scala/Server/Clients.scala') 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 * -- cgit v1.2.3