/**
  * Overrides parent's onCreate method. Sets player, opponents and health bars.
  *
  * @param savedInstanceState
  */
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   Intent getIntent = getIntent();
   player = (Player) getIntent.getSerializableExtra("player");
   level = getIntent.getStringExtra("level");
   opponents = new ArrayList<Opponent>();
   playerProgressBar = (ProgressBar) findViewById(R.id.playerProgressBar);
   opProgressBar = (ProgressBar) findViewById(R.id.oppProgressBar);
   playerHealth = (TextView) findViewById(R.id.playerHealthTextView);
   opHealth = (TextView) findViewById(R.id.oppTextView);
   opList = getIntent.getStringArrayListExtra("opList");
   opponents = (ArrayList<Opponent>) getIntent.getSerializableExtra("opponents");
   displayedResults = false;
   if (opList == null) {
     opList = new ArrayList<String>();
   }
   if (opponents == null) {
     opponents = new ArrayList<Opponent>();
   }
   setContentView(R.layout.activity_fight);
   setContent();
   totalEnemyHP = 0;
   for (Opponent enemy : opponents) {
     totalEnemyHP += enemy.getTotalHealth();
   }
 }
Exemple #2
0
 public Opponent getOpponent(TetrisId tetrisId) {
   for (Opponent opponent : opponents) {
     if (opponent.getTetrisId().equals(tetrisId)) {
       return opponent;
     }
   }
   return null;
 }
Exemple #3
0
 public void addPenaltyLine(TetrisId tetrisId, int lineCount) {
   for (Opponent opponent : opponents) {
     if (opponent.isOpponent(tetrisId)) {
       opponent = opponent.addPenaltyLine(lineCount);
       fireBattleEvent(new BattlePenaltyLineAdded(battleId, opponent.getTetrisId(), lineCount));
     }
   }
 }
Exemple #4
0
 public boolean contains(TetrisId tetrisId) {
   for (Opponent opponent : opponents) {
     if (opponent.getTetrisId().equals(tetrisId)) {
       return true;
     }
   }
   return false;
 }
 /**
  * Method to set the progress bars when damage is dealt
  *
  * @param opponent Sets player and opponent health bars based on percentage of health left.
  * @param opponent
  */
 private void setProgressBars(Opponent opponent) {
   playerProgressBar = (ProgressBar) findViewById(R.id.playerProgressBar);
   opProgressBar = (ProgressBar) findViewById(R.id.oppProgressBar);
   playerHealth = (TextView) findViewById(R.id.playerHealthTextView);
   playerHealth.setText("Player HP : " + player.getCurrentHealth());
   playerProgressBar.setProgress(player.getPercentHealthLeft());
   opHealth = (TextView) findViewById(R.id.oppTextView);
   String oppBar = opponent.getName() + " HP: " + opponent.getTotalHealth();
   opHealth.setText(oppBar);
 }
Exemple #6
0
  public boolean storeOpponents(ArrayList<Opponent> opponents) {
    JSONArray ja = new JSONArray();

    try {
      for (Opponent o : opponents) {
        JSONObject jo = new JSONObject();
        jo.put(JSON_OPPONENT_PIN, o.getPlayer().getPin());
        jo.put(JSON_OPPONENT_WIN, (double) o.getResult());
        jo.put(JSON_OPPONENT_COLOR, o.getColor());
        jo.put(JSON_OPPONENT_HANDICAP, o.getHandicap());
        ja.put(jo);
      }
    } catch (JSONException e) {
      e.printStackTrace();
    }

    return mPrefs.edit().putString(OPPONENTS, ja.toString()).commit();
  }
 /**
  * Gets the next opponent after the current opponent is defeated. Updates Leaderboard and calls
  * RewardScreen if victorious.
  */
 public void generateNextOpponent() {
   RelativeLayout rl = (RelativeLayout) findViewById(R.id.fightLayout);
   ImageButton frfd = (ImageButton) findViewById(R.id.firstRowFirstDice);
   frfd.setTag(null);
   ImageButton frsd = (ImageButton) findViewById(R.id.firstRowSecondDice);
   frsd.setTag(null);
   ImageButton srfd = (ImageButton) findViewById(R.id.secondRowFirstDice);
   srfd.setTag(null);
   ImageButton srsd = (ImageButton) findViewById(R.id.secondRowSecondDice);
   srsd.setTag(null);
   if (opponents.size() == 0) {
     if (this.player.getUserId() != 0) {
       updateLeaderboard();
     }
     rewardsScreen();
   } else {
     if (this.player.getUserId() != 0) {
       updateLeaderboard();
     }
     Opponent next = opponents.get(0);
     currOpponet = next;
     int resId = getResources().getIdentifier(next.getLayout(), "drawable", getPackageName());
     rl.setBackgroundColor(Color.WHITE);
     rl.setBackground(ContextCompat.getDrawable(this, resId));
     resetDicePics();
     generateOperations(currOpponet.getOp());
     generateAns(level);
     opProgressBar.setProgress(currOpponet.getPercentHealthLeft());
     opHealth.setText(currOpponet.getName() + " HP: " + currOpponet.getCurrentHealth());
   }
 }
