Messaging
authorJBM <jbm@codingame.com>
Thu, 21 May 2020 15:38:27 +0000 (17:38 +0200)
committerJBM <jbm@codingame.com>
Wed, 27 May 2020 14:53:54 +0000 (16:53 +0200)
.gitignore
PLAN.org
config/Boss.java
config/Boss.sh [deleted file]
config/statement_en.html
src/main/java/com/codingame/game/Player.java
src/main/java/com/codingame/game/Referee.java
src/test/java/Player2.java

index a786704..5a6e008 100644 (file)
@@ -6,3 +6,4 @@ target/
 .vscode
 .factorypath
 bin
 .vscode
 .factorypath
 bin
+*~
index 8957eba..ed0f737 100644 (file)
--- a/PLAN.org
+++ b/PLAN.org
@@ -2,10 +2,7 @@
 * DONE document maps
 * DONE document length/distance thingy
 * TODO debug rotating avatar
 * DONE document maps
 * DONE document length/distance thingy
 * TODO debug rotating avatar
-* TODO easter egg for YannT
-meta^5 @YannT :: (a -> b) -> f1 (f2 (f3 a)) -> f1 (f2 (f3 b))
-* TODO messages
-tortue
-by the power of grayskull
+* DONE easter egg for YannT
+* DONE messages
 * TODO referee cleanup
 * DONE upgrade deps
 * TODO referee cleanup
 * DONE upgrade deps
index d3c297d..548c083 100644 (file)
@@ -1,10 +1,17 @@
 import java.util.Random;
 import java.util.Scanner;
 
 import java.util.Random;
 import java.util.Scanner;
 
-public class Player2 {
+public class Boss {
+    private final static String[] messages = {
+        "meta⁵ @YannT ∷ (a → b) → f1 (f2 (f3 a)) → f1 (f2 (f3 b))",
+        "By the power of Grayskull!",
+        "tortue",
+        "how is ur csb",
+        "YHBT"
+    };
     public static void main(String[] args) {
         Scanner in = new Scanner(System.in);
     public static void main(String[] args) {
         Scanner in = new Scanner(System.in);
-        Random random = new Random(0);
+        Random random = new Random();
 
         int roadLength = in.nextInt();
         int initialStones = in.nextInt();
 
         int roadLength = in.nextInt();
         int initialStones = in.nextInt();
@@ -13,8 +20,14 @@ public class Player2 {
             int trollDistance = in.nextInt();
             int stones = in.nextInt();
             int opponentStones = in.nextInt();
             int trollDistance = in.nextInt();
             int stones = in.nextInt();
             int opponentStones = in.nextInt();
-           
-            System.out.println(random.nextInt(stones+1));
+
+            if (random.nextInt(30) == 0) {
+                System.out.println(random.nextInt(stones+1) + " " +
+                                   messages[random.nextInt(messages.length)]);
+            }
+            else {
+                System.out.println(random.nextInt(stones+1));
+            }
         }
     }
 }
         }
     }
 }
diff --git a/config/Boss.sh b/config/Boss.sh
deleted file mode 100644 (file)
index 0b3832f..0000000
+++ /dev/null
@@ -1 +0,0 @@
-exec yes 1
index 0102747..89a0e27 100644 (file)
        <span>Change Log</span>
      </h2>
      <ul>
        <span>Change Log</span>
      </h2>
      <ul>
+       <li>
+         Of course that game needed MSG functionality!
+       </li>
        <li>
          Enforce the one-stone rule.  (that also fixed the legacy
          buh&mdash;sorry people!  I put an easter egg in exchange)
        <li>
          Enforce the one-stone rule.  (that also fixed the legacy
          buh&mdash;sorry people!  I put an easter egg in exchange)
index bf40000..7204af3 100644 (file)
@@ -1,5 +1,10 @@
 package com.codingame.game;
 
 package com.codingame.game;
 
