Advertisement
romaji

Marathon Mode, But it hates you

Nov 4th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.11 KB | None | 0 0
  1. package mu.nu.nullpo.game.subsystem.mode;
  2.  
  3. import mu.nu.nullpo.game.component.Piece;
  4. import mu.nu.nullpo.game.event.EventReceiver;
  5. import mu.nu.nullpo.game.play.GameEngine;
  6. import mu.nu.nullpo.util.CustomProperties;
  7.  //For the love of all that is holy, don't play with different piece lists than the normal 7. Please
  8. // also this isn't netplay safe at all
  9. // Also hi, this is Romaji Milton Amulo, in 2018, coding Java again
  10. // USES A PROTECTED MODE VERSION OF MARATHON MODE
  11. public class MarathonModeButItHatesYou extends MarathonMode {
  12.    
  13.     @Override
  14.     public String getName() {
  15.         return "EVIL MARATHON";
  16.     }
  17.     private int[] record;
  18.     private int badPiece;
  19.    
  20.     private boolean hasSkipped;
  21.     private static final boolean debugMode=true;
  22.    
  23.     @Override
  24.     public void startGame(GameEngine engine, int playerID) {
  25.         super.startGame(engine, playerID);
  26.         record = new int[7];
  27.         record[0]=1; // pre set I as bad piece
  28.         badPiece=0;
  29.         hasSkipped=false;
  30.  
  31.     }
  32.     /*
  33.      * takes in what was just dropped
  34.      */
  35.     public void pieceLocked(GameEngine engine, int playerID, int lines) {
  36.         record[engine.nowPieceObject.id] +=lines; //adds to record per piece.
  37.         if (engine.nextPieceArrayID[engine.nextPieceCount]==badPiece) { //if bad, skip
  38.             engine.nextPieceCount++;
  39.             hasSkipped=true;
  40.         }
  41.         if (engine.nextPieceCount%7==0){
  42.             recomputeBadPiece(engine);
  43.         }
  44.     }
  45.    
  46.  
  47.     /*
  48.      * Render score and what piece will be skipped.
  49.      */
  50.     @Override
  51.     public void renderLast(GameEngine engine, int playerID) {
  52.         super.renderLast(engine, playerID);
  53.         if (hasSkipped) {
  54.             engine.owner.receiver.drawScoreFont(engine, playerID, 0, 14, "SAFE FOR NOW", EventReceiver.COLOR_BLUE);
  55.         } else {
  56.             engine.owner.receiver.drawScoreFont(engine, playerID, 0, 14, Piece.getPieceName(badPiece) +
  57.                     " WILL BE SKIPPED", EventReceiver.COLOR_RED);
  58.         }
  59. //      if (debugMode) { //I don't understand, but this breaks everything
  60. //          engine.owner.receiver.drawScoreFont(engine, playerID, 0, 15, String.valueOf(record[0])+""+
  61. //                  String.valueOf(record[1])+""+String.valueOf(record[2])+""+String.valueOf(record[3])
  62. //                  +""+String.valueOf(record[4])+""+String.valueOf(record[5])+""+String.valueOf(record[6]));
  63. //          //Someone help me write out the values of record.
  64. //      }
  65.        
  66.      }
  67.    
  68.     private void recomputeBadPiece(GameEngine engine) {
  69.         //erase common min, so least favorite piece is never removed.
  70.         int CommonMin=999999999; //should be high enough
  71.         for (int value : record) {
  72.             if (value<CommonMin) {
  73.                 CommonMin = value;
  74.                 if (CommonMin == 0) {
  75.                     break; //if the common min is zero, no need to keep looking
  76.                 }
  77.             }
  78.         }
  79.         if(CommonMin >0) { //no point getting rid of the common min if it's zero
  80.             for(int index=0;index<7;index++) {
  81.                 record[index]-=CommonMin;
  82.             }
  83.         }
  84.         int total=0; //now, see how large to set the RNG
  85.         for (int value : record) {
  86.             total+=value;
  87.         }
  88.         if (total==0) { //if no piece is favored, be merciful, and don't have a skip piece. This time.
  89.             badPiece=-1;
  90.             return;
  91.         }
  92.         hasSkipped=false;
  93.         int RGN = engine.random.nextInt(total); //get a random int at least one less than total.
  94.                                                 //RGN = Randomly Generated Number
  95.         for(int index=0;index<7;index++) {
  96.             RGN -= record[index];
  97.             if (RGN<0) {
  98.                 badPiece=index; //set bad piece to when RGN goes below 0, and then leave
  99.                 break;
  100.             }
  101.         }
  102.     }
  103.    
  104.     // now for edited copypasta code
  105.  
  106.     /**
  107.      * Read rankings from property file
  108.      * @param prop Property file
  109.      * @param ruleName Rule name
  110.      */
  111.     @Override
  112.     protected void loadRanking(CustomProperties prop, String ruleName) {
  113.         for(int i = 0; i < RANKING_MAX; i++) {
  114.             for(int j = 0; j < GAMETYPE_MAX; j++) {
  115.                 rankingScore[j][i] = prop.getProperty("evilmarathon.ranking." + ruleName + "." + j + ".score." + i, 0);
  116.                 rankingLines[j][i] = prop.getProperty("evilmarathon.ranking." + ruleName + "." + j + ".lines." + i, 0);
  117.                 rankingTime[j][i] = prop.getProperty("evilmarathon.ranking." + ruleName + "." + j + ".time." + i, 0);
  118.             }
  119.         }
  120.     }
  121.  
  122.     /**
  123.      * Save rankings to property file
  124.      * @param prop Property file
  125.      * @param ruleName Rule name
  126.      */
  127.     protected void saveRanking(CustomProperties prop, String ruleName) {
  128.         for(int i = 0; i < RANKING_MAX; i++) {
  129.             for(int j = 0; j < GAMETYPE_MAX; j++) {
  130.                 prop.setProperty("evilmarathon.ranking." + ruleName + "." + j + ".score." + i, rankingScore[j][i]);
  131.                 prop.setProperty("evilmarathon.ranking." + ruleName + "." + j + ".lines." + i, rankingLines[j][i]);
  132.                 prop.setProperty("evilmarathon.ranking." + ruleName + "." + j + ".time." + i, rankingTime[j][i]);
  133.             }
  134.         }
  135.     }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement