aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/Server/Clients.scala
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-07 22:52:25 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-07 22:52:25 +0200
commit239571e3408a3187953bef1dd5d516461bad0e31 (patch)
tree67c062a635affc90c08a92ac61adfed2445985d8 /src/main/scala/Server/Clients.scala
parentdef8975617e5c6da431e41cc889d167b0f2e2bb0 (diff)
downloadscalevalapokalypsi-239571e3408a3187953bef1dd5d516461bad0e31.tar.gz
scalevalapokalypsi-239571e3408a3187953bef1dd5d516461bad0e31.zip
Added turns, time limits and turn order randomization (feature/bug?)
Diffstat (limited to 'src/main/scala/Server/Clients.scala')
-rw-r--r--src/main/scala/Server/Clients.scala8
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
*