rt

Reader's Theatre
Log | Files | Refs | README | LICENSE

commit 903efad6408c0fe6fb120b23c4d20de49b76cb05
parent 13e44708d7553b395972baed64b6be813d41b79c
Author: zerous Naveen Narayanan <zerous@nocebo.space>
Date:   Sat, 14 Dec 2019 18:22:03 +0100

Incite randomness but make sure that it is controlled so as to let user play a script at the earliest.

Diffstat:
Mservertask.java | 2+-
Mutil.java | 25++++++++++++++++++++++---
2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/servertask.java b/servertask.java @@ -36,7 +36,7 @@ public class servertask implements Runnable { private void register(String m) { String[] inp = m.split(" ", 2); - player = new acc(inp[0], inp[1], 1); + player = new acc(inp[0], inp[1], util.getRandomScore()); server.Accounts.add(player); } diff --git a/util.java b/util.java @@ -4,6 +4,9 @@ import java.util.regex.PatternSyntaxException; import java.util.Random; public class util { + private static int prev = getRandomInt(); + private static int t = 0; + public static boolean isNumeric(String s) { try { int d = Integer.parseInt(s); @@ -36,9 +39,7 @@ public class util { public static int getRandomInt() { int res = 0; Random r = new Random(); - res = r.nextInt(5); - if (res == 0) - return 1; + res = r.nextInt((5-1) + 1) + 1; return res; } @@ -53,4 +54,22 @@ public class util { } return sb.toString(); } + + public static int getRandomScore() { + int s; + + if (t == 3) { + t = 0; + s = getRandomInt(); + System.out.println("dbg: s: " + s); + prev = s; + } else { + if (prev >= 5) + prev = 1; + s = prev + 1; + } + + t++; + return s; + } }