Exemple #8
0
  public static void main(String[] args) {

    Boolean didUserWin = false;
    CardPile deck;

    ArrayList<Player> players = new ArrayList<Player>();
    players.add(new User("Human"));

    printGreeting();

    int numComps;
    if (DEBUG) {
      numComps = 3;
    } else {
      /*
       * ask for number of player
       */
      numComps = getNumComps();
    }
    /*
     * Create computer players
     */
    for (int i = 0; i < numComps; i++) {
      players.add(new Opponent("Comp " + String.valueOf(i + 1)));
    }

    /*
     * get our deck of cards
     */
    deck = new CardPile();

    Boolean isContinuePlay = true;

    while (isContinuePlay) {

      /*
       * randomizes position of cards within deck
       */
      deck.shuffle();

      System.out.println("Cards have been shuffled.  Let's play!");
      pause();

      System.out.println("Dealer is dealing cards to players...");
      pause();

      /*
       * draw cards for each player
       */
      if (DEBUG) {
        players.get(0).getHand().addCard(new Card(Suit.SPADES, Rank.ACE));
        players.get(0).getHand().addCard(new Card(Suit.HEARTS, Rank.TEN));
        players.get(0).getHand().addCard(new Card(Suit.HEARTS, Rank.TWO));
        players.get(0).getHand().addCard(new Card(Suit.SPADES, Rank.FIVE));
        players.get(0).getHand().addCard(new Card(Suit.CLUBS, Rank.FOUR));
        players.get(1).getHand().addCard(new Card(Suit.HEARTS, Rank.ACE));
        players.get(1).getHand().addCard(new Card(Suit.SPADES, Rank.NINE));
        players.get(1).getHand().addCard(new Card(Suit.SPADES, Rank.THREE));
        players.get(1).getHand().addCard(new Card(Suit.CLUBS, Rank.KING));
        players.get(1).getHand().addCard(new Card(Suit.SPADES, Rank.FOUR));
        players.get(2).getHand().addCard(new Card(Suit.SPADES, Rank.QUEEN));
        players.get(2).getHand().addCard(new Card(Suit.CLUBS, Rank.TEN));
        players.get(2).getHand().addCard(new Card(Suit.CLUBS, Rank.JACK));
        players.get(2).getHand().addCard(new Card(Suit.HEARTS, Rank.SIX));
        players.get(2).getHand().addCard(new Card(Suit.CLUBS, Rank.FOUR));
        players.get(3).getHand().addCard(new Card(Suit.DIAMONDS, Rank.TWO));
        players.get(3).getHand().addCard(new Card(Suit.SPADES, Rank.NINE));
        players.get(3).getHand().addCard(new Card(Suit.DIAMONDS, Rank.THREE));
        players.get(3).getHand().addCard(new Card(Suit.SPADES, Rank.TEN));
        players.get(3).getHand().addCard(new Card(Suit.HEARTS, Rank.FOUR));
      } else {
        for (int c = 1; c <= MAX_HAND_SIZE; c++) {
          for (Player player : players) {
            player.getHand().addCard(deck.drawCard());
          }
        }
      }
      /*
       * show user their hand in descending rank
       */
      showHand(players.get(USER_INDEX_POSITION), "The cards in your hand are: ");
      pause();

      System.out.println("It is time now to discard unwanted cards.");
      /*
       * get user's unwanted cards
       */
      ArrayList<Integer> discardIndices = getDiscardedCards(players.get(USER_INDEX_POSITION));

      /*
       * physically discard the user's cards
       */
      ArrayList<Card> discardCards = new ArrayList<Card>();
      for (int discardIndex : discardIndices) {
        Card card = players.get(USER_INDEX_POSITION).getHand().getCardAtIndex(discardIndex - 1);
        if (card != null) {
          discardCards.add(card);
        } else {
          System.out.println("Failed to get card at index " + discardIndex);
        }
      }
      for (Card discardCard : discardCards) {
        players.get(USER_INDEX_POSITION).getHand().discardCard(discardCard);
      }

      if (!DEBUG) {
        /*
         * opponents discard their non-valuable cards
         */
        for (int i = 0; i < players.size(); i++) {
          // we loop through all index values of array not assuming
          // which
          // index position user is at... if index is user, continue
          if (i == USER_INDEX_POSITION) continue;
          // now we are in index position related to opponent
          // Cast player as opponent
          Opponent opponent = (Opponent) players.get(i);
          opponent.discardCards();

          int discarded = MAX_HAND_SIZE - players.get(i).getHand().getCardCount();
          if (discarded > 0) {
            System.out.println(
                players.get(i).getName()
                    + " has discarded "
                    + discarded
                    + " card"
                    + (discarded > 1 ? "s" : ""));
          } else {
            System.out.println(players.get(i).getName() + " has chosen to keep their hand");
          }
        }
      }
      pause();

      /*
       * loop through each player and draw new cards
       */
      for (Player player : players) {
        int drawn = 0;
        for (int i = player.getHand().getCardCount() + 1; i <= MAX_HAND_SIZE; i++) {
          player.getHand().addCard(deck.drawCard());
          drawn++;
        }
        if (drawn > 0)
          System.out.println(
              player.getName() + " has drawn " + drawn + " card" + (drawn > 1 ? "s" : ""));
      }
      pause();

      /*
       * show everyone's hand and determine who has best
       */
      int highestScore = -1;
      for (Player player : players) {
        int playerScore = player.getHand().evalHand();
        if (highestScore < playerScore) {
          highestScore = playerScore;
        }

        System.out.println(player.getName() + " has a " + player.getHand().getHandHas());
        showHand(player, player.getName() + "'s hand: ");
        System.out.println();
      }
      // We need ArrayList of who has highest score in case of ties
      ArrayList<Player> winners = new ArrayList<Player>();
      for (Player player : players) {
        int playerScore = player.getHand().evalHand();
        if (highestScore == playerScore) {
          winners.add(player);
        }
      }

      System.out.println();
      if (winners.size() == 1) {
        System.out.println(
            winners.get(0).getName()
                + " wins this hand with a "
                + winners.get(0).getHand().getHandHas()
                + ".");
        didUserWin = (winners.get(0).getName() == players.get(USER_INDEX_POSITION).getName());
      } else {
        // we need to break ties
        for (int i = 0; i < winners.size() - 1; i++)
          for (int j = i + 1; j < winners.size(); j++) {
            Player player1 = winners.get(i);
            Player player2 = winners.get(j);
            if (player1.equals(player2)) continue;
            int result = player1.getHand().willBeat(player2.getHand());
            if (result == 1) {
              // player 2 lost this match, so remove from winners
              // list
              winners.remove(player2);
              j--;
            } else if (result == 0) {
              // player 1 lost this match, so remove from winners
              // list
              winners.remove(player1);
              j--;
            }
          }
        if (winners.size() == 1) {
          System.out.println(
              winners.get(0).getName()
                  + " wins this hand with a "
                  + winners.get(0).getHand().getHandHas()
                  + ".");
          didUserWin = (winners.get(0).getName() == players.get(USER_INDEX_POSITION).getName());
        } else {
          System.out.println("There was an unbreakable tie.");
        }
      }

      // Placeholder - hardcode to end game
      isContinuePlay = false;
    }

    if (didUserWin) System.out.println("Thanks for playing.  You rock!");
    else System.out.println("Thanks for playing.  Better luck next time.");
  }
  /**
   * Method to actually do the calculations of the attack. First grab the dice that were used, do
   * the computations against the operations presented and then deal out damage. Then if an opponent
   * dies, generate a new opponent or if there is none go to the reward screen.
   *
   * @param view view of the application
   */
  public void attackClicked(View view) {
    currentElement = "Light";
    // Generate all of the stuff we need to calculate damage
    // Create the list of the dice in the first row
    ArrayList<Die> firstRow = new ArrayList<Die>();
    // Create the list of dice in the second row
    ArrayList<Die> secondRow = new ArrayList<Die>();
    // Find which dice was used in the first row first position
    ImageButton firstRowFirstDice = (ImageButton) findViewById(R.id.firstRowFirstDice);
    // Find which dice was used in the first row second position
    ImageButton firstRowSecondDice = (ImageButton) findViewById(R.id.firstRowSecondDice);
    // Find which dice was used in the second row first slot
    ImageButton secondRowFirstDice = (ImageButton) findViewById(R.id.secondRowFirstDice);
    // Find which dice was used in the second row second slot
    ImageButton secondRowSecondDice = (ImageButton) findViewById(R.id.secondRowSecondDice);
    if ((firstRowFirstDice.getTag() == null)
        || (firstRowSecondDice.getTag() == null)
        || (secondRowFirstDice.getTag() == null)
        || (secondRowSecondDice.getTag() == null)) {
      Intent healthLow = new Intent(this, HealthTooLowActivity.class);
      healthLow.putExtra("player", player);
      healthLow.putExtra("dice", true);
      startActivityForResult(healthLow, 200);
    } else {

      // Get the value of the dice as a string
      String frfd = firstRowFirstDice.getTag().toString();
      String frsd = firstRowSecondDice.getTag().toString();
      String srfd = secondRowFirstDice.getTag().toString();
      String srsd = secondRowSecondDice.getTag().toString();
      // Find the text view for the first answer
      TextView firstRowAns = (TextView) findViewById(R.id.firstRowFirstAns);
      // Find the text view for the second answer
      TextView secondRowAns = (TextView) findViewById(R.id.secondRowAns);
      TextView firstRowSecondOp = (TextView) findViewById(R.id.firstRowSecondOp);
      TextView secondRowSecondOp = (TextView) findViewById(R.id.secondRowSecondOp);
      boolean isDead = false;
      diceUsed = player.getDiceUsed();
      playerProgressBar = (ProgressBar) findViewById(R.id.playerProgressBar);
      opProgressBar = (ProgressBar) findViewById(R.id.oppProgressBar);
      generateOps = false;
      TextView firstRowFirstOp = (TextView) findViewById(R.id.firstRowFirstOp);
      TextView secondRowFirstOp = (TextView) findViewById(R.id.secondRowFirstOp);
      int firstRowFirstDiceRoll = 0;
      int firstRowSecondDiceRoll = 0;
      int secondRowFirstDiceRoll = 0;
      int secondRowSecondDiceRoll = 0;

      // Loop through the dice used array list to figure out which dice was used in which row
      for (int i = 0; i < diceUsed.size(); i++) {
        // If the dice selected equals the string value of the first row first position dice and the
        // first row array list is less than 2, add it to the first row list
        if (diceUsed.get(i).getDiceType().equals(frfd) && firstRow.size() < 2) {
          firstRow.add(diceUsed.get(i));
          // Else if the dice value is equal to the first row second position and the first row
          // array list is less than 2, add it to the first row list
        } else if (diceUsed.get(i).getDiceType().equals(frsd) && firstRow.size() < 2) {
          firstRow.add(diceUsed.get(i));
          // Else if the dice value is equal to the second row first dice and that list is less than
          // two, add it to the second row list
        } else if (diceUsed.get(i).getDiceType().equals(srfd) && secondRow.size() < 2) {
          secondRow.add(diceUsed.get(i));
          // Else if the dice value is equal to the second row second dice and that list is less
          // than two, add it to the second row list
        } else if (diceUsed.get(i).getDiceType().equals(srsd) && secondRow.size() < 2) {
          secondRow.add(diceUsed.get(i));
        }
      }
      int firstRowTotal = 0;
      int secondRowTotal = 0;

      // For every dice in the first row list, have them roll dice and add it to the total
      for (Die d : firstRow) {
        if (firstRow.indexOf(d) == 0) {
          firstRowFirstDiceRoll = d.rollDice();
          firstRowTotal += firstRowFirstDiceRoll;
        } else {
          if (firstRowFirstOp.getText().equals("+")) {
            firstRowSecondDiceRoll = d.rollDice();
            firstRowTotal += firstRowSecondDiceRoll;
          } else if (firstRowFirstOp.getText().equals("-")) {
            firstRowSecondDiceRoll = d.rollDice();
            firstRowTotal = firstRowTotal - firstRowSecondDiceRoll;

          } else if (firstRowFirstOp.getText().equals("*")) {
            firstRowSecondDiceRoll = d.rollDice();
            firstRowTotal = firstRowTotal * firstRowSecondDiceRoll;
          } else {
            firstRowSecondDiceRoll = d.rollDice();
            firstRowTotal = firstRowTotal / firstRowSecondDiceRoll;
          }
        }
      }
      // For every dice in the second row list, have them roll dice and add it to the total
      for (Die d : secondRow) {
        if (secondRow.indexOf(d) == 0) {
          secondRowFirstDiceRoll = d.rollDice();
          secondRowTotal += secondRowFirstDiceRoll;
        } else {
          if (secondRowFirstOp.getText().equals("+")) {
            secondRowSecondDiceRoll = d.rollDice();
            secondRowTotal += secondRowSecondDiceRoll;
          } else if (secondRowFirstOp.getText().equals("-")) {
            secondRowSecondDiceRoll = d.rollDice();
            secondRowTotal = secondRowTotal - secondRowSecondDiceRoll;

          } else if (secondRowFirstOp.getText().equals("*")) {
            secondRowSecondDiceRoll = d.rollDice();
            secondRowTotal = secondRowTotal * secondRowSecondDiceRoll;
          } else {
            secondRowSecondDiceRoll = d.rollDice();
            secondRowTotal = secondRowTotal / secondRowSecondDiceRoll;
          }
        }
      }
      // If the selected element is fire, add + 1 to each row
      if (currentElement.equals("Fire")) {
        firstRowTotal++;
        secondRowTotal++;
      }
      Log.i("firstrowdm", "first row damage : " + firstRowTotal);
      Log.i("firstrowdmg", "second rwo damage : " + secondRowTotal);
      if (firstRowTotal < 0) {
        firstRowTotal = 0;
      }
      if (secondRowTotal < 0) {
        secondRowTotal = 0;
      }
      this.player.updateMaxSingleDamage(firstRowTotal);
      this.player.updateMaxSingleDamage(secondRowTotal);
      this.player.updateMaxTotalDamage(firstRowTotal + secondRowTotal);
      int firstRowAttack = 0;
      int secondRowAttack = 0;
      String firstRowUser = "";
      String secondRowUser = "";
      double totalRolls = 0;
      double totalHits = 0;
      boolean isDeadOnFirstRoll = false;
      // Now check damage calulations
      // If the first row total from the dice is greater or equal to the answer
      if (firstRowTotal >= Integer.parseInt(firstRowAns.getText().toString())) {
        // do attack,
        firstRowAttack = firstRowTotal - Integer.parseInt(firstRowAns.getText().toString());
        currOpponet.takeDamage((int) (firstRowAttack * player.getDamageRate()));
        firstRowUser = "******";
        // recalc health,
        int gj2 = currOpponet.getCurrentHealth();
        opHealth.setText(currOpponet.getName() + " HP: " + currOpponet.getCurrentHealth());
        opProgressBar.setProgress(currOpponet.getPercentHealthLeft());
        this.player.updateTotalHits();
        this.player.updateTotalRolls();
        totalRolls++;
        totalHits++;
        // Check op health if dead rewards screen,
        if (currOpponet.getCurrentHealth() <= 0) {
          player.swapDiceBackToInv();
          opponents.remove(0);
          generateOps = true;
          isDeadOnFirstRoll = true;
          isDead = true;
          this.player.updateHighestAcc(totalHits / totalRolls * 100);
          generateResults(
              firstRowFirstDiceRoll,
              firstRowSecondDiceRoll,
              secondRowFirstDiceRoll,
              secondRowSecondDiceRoll,
              firstRowFirstOp.getText().toString(),
              secondRowFirstOp.getText().toString(),
              firstRowSecondOp.getText().toString(),
              secondRowSecondOp.getText().toString(),
              firstRowAns.getText().toString(),
              secondRowAns.getText().toString(),
              firstRowAttack,
              firstRowUser,
              secondRowAttack,
              secondRowUser,
              isDeadOnFirstRoll,
              isDead,
              currOpponet.getAttack());
          generateNextOpponent();
        }
        // Else if it is less than the answer
      } else {
        // do enemy attack,
        firstRowAttack = Integer.parseInt(firstRowAns.getText().toString()) - firstRowTotal;
        player.takeDamage(firstRowAttack + currOpponet.getAttack());
        firstRowUser = "******";
        // recalc health,
        playerHealth.setText("Player Health: " + player.getCurrentHealth());
        int d = player.getPercentHealthLeft();
        playerProgressBar.setProgress(player.getPercentHealthLeft());
        this.player.updateTotalRolls();
        totalRolls++;
      }

      // IF the second row total from the dice is greater or equal to the answer
      if ((secondRowTotal >= Integer.parseInt(secondRowAns.getText().toString()))
          && !(currOpponet.getCurrentHealth() < 0)
          && !(isDead)) {
        // do attack,
        secondRowAttack = secondRowTotal - Integer.parseInt(secondRowAns.getText().toString());
        currOpponet.takeDamage((int) (secondRowAttack * player.getDamageRate()));
        secondRowUser = "******";
        // recalc health,
        int o1 = currOpponet.getCurrentHealth();
        opHealth.setText(currOpponet.getName() + " HP: " + currOpponet.getCurrentHealth());
        opProgressBar.setProgress(currOpponet.getPercentHealthLeft());
        this.player.updateTotalHits();
        this.player.updateTotalRolls();
        totalRolls++;
        totalHits++;
        // Check op health if dead rewards screen,
        if (currOpponet.getCurrentHealth() <= 0) {
          player.swapDiceBackToInv();
          if (opponents.size() > 0) opponents.remove(0);
          generateOps = true;
          isDead = true;
          player.swapDiceBackToInv();
          generateResults(
              firstRowFirstDiceRoll,
              firstRowSecondDiceRoll,
              secondRowFirstDiceRoll,
              secondRowSecondDiceRoll,
              firstRowFirstOp.getText().toString(),
              secondRowFirstOp.getText().toString(),
              firstRowSecondOp.getText().toString(),
              secondRowSecondOp.getText().toString(),
              firstRowAns.getText().toString(),
              secondRowAns.getText().toString(),
              firstRowAttack,
              firstRowUser,
              secondRowAttack,
              secondRowUser,
              false,
              isDead,
              currOpponet.getAttack());
          generateNextOpponent();
        }
        // Else if it is less than the answer
      } else if (!(currOpponet.getCurrentHealth() < 0) && !(isDead)) {
        // do enemy attack,
        secondRowAttack = Integer.parseInt(secondRowAns.getText().toString()) - secondRowTotal;
        player.takeDamage(secondRowAttack + currOpponet.getAttack());
        secondRowUser = "******";
        // recalc health,
        playerHealth.setText("Player Health: " + player.getCurrentHealth());
        playerProgressBar.setProgress(player.getPercentHealthLeft());
        this.player.updateTotalRolls();
        totalRolls++;
      }

      // If at this point we have not gotten pushed to the rewards screen, lets see if the player is
      // dead
      if (player.getCurrentHealth() <= 0) {
        player.swapDiceBackToInv();
        generateResults(
            firstRowFirstDiceRoll,
            firstRowSecondDiceRoll,
            secondRowFirstDiceRoll,
            secondRowSecondDiceRoll,
            firstRowFirstOp.getText().toString(),
            secondRowFirstOp.getText().toString(),
            firstRowSecondOp.getText().toString(),
            secondRowSecondOp.getText().toString(),
            firstRowAns.getText().toString(),
            secondRowAns.getText().toString(),
            firstRowAttack,
            firstRowUser,
            secondRowAttack,
            secondRowUser,
            false,
            false,
            currOpponet.getAttack());
        generateDeathScreen();
      }
      // Else the player is alive and so is the monster, so reset the dice locations to null
      // Generate new answers
      // Generate new operations
      // Swap the dice from the players usedDice array to the inventory and keep fighting
      else if (generateOps == false) {
        // reset operations and dice
        player.swapDiceBackToInv();
        generateResults(
            firstRowFirstDiceRoll,
            firstRowSecondDiceRoll,
            secondRowFirstDiceRoll,
            secondRowSecondDiceRoll,
            firstRowFirstOp.getText().toString(),
            secondRowFirstOp.getText().toString(),
            firstRowSecondOp.getText().toString(),
            secondRowSecondOp.getText().toString(),
            firstRowAns.getText().toString(),
            secondRowAns.getText().toString(),
            firstRowAttack,
            firstRowUser,
            secondRowAttack,
            secondRowUser,
            false,
            false,
            currOpponet.getAttack());
        resetDicePics();
        generateOperations(currOpponet.getOp());
        generateAns(level);

        ImageButton frfdTag = (ImageButton) findViewById(R.id.firstRowFirstDice);
        frfdTag.setTag(null);
        ImageButton frsdTag = (ImageButton) findViewById(R.id.firstRowSecondDice);
        frsdTag.setTag(null);
        ImageButton srfdTag = (ImageButton) findViewById(R.id.secondRowFirstDice);
        srfdTag.setTag(null);
        ImageButton srsdTag = (ImageButton) findViewById(R.id.secondRowSecondDice);
        srsdTag.setTag(null);
      }
    }
  }
 /**
  * Sets the content for the fight based on the level chosen. For each level, adds opponents
  * equation operators and answers, plus sets the first background.
  */
 public void setContent() {
   String lastMap = player.getLastMap();
   RelativeLayout rl = (RelativeLayout) findViewById(R.id.fightLayout);
   switch (level) {
     case "1_1":
       rl.setBackground(ContextCompat.getDrawable(this, R.drawable.zone1gobloidspearman));
       Opponent spearman = new Opponent(Opponent.Stats.GB_SPEARMAN, "zone1gobloidspearman");
       currOpponet = spearman;
       setProgressBars(currOpponet);
       spearman.setOp(opList);
       opponents.add(spearman);
       opList.clear();
       opList.add("+");
       generateOperations(opList);
       generateAns(level);
       break;
     case "1_2":
       rl.setBackground(ContextCompat.getDrawable(this, R.drawable.zone1gobloidslasher));
       Opponent slasher = new Opponent(Opponent.Stats.GB_SLASHER, "zone1gobloidslasher");
       currOpponet = slasher;
       setProgressBars(currOpponet);
       opList.clear();
       opList.add("+");
       slasher.setOp(opList);
       opponents.add(slasher);
       generateOperations(opList);
       generateAns(level);
       break;
     case "1_3":
       rl.setBackground(ContextCompat.getDrawable(this, R.drawable.zone1gobloidslasher));
       slasher = new Opponent(Opponent.Stats.GB_SLASHER, "zone1gobloidslasher");
       spearman = new Opponent(Opponent.Stats.GB_SPEARMAN, "zone1gobloidspearman");
       currOpponet = slasher;
       setProgressBars(currOpponet);
       opList.clear();
       opList.add("+");
       opList.add("-");
       spearman.setOp(opList);
       slasher.setOp(opList);
       opponents.add(slasher);
       opponents.add(spearman);
       generateOperations(opList);
       generateAns(level);
       break;
     case "1_4":
       rl.setBackground(ContextCompat.getDrawable(this, R.drawable.zone1gobloidslasher));
       slasher = new Opponent(Opponent.Stats.GB_SLASHER, "zone1gobloidslasher");
       Opponent slasherTwo = new Opponent(Opponent.Stats.GB_SLASHER, "zone1gobloidslasher");
       Opponent shaman = new Opponent(Opponent.Stats.GB_SHAMAN, "zone1gobloidshaman");
       currOpponet = slasher;
       setProgressBars(currOpponet);
       opList.clear();
       opList.add("+");
       opList.add("-");
       shaman.setOp(opList);
       slasher.setOp(opList);
       slasherTwo.setOp(opList);
       opponents.add(slasher);
       opponents.add(shaman);
       opponents.add(slasherTwo);
       generateOperations(opList);
       generateAns(level);
       break;
     case "1_5":
       rl.setBackground(ContextCompat.getDrawable(this, R.drawable.zone1gobloidspearman));
       spearman = new Opponent(Opponent.Stats.GB_SPEARMAN, "zone1gobloidspearman");
       shaman = new Opponent(Opponent.Stats.GB_SHAMAN, "zone1gobloidshaman");
       Opponent grabber = new Opponent(Opponent.Stats.SK_GRABBER, "zone1skeletoniangrabber");
       currOpponet = spearman;
       setProgressBars(currOpponet);
       opList.clear();
       opList.add("+");
       opList.add("-");
       spearman.setOp(opList);
       shaman.setOp(opList);
       grabber.setOp(opList);
       opponents.add(spearman);
       opponents.add(shaman);
       opponents.add(grabber);
       generateOperations(opList);
       generateAns(level);
       break;
     case "2_1":
       rl.setBackground(ContextCompat.getDrawable(this, R.drawable.zone2gobloidslasher));
       slasher = new Opponent(Opponent.Stats.GB_SLASHER, "zone2gobloidslasher");
       grabber = new Opponent(Opponent.Stats.SK_GRABBER, "zone2skeletoniangrabber");
       currOpponet = slasher;
       setProgressBars(currOpponet);
       opList.clear();
       opList.add("+");
       opList.add("-");
       slasher.setOp(opList);
       grabber.setOp(opList);
       opponents.add(slasher);
       opponents.add(grabber);
       generateOperations(opList);
       generateAns(level);
       break;
     case "2_2":
       rl.setBackground(ContextCompat.getDrawable(this, R.drawable.zone2skeletoniangrabber));
       grabber = new Opponent(Opponent.Stats.SK_GRABBER, "zone2skeletoniangrabber");
       Opponent smasher = new Opponent(Opponent.Stats.SK_SMASHER, "zone2skeletoniansmasher");
       Opponent grabberTwo = new Opponent(Opponent.Stats.SK_GRABBER, "zone2skeletoniangrabber");
       currOpponet = grabber;
       setProgressBars(currOpponet);
       opList.clear();
       opList.add("+");
       opList.add("-");
       opList.add("*");
       grabber.setOp(opList);
       smasher.setOp(opList);
       grabberTwo.setOp(opList);
       opponents.add(grabber);
       opponents.add(smasher);
       opponents.add(grabberTwo);
       generateOperations(opList);
       generateAns(level);
       break;
     case "2_3":
       rl.setBackground(ContextCompat.getDrawable(this, R.drawable.zone2skeletoniansmasher));
       grabber = new Opponent(Opponent.Stats.SK_GRABBER, "zone2skeletoniangrabber");
       smasher = new Opponent(Opponent.Stats.SK_SMASHER, "zone2skeletoniansmasher");
       Opponent smasherTwo = new Opponent(Opponent.Stats.SK_SMASHER, "zone2skeletoniansmasher");
       currOpponet = smasher;
       setProgressBars(currOpponet);
       opList.clear();
       opList.add("+");
       opList.add("-");
       opList.add("*");
       grabber.setOp(opList);
       smasher.setOp(opList);
       smasherTwo.setOp(opList);
       opponents.add(smasher);
       opponents.add(grabber);
       opponents.add(smasherTwo);
       generateOperations(opList);
       generateAns(level);
       break;
     case "2_4":
       rl.setBackground(ContextCompat.getDrawable(this, R.drawable.zone2skeletonianwizard));
       Opponent wizard = new Opponent(Opponent.Stats.SK_WIZARD, "zone2skeletonianwizard");
       currOpponet = wizard;
       setProgressBars(currOpponet);
       opList.clear();
       opList.add("+");
       opList.add("-");
       opList.add("*");
       wizard.setOp(opList);
       opponents.add(wizard);
       generateOperations(opList);
       generateAns(level);
       break;
     case "2_5":
       rl.setBackground(ContextCompat.getDrawable(this, R.drawable.zone2skeletoniangrabber));
       grabber = new Opponent(Opponent.Stats.SK_GRABBER, "zone2skeletoniangrabber");
       wizard = new Opponent(Opponent.Stats.SK_WIZARD, "zone2skeletonianwizard");
       currOpponet = grabber;
       setProgressBars(currOpponet);
       opList.clear();
       opList.add("+");
       opList.add("-");
       opList.add("*");
       wizard.setOp(opList);
       grabber.setOp(opList);
       opponents.add(grabber);
       opponents.add(wizard);
       generateOperations(opList);
       generateAns(level);
       break;
     case "3_1":
       rl.setBackground(ContextCompat.getDrawable(this, R.drawable.zone3skeletoniangrabber));
       grabber = new Opponent(Opponent.Stats.SK_GRABBER, "zone3skeletoniangrabber");
       spearman = new Opponent(Opponent.Stats.GB_SPEARMAN, "zone3gobloidspearman");
       shaman = new Opponent(Opponent.Stats.GB_SHAMAN, "zone3gobloidshaman");
       currOpponet = grabber;
       setProgressBars(currOpponet);
       opList.clear();
       opList.add("+");
       opList.add("-");
       opList.add("*");
       spearman.setOp(opList);
       shaman.setOp(opList);
       grabber.setOp(opList);
       opponents.add(grabber);
       opponents.add(spearman);
       opponents.add(shaman);
       generateOperations(opList);
       generateAns(level);
       break;
     case "3_2":
       rl.setBackground(ContextCompat.getDrawable(this, R.drawable.zone3skeletoniangrabber));
       grabber = new Opponent(Opponent.Stats.SK_GRABBER, "zone3skeletoniangrabber");
       smasher = new Opponent(Opponent.Stats.SK_SMASHER, "zone3skeletoniansmasher");
       slasher = new Opponent(Opponent.Stats.GB_SLASHER, "zone3gobloidslasher");
       currOpponet = grabber;
       setProgressBars(currOpponet);
       opList.clear();
       opList.add("+");
       opList.add("-");
       opList.add("*");
       opList.add("/");
       smasher.setOp(opList);
       slasher.setOp(opList);
       grabber.setOp(opList);
       opponents.add(grabber);
       opponents.add(smasher);
       opponents.add(slasher);
       generateOperations(opList);
       generateAns(level);
       break;
     case "3_3":
       rl.setBackground(ContextCompat.getDrawable(this, R.drawable.zone3gobloidslasher));
       smasher = new Opponent(Opponent.Stats.SK_SMASHER, "zone3skeletoniansmasher");
       slasher = new Opponent(Opponent.Stats.GB_SLASHER, "zone3gobloidslasher");
       slasherTwo = new Opponent(Opponent.Stats.GB_SLASHER, "zone3gobloidslasher");
       currOpponet = slasher;
       setProgressBars(currOpponet);
       opList.clear();
       opList.add("+");
       opList.add("-");
       opList.add("*");
       opList.add("/");
       smasher.setOp(opList);
       slasher.setOp(opList);
       slasherTwo.setOp(opList);
       opponents.add(slasher);
       opponents.add(smasher);
       opponents.add(slasherTwo);
       generateOperations(opList);
       generateAns(level);
       break;
     case "3_4":
       rl.setBackground(ContextCompat.getDrawable(this, R.drawable.zone3skeletoniansmasher));
       smasher = new Opponent(Opponent.Stats.SK_SMASHER, "zone3skeletoniansmasher");
       shaman = new Opponent(Opponent.Stats.GB_SLASHER, "zone3gobloidslasher");
       smasherTwo = new Opponent(Opponent.Stats.GB_SLASHER, "zone3skeletoniansmasher");
       currOpponet = smasher;
       setProgressBars(currOpponet);
       opList.clear();
       opList.add("+");
       opList.add("-");
       opList.add("*");
       opList.add("/");
       smasher.setOp(opList);
       shaman.setOp(opList);
       smasherTwo.setOp(opList);
       opponents.add(smasher);
       opponents.add(shaman);
       opponents.add(smasherTwo);
       generateOperations(opList);
       generateAns(level);
       break;
     case "3_5":
       rl.setBackground(ContextCompat.getDrawable(this, R.drawable.zone3gobloidspearman));
       spearman = new Opponent(Opponent.Stats.GB_SPEARMAN, "zone3gobloidspearman");
       shaman = new Opponent(Opponent.Stats.GB_SHAMAN, "zone3gobloidshaman");
       grabber = new Opponent(Opponent.Stats.SK_GRABBER, "zone3skeletoniangrabber");
       wizard = new Opponent(Opponent.Stats.SK_WIZARD, "zone3skeletonianwizard");
       currOpponet = spearman;
       setProgressBars(currOpponet);
       opList.clear();
       opList.add("+");
       opList.add("-");
       opList.add("*");
       opList.add("/");
       spearman.setOp(opList);
       shaman.setOp(opList);
       grabber.setOp(opList);
       wizard.setOp(opList);
       opponents.add(spearman);
       opponents.add(grabber);
       opponents.add(shaman);
       opponents.add(wizard);
       generateOperations(opList);
       generateAns(level);
       break;
   }
 }