+import java.util.regex.Pattern;
+import java.util.Scanner;
+import java.util.InputMismatchException;
+import java.util.NoSuchElementException;
+
 import com.codingame.gameengine.core.AbstractMultiplayerPlayer;
 import com.codingame.gameengine.module.entities.Group;
 import com.codingame.gameengine.module.entities.Text;
 import com.codingame.gameengine.core.AbstractMultiplayerPlayer;
 import com.codingame.gameengine.module.entities.Group;
 import com.codingame.gameengine.module.entities.Text;
@@ -8,23 +13,19 @@ import com.codingame.gameengine.module.entities.Sprite;
 public class Player extends AbstractMultiplayerPlayer {
     Group avatar;
     Text stoneCounter;
 public class Player extends AbstractMultiplayerPlayer {
     Group avatar;
     Text stoneCounter;
+    Text message;
     Sprite castle;
     Text stone;
     Sprite castle;
     Text stone;
-    
+
+    private String messageString;
+    public String getMessageString() { return messageString; }
 
     private int castlePosition;
 
     private int castlePosition;
-    public int getCastlePosition() {
-        return castlePosition;
-    }
-    public void setCastlePosition(int pos) {
-        castlePosition = pos;
-    }
+    public int getCastlePosition() { return castlePosition; }
+    public void setCastlePosition(int pos) { castlePosition = pos; }
 
     private int stones;
 
     private int stones;
-    public int getStones()
-    {
-        return stones;
-    }
+    public int getStones() { return stones; }
     public void consumeStones(int n) throws InvalidAction {
         if (n > stones) {
             throw new InvalidAction("attempted to throw more stones than they had.");
     public void consumeStones(int n) throws InvalidAction {
         if (n > stones) {
             throw new InvalidAction("attempted to throw more stones than they had.");
@@ -47,12 +48,8 @@ public class Player extends AbstractMultiplayerPlayer {
     }
 
     private int multiplier;
     }
 
     private int multiplier;
-    public int getMultiplier() {
-        return multiplier;
-    }
-    public void setMultiplier(int m){
-        multiplier = m;
-    }
+    public int getMultiplier() { return multiplier; }
+    public void setMultiplier(int m){ multiplier = m; }
 
     public void adjustScore(int trollPosition) {
         setScore(Math.abs(castlePosition - trollPosition));
 
     public void adjustScore(int trollPosition) {
         setScore(Math.abs(castlePosition - trollPosition));
@@ -63,7 +60,19 @@ public class Player extends AbstractMultiplayerPlayer {
         return 1;
     }
 
         return 1;
     }
 
+    static final Pattern rest = Pattern.compile(".*");
+    static final Pattern eol = Pattern.compile("\n");
     public int getAction() throws TimeoutException, NumberFormatException {
     public int getAction() throws TimeoutException, NumberFormatException {
-        return Integer.parseInt(getOutputs().get(0));
+        Scanner s = new Scanner(getOutputs().get(0));
+        messageString = "";
+        try {
+            int st = s.nextInt();
+            s.useDelimiter(eol);
+            if (s.hasNext(rest))
+                messageString = s.next(rest);
+            return st;
+        }
+        catch (InputMismatchException e) { throw new NumberFormatException(); }
+        catch (NoSuchElementException e) { throw new NumberFormatException(); }
     }
 }
     }
 }
index 5b6ec3a..7efe7b3 100644 (file)
@@ -134,6 +134,16 @@ public class Referee extends AbstractReferee {
                 .setFillColor(0x7f3f00)
                 .setAnchor(0.5);
 
                 .setFillColor(0x7f3f00)
                 .setAnchor(0.5);
 
+            player.message = graphicEntityModule.createText()
+                .setX(p0 ? 15 : 1920-15)
+                .setY(680)
+                .setZIndex(1)
+                .setFontSize(40)
+                .setStrokeColor(0x000000)
+                .setFillColor(0xffbf7f)
+                .setAnchorX(p0 ? 0 : 1)
+                .setAnchorY(1);
+
             player.castle = graphicEntityModule.createSprite()
                 .setImage("castle.png")
                 .setTint(player.getColorToken())
             player.castle = graphicEntityModule.createSprite()
                 .setImage("castle.png")
                 .setTint(player.getColorToken())
@@ -150,7 +160,6 @@ public class Referee extends AbstractReferee {
                 .setFillColor(0x12322a)
                 .setAnchor(0.5)
                 .setAlpha(0);
                 .setFillColor(0x12322a)
                 .setAnchor(0.5)
                 .setAlpha(0);
-
         }
     }
 
         }
     }
 
@@ -266,6 +275,11 @@ public class Referee extends AbstractReferee {
                 player.setScore(-1);
                 endGame();
             }
                 player.setScore(-1);
                 endGame();
             }
+
+            player.message
+                .setText(player.getMessageString());
+            //  .setAnchorX(/*player == p0 ? 0 : */ 1);
+            graphicEntityModule.commitEntityState(0, player.message);
         }
 
         if (delta > 0) {
         }
 
         if (delta > 0) {
@@ -304,23 +318,25 @@ public class Referee extends AbstractReferee {
     }
 
     private void endGame() {
     }
 
     private void endGame() {
-        gameManager.endGame();
+        if (! gameManager.isGameEnd()) {
+            gameManager.endGame();
 
 
-        if (p0.getScore() > p1.getScore()) {
-            gameManager.addToGameSummary(GameManager.formatSuccessMessage(p0.getNicknameToken() + " wins"));
-            destroyPlayer(p1);
-        }
-        else if (p0.getScore() < p1.getScore()) {
-            gameManager.addToGameSummary(GameManager.formatSuccessMessage(p1.getNicknameToken() + " wins"));
-            destroyPlayer(p0);
-        }
-        else if (p0.getScore() < 0) {
-            gameManager.addToGameSummary(GameManager.formatErrorMessage("Everybody loses!"));
-            destroyPlayer(p0);
-            destroyPlayer(p1);
-        }
-        else {
-            gameManager.addToGameSummary("Draw.");
+            if (p0.getScore() > p1.getScore()) {
+                gameManager.addToGameSummary(GameManager.formatSuccessMessage(p0.getNicknameToken() + " wins"));
+                destroyPlayer(p1);
+            }
+            else if (p0.getScore() < p1.getScore()) {
+                gameManager.addToGameSummary(GameManager.formatSuccessMessage(p1.getNicknameToken() + " wins"));
+                destroyPlayer(p0);
+            }
+            else if (p0.getScore() < 0) {
+                gameManager.addToGameSummary(GameManager.formatErrorMessage("Everybody loses!"));
+                destroyPlayer(p0);
+                destroyPlayer(p1);
+            }
+            else {
+                gameManager.addToGameSummary("Draw.");
+            }
         }
     }
 }
         }
     }
 }
index d3c297d..5dbb9b8 100644 (file)
@@ -2,9 +2,16 @@ import java.util.Random;
 import java.util.Scanner;
 
 public class Player2 {
 import java.util.Scanner;
 
 public class Player2 {
+    private final static String[] messages = {
+        "meta⁵ @YannT ∷ (a → b) → f1 (f2 (f3 a)) → f1 (f2 (f3 b))",
+        "By the power of Grayskull!",
+        "tortue",
+        "how is ur csb",
+        "YHBT"
+    };
     public static void main(String[] args) {
         Scanner in = new Scanner(System.in);
     public static void main(String[] args) {
         Scanner in = new Scanner(System.in);
-        Random random = new Random(0);
+        Random random = new Random();
 
         int roadLength = in.nextInt();
         int initialStones = in.nextInt();
 
         int roadLength = in.nextInt();
         int initialStones = in.nextInt();
@@ -13,8 +20,14 @@ public class Player2 {
             int trollDistance = in.nextInt();
             int stones = in.nextInt();
             int opponentStones = in.nextInt();
             int trollDistance = in.nextInt();
             int stones = in.nextInt();
             int opponentStones = in.nextInt();
-           
-            System.out.println(random.nextInt(stones+1));
+
+            if (random.nextInt(30) == 0) {
+                System.out.println(random.nextInt(stones+1) + " " +
+                                   messages[random.nextInt(messages.length)]);
+            }
+            else {
+                System.out.println(random.nextInt(stones+1));
+            }
         }
     }
 }
         }
     }
 }