Exemple #11
0
  // Build the board with predetermined values for each object in the game
  private void buildBoardValue(Gameboard gameboard, Player player, Opponent opponent) {

    // resets the tilevalue, inReachTurrent and inReachBullet values
    for (int i = 0; i < gameboard.getWidth(); i++) {
      for (int j = 0; j < gameboard.getHeight(); j++) {
        tileValue[i][j] = 0;
        for (int k = 0; k < 4; k++) {
          inReachTurret[i][j][k] = null;
          inReachBullet[i][j][k] = null;
        }
      }
    }

    ArrayList<PowerUp> allPowerUps = gameboard.getPowerUps();

    // set the value for each powertype
    for (int i = 0; i < allPowerUps.size(); i++) {
      switch (allPowerUps.get(i).getPowerUpType()) {
        case SHIELD:
          tileValue[allPowerUps.get(i).getX()][allPowerUps.get(i).getY()] = 50;
          break;
        case LASER:
          tileValue[allPowerUps.get(i).getX()][allPowerUps.get(i).getY()] = 45;
          break;
        case TELEPORT:
          tileValue[allPowerUps.get(i).getX()][allPowerUps.get(i).getY()] = 40;
          break;
      }
    }

    ArrayList<Turret> allTurrets = gameboard.getTurrets();

    // sets the value according to condition of the bot
    for (int i = 0; i < allTurrets.size(); i++) {
      Turret t = allTurrets.get(i);
      tileValue[t.getX()][t.getY()] = -1000;
      if (!t.isDead()) {
        Boolean[] goDir = {true, true, true, true};

        int shieldVal = 0;
        if (player.isShieldActive()) {
          shieldVal = 100;
        } else if (player.getLaserCount() > 0) {
          shieldVal = 60;
        } else if (player.getShieldCount() > 0) {
          shieldVal = 43;
        } else {
          shieldVal = -10;
        }

        for (int j = 1; j <= 5; j++) {
          try {
            int nx, ny;
            nx = (t.getX() + j) % gameboard.getWidth();
            ny = t.getY();
            if (gameboard.isWallAtTile(nx, ny)) goDir[0] = false;
            else if (goDir[0]) {
              tileValue[nx][ny] = shieldVal;
              inReachTurret[nx][ny][returnNextIndex(inReachTurret[nx][ny])] = t;
            }
            nx = (t.getX() - j + gameboard.getWidth()) % gameboard.getWidth();
            ny = t.getY();
            if (gameboard.isWallAtTile(nx, ny)) goDir[1] = false;
            else if (goDir[1]) {
              tileValue[nx][ny] = shieldVal;
              inReachTurret[nx][ny][returnNextIndex(inReachTurret[nx][ny])] = t;
            }
            nx = t.getX();
            ny = (t.getY() + j) % gameboard.getHeight();
            if (gameboard.isWallAtTile(nx, ny)) goDir[2] = false;
            else if (goDir[2]) {
              tileValue[nx][ny] = shieldVal;
              inReachTurret[nx][ny][returnNextIndex(inReachTurret[nx][ny])] = t;
            }
            nx = t.getX();
            ny = (t.getY() - j + gameboard.getHeight()) % gameboard.getHeight();
            if (gameboard.isWallAtTile(nx, ny)) goDir[3] = false;
            else if (goDir[3]) {
              tileValue[nx][ny] = shieldVal;
              inReachTurret[nx][ny][returnNextIndex(inReachTurret[nx][ny])] = t;
            }
          } catch (Exception e) {
          }
        }
      }
    }

    // Adjust the tile values to incorporate whether the opponent has laser or not
    Boolean[] goDir = {true, true, true, true};
    if (opponent.getLaserCount() >= 1) {
      try {
        for (int j = 1; j <= 5; j++) {
          int nx, ny;
          nx = (opponent.getX() + j) % gameboard.getWidth();
          ny = opponent.getY();
          if (gameboard.isWallAtTile(nx, ny)) goDir[0] = false;
          else if (goDir[0]) {
            if (nx == player.getX() && ny == player.getY()) tileValue[nx][ny] = -4;
            else tileValue[nx][ny] = -1;
          }
          nx = (opponent.getX() - j + gameboard.getWidth()) % gameboard.getWidth();
          ny = opponent.getY();
          if (gameboard.isWallAtTile(nx, ny)) goDir[1] = false;
          else if (goDir[1]) {
            if (nx == player.getX() && ny == player.getY()) tileValue[nx][ny] = -4;
            else tileValue[nx][ny] = -1;
          }
          nx = opponent.getX();
          ny = (opponent.getY() + j) % gameboard.getHeight();
          if (gameboard.isWallAtTile(nx, ny)) goDir[2] = false;
          else if (goDir[2]) {
            if (nx == player.getX() && ny == player.getY()) tileValue[nx][ny] = -4;
            else tileValue[nx][ny] = -1;
          }
          nx = opponent.getX();
          ny = (opponent.getY() - j + gameboard.getHeight()) % gameboard.getHeight();
          if (gameboard.isWallAtTile(nx, ny)) goDir[3] = false;
          else if (goDir[3]) {
            if (nx == player.getX() && ny == player.getY()) tileValue[nx][ny] = -4;
            else tileValue[nx][ny] = -1;
          }
        }
      } catch (Exception e) {
      }
    }

    // modifies the gameboard tile vales to incorporate bullets
    for (int i = 0; i < gameboard.getBullets().size(); i++) {
      Bullet b = gameboard.getBullets().get(i);
      int h = gameboard.getHeight();
      int w = gameboard.getWidth();
      int nx, ny;
      switch (b.getDirection()) {
        case UP:
          nx = b.getX();
          ny = (b.getY() + h - 1) % h;
          if (nx == player.getX() && ny == player.getY()) tileValue[nx][ny] = -4;
          else tileValue[nx][ny] = -2;
          inReachBullet[nx][ny][returnNextIndex(inReachBullet[nx][ny])] = b;
          break;
        case RIGHT:
          nx = (b.getX() + 1) % w;
          ny = b.getY();
          if (nx == player.getX() && ny == player.getY()) tileValue[nx][ny] = -4;
          else tileValue[nx][ny] = -2;
          inReachBullet[nx][ny][returnNextIndex(inReachBullet[nx][ny])] = b;
          break;
        case DOWN:
          nx = b.getX();
          ny = (b.getY() + 1) % h;
          if (nx == player.getX() && ny == player.getY()) tileValue[nx][ny] = -4;
          else tileValue[nx][ny] = -2;
          inReachBullet[nx][ny][returnNextIndex(inReachBullet[nx][ny])] = b;
          break;
        case LEFT:
          nx = (b.getX() + w - 1) % w;
          ny = b.getY();
          if (nx == player.getX() && ny == player.getY()) tileValue[nx][ny] = -4;
          else tileValue[nx][ny] = -2;
          inReachBullet[nx][ny][returnNextIndex(inReachBullet[nx][ny])] = b;
          break;
      }
    }

    ArrayList<Wall> allWalls = gameboard.getWalls();

    for (int i = 0; i < allWalls.size(); i++) {
      tileValue[allWalls.get(i).getX()][allWalls.get(i).getY()] = -1000;
    }
  }
Exemple #12
0
  // augments bfs algorithm to navigate the board and decides the move
  private Move bfs(
      Gameboard gameboard,
      Player player,
      Opponent opponent,
      int x,
      int y,
      Direction dir,
      int maxVal) {
    Node record[][][] = new Node[gameboard.getWidth()][gameboard.getHeight()][4];
    Node nextMove = null;
    Node lastMove = null;

    // System.out.println(dir);

    int d = 0;
    switch (dir) {
      case UP:
        d = 0;
        break;
      case DOWN:
        d = 2;
        break;
      case LEFT:
        d = 3;
        break;
      case RIGHT:
        d = 1;
        break;
    }

    queue.clear();
    queue.add(new Node(x, y, null, 0, d));

    while (!queue.isEmpty()) {
      Node curNode = queue.remove();

      // System.out.println("CurNode: " + curNode.toString());

      try {
        if (gameboard.isWallAtTile(curNode.x, curNode.y)) continue;
        else if (gameboard.isTurretAtTile(curNode.x, curNode.y)) continue;
        else if (opponent.getX() == curNode.x && opponent.getY() == curNode.y) continue;
      } catch (Exception e) {

      }

      if (tileValue[curNode.x][curNode.y] == maxVal) {
        // System.out.println("Target: " + curNode.toString());
        nextMove = getPath(curNode);
        lastMove = curNode;
        break;
      } else if (tileValue[curNode.x][curNode.y] > 40 && curNode.steps <= 5) {
        // System.out.println("Target: " + curNode.toString());
        nextMove = getPath(curNode);
        lastMove = curNode;
        break;
      }

      Node newNode = null;
      int curDir = -1;
      switch (curNode.d) {
        case UP:
          // System.out.println("Facing UP!");
          newNode =
              new Node(
                  curNode.x,
                  (curNode.y - 1 + gameboard.getHeight()) % gameboard.getHeight(),
                  curNode,
                  curNode.steps + 1,
                  0);
          // System.out.println("Declared this node: " + newNode.toString());
          if (record[newNode.x][newNode.y][newNode.getDirInt()] == null) {
            queue.add(newNode);
            record[newNode.x][newNode.y][newNode.getDirInt()] = newNode;
            // System.out.println("Pushed: " + newNode.toString());
          }
          curDir = 0;
          break;
        case RIGHT:
          // System.out.println("Facing Right!");
          newNode =
              new Node(
                  (curNode.x + 1 + gameboard.getWidth()) % gameboard.getWidth(),
                  curNode.y,
                  curNode,
                  curNode.steps + 1,
                  1);
          // System.out.println("Declared this node: " + newNode.toString());
          if (record[newNode.x][newNode.y][newNode.getDirInt()] == null) {
            queue.add(newNode);
            record[newNode.x][newNode.y][newNode.getDirInt()] = newNode;
            // System.out.println("Pushed: " + newNode.toString());
          }
          curDir = 1;
          break;
        case DOWN:
          newNode =
              new Node(
                  curNode.x,
                  (curNode.y + 1 + gameboard.getHeight()) % gameboard.getHeight(),
                  curNode,
                  curNode.steps + 1,
                  2);
          if (record[newNode.x][newNode.y][newNode.getDirInt()] == null) {
            queue.add(newNode);
            record[newNode.x][newNode.y][newNode.getDirInt()] = newNode;
          }
          curDir = 2;
          break;
        case LEFT:
          newNode =
              new Node(
                  (curNode.x - 1 + gameboard.getWidth()) % gameboard.getWidth(),
                  curNode.y,
                  curNode,
                  curNode.steps + 1,
                  3);
          if (record[newNode.x][newNode.y][newNode.getDirInt()] == null) {
            queue.add(newNode);
            record[newNode.x][newNode.y][newNode.getDirInt()] = newNode;
          }
          curDir = 3;
          break;
      }

      for (int i = 1; i <= 3; i++) {
        int fuDir = (curDir + i) % 4;
        switch (fuDir) {
          case 0:
            newNode =
                new Node(
                    curNode.x,
                    (curNode.y - 1 + gameboard.getHeight()) % gameboard.getHeight(),
                    curNode,
                    curNode.steps + 2,
                    0);
            if (record[newNode.x][newNode.y][newNode.getDirInt()] == null) {
              queue.add(newNode);
              record[newNode.x][newNode.y][newNode.getDirInt()] = newNode;
              // System.out.println("Pushed: " + newNode.toString());
            }
            break;
          case 1:
            newNode =
                new Node(
                    (curNode.x + 1 + gameboard.getWidth()) % gameboard.getWidth(),
                    curNode.y,
                    curNode,
                    curNode.steps + 2,
                    1);
            if (record[newNode.x][newNode.y][newNode.getDirInt()] == null) {
              queue.add(newNode);
              record[newNode.x][newNode.y][newNode.getDirInt()] = newNode;
              // System.out.println("Pushed: " + newNode.toString());
            }
            break;
          case 2:
            newNode =
                new Node(
                    curNode.x,
                    (curNode.y + 1 + gameboard.getHeight()) % gameboard.getHeight(),
                    curNode,
                    curNode.steps + 2,
                    2);
            if (record[newNode.x][newNode.y][newNode.getDirInt()] == null) {
              queue.add(newNode);
              record[newNode.x][newNode.y][newNode.getDirInt()] = newNode;
              // System.out.println("Pushed: " + newNode.toString());
            }
            break;
          case 3:
            newNode =
                new Node(
                    (curNode.x - 1 + gameboard.getWidth()) % gameboard.getWidth(),
                    curNode.y,
                    curNode,
                    curNode.steps + 2,
                    3);
            if (record[newNode.x][newNode.y][newNode.getDirInt()] == null) {
              queue.add(newNode);
              record[newNode.x][newNode.y][newNode.getDirInt()] = newNode;
              // System.out.println("Pushed: " + newNode.toString());
            }
            break;
        }
      }
    }

    // System.out.println("Nextmove: " + nextMove.toString());
    if (nextMove.steps == 1 && tileValue[nextMove.x][nextMove.y] == -1) {
      if (player.getShieldCount() >= 1) {
        return Move.SHIELD;
      } else {
        return Move.NONE;
      }
    } else if (nextMove.steps == 1 && tileValue[nextMove.x][nextMove.y] == -2) {
      for (int i = 0; i < 4 && inReachBullet[nextMove.x][nextMove.y][i] != null; i++) {
        Bullet b = inReachBullet[nextMove.x][nextMove.y][i];
        if (player.getDirection() == Direction.opposite(b.getDirection())) {
          return Direction.directionToMovement(Direction.clockwise(player.getDirection()));
        } else {
          return Move.NONE;
        }
      }
    } else if (lastMove.steps <= 1) {
      Turret t = inReachTurret[lastMove.x][lastMove.y][0];
      if (tileValue[lastMove.x][lastMove.y] == 60 && t.getCooldownTime() >= 2) {
        // System.out.format("Turret x:%d y:%d cool:%d fire:%d\n", t.getX(), t.getY(),
        // t.getCooldownTime(), t.getFireTime());
        int cycle = t.getCooldownTime() + t.getFireTime();
        int fuStatus1 = gameboard.getCurrentTurnNumber() % cycle + 1;
        int fuStatus2 = gameboard.getCurrentTurnNumber() % cycle + 2;
        if (lastMove.steps == 1) {
          if (fuStatus1 > t.getFireTime()
              && fuStatus1 <= cycle
              && fuStatus2 > t.getFireTime()
              && fuStatus2 <= cycle) {
            return Move.FORWARD;
          } else {
            return Move.NONE;
          }
        } else if (lastMove.steps == 0) {
          return Move.LASER;
        }
      } else if (tileValue[lastMove.x][lastMove.y] == 43
          || (t != null && t.getCooldownTime() <= 1 && player.getShieldCount() >= 1)) {
        // Turret t = inReachTurret[lastMove.x][lastMove.y][0];
        // System.out.format("Turret x:%d y:%d cool:%d fire:%d\n", t.getX(), t.getY(),
        // t.getCooldownTime(), t.getFireTime());
        int cycle = t.getCooldownTime() + t.getFireTime();
        int fuStatus1 = gameboard.getCurrentTurnNumber() % cycle + 1;
        int fuStatus2 = gameboard.getCurrentTurnNumber() % cycle + 2;
        if (lastMove.steps == 1 && !player.isShieldActive()) {
          if (!t.isFiringNextTurn()) {
            return Move.FORWARD;
          } else if (fuStatus2 <= t.getFireTime()) {
            return Move.SHIELD;
          } else if (fuStatus2 > t.getFireTime() && fuStatus2 <= t.getCooldownTime()) {
            return Move.NONE;
          }
        } else if (player.isShieldActive()) {
          return Move.FORWARD;
        } else if (lastMove.steps == 0) {
          if (t.isFiringNextTurn()) {
            return Move.SHIELD;
          } else {
            return Move.NONE;
          }
        }
      } else if (tileValue[lastMove.x][lastMove.y] > 40
          && tileValue[lastMove.x][lastMove.y] <= 50) {
        return Move.FORWARD;
      } else if (tileValue[lastMove.x][lastMove.y] == 100) {
        return Move.FORWARD;
      } else if (tileValue[player.getX()][player.getY()] < 0) {
        return Move.FORWARD;
      }
    } else {
      if (nextMove.steps == 2) {
        return Direction.directionToMovement(nextMove.d);
      } else {
        Turret t = inReachTurret[nextMove.x][nextMove.y][0];
        if (t == null || !t.isFiringNextTurn()) {
          // System.out.println("1");
          return Move.FORWARD;
        } else return Move.NONE;
      }
    }

    return Move.NONE;

    // for(int x=0;x<gameboard.getWidth();x++) {
    // 	for(int y=0;y<gameboard.getHeight();y++) {
    // 		record[x][y][] = new Node(0,1, null,-1, -1)
    // 	}
    // }

  }