It is currently 25 Apr 2024, 00:53
   
Text Size

Quest Mode source code changes

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Quest Mode source code changes

Postby mtgrares » 30 Apr 2009, 18:57

This is just for DennisBergkamp. I guess I could just private message but it is long, so I decided just to do this. (I can't imagine anyone else really wanting to read this, but...who knows.)

This update also requires the files questDecks-easy.txt, questDecks-medium.txt, and questDecks-hard.txt and they must have at least 3 decks names in each file. Attached are the files from Chris' 04-26-09 release: questData, questDecks-easy.txt, questDecks-medium.txt, and questDecks-hard.txt

In case you have other questions you can also check out the complete source that is in
http://www.mediafire.com/file/g4bjwmtnmny/beta-forge.zip

As always post any questions that you have.

Gui_QuestOptions.java - added one line questData.readAIQuestDeckFiles();

Code: Select all
  void newQuestButton_actionPerformed(ActionEvent e)
  {
    String difficulty = "";

    if(easyRadio.isSelected())
      difficulty = questData.EASY;

    else if(mediumRadio.isSelected())
      difficulty = questData.MEDIUM;

    else if(hardRadio.isSelected())
      difficulty = questData.HARD;

    else if(veryHardRadio.isSelected())
      difficulty = questData.VERY_HARD;

    else //user didn't select a difficulty
      return;

    //give the user a few cards to build a deck
    questData.newGame(difficulty);

    copyAIDecks(questData, QuestData.loadData());
    QuestData.saveData(questData);

    questData.readAIQuestDeckFiles();

    //set global variable
    AllZone.QuestData = questData;

    dispose();
    new Gui_Quest();
  }
I put all of my changes to QuestData at the beginning. I start and end with the string //CHANGED!!!!!!!!!!!!!!!!!
I think I changed and then unchanged the constructor, so I think I didn't change it after all but I'm not 100% sure.

Code: Select all
//when you create QuestData and AFTER you copy the AI decks over
//you have to call one of these two methods below
//see Gui_QuestOptions for more details
//
//static readAIQuestDeckFiles(QuestData data, ArrayList aiDeckNames)
//OR non-static readAIQuestDeckFiles()
//which reads the files "questDecks-easy.txt", "questDecks-medium.txt","questDecks-hard.txt",
public class QuestData
{
  //CHANGED!!!!!!!!!!!!!!!!!
  //also changed Gui_QuestOptions.newQuestButton_actionPerformed()
  //copyAIDecks(questData, QuestData.loadData());
  //QuestData.saveData(questData);
  //questData.readAIQuestDeckFiles();

  //easy, medium, hard, very hard
  //easy gets a new booster pack after 1 wins
  //medium gets a new booster pack after after 2 wins, etc...
  //these numbers are just guesses
  private int[] addCardsArray = {1, 2, 2, 2};

  private ArrayList easyAIDecks;
  private ArrayList mediumAIDecks;
  private ArrayList hardAIDecks;

  public String[] getOpponents()
  {
    int difficulty[][] =
    {
      //if getWin() is < 4 return use easyAIDecks
      //if getWin() is < 7 return mediumAIDecks
      //else use hardAIDecks
      {4,7},   //easy difficulty
      {6, 12}, //medium difficulty
      {10, 20},//hard difficulty
      {10, 20},//very hard difficulty
    };

    int index = convertDifficultyToIndex(getDifficulty());

    if(getWin() < difficulty[index][0])
      return getOpponents(easyAIDecks);

    if(getWin() < difficulty[index][1])
      return getOpponents(mediumAIDecks);

    return getOpponents(hardAIDecks);
  }//getOpponents()

  public String[] getOpponents(ArrayList aiDeck)
  {
    Collections.shuffle(aiDeck);

    return new String[]
    {
      aiDeck.get(0).toString(),
      aiDeck.get(1).toString(),
      aiDeck.get(2).toString()
    };

  }//getOpponents()

  private static ArrayList readFile(String filename, ArrayList aiDecks)
  {
    ArrayList list = FileUtil.readFile(filename);

    //remove any blank lines
    ArrayList noBlankLines = new ArrayList();
    String s;
    for(int i = 0; i < list.size(); i++)
    {
      s = list.get(i).toString().trim();
      if(! s.equals(""))
        noBlankLines.add(s);
    }
    list = noBlankLines;

    if(list.size() < 3)
      showError("QuestData : readFile() error, file - " +filename +" - is too short, it must contain at least 3 ai decks names");


    for(int i = 0; i < list.size(); i++)
      if(! aiDecks.contains(list.get(i).toString()))
        showError("QuestData : readFile() error, file - " +filename +" - contains the invalid ai deck name: " +list.get(i));


    return list;
  }//readFile()

  public QuestData()
  {
    for(int i = 0; i < 40; i++)
    {
      cardPool.add("Forest");
      cardPool.add("Mountain");
      cardPool.add("Swamp");
      cardPool.add("Island");
      cardPool.add("Plains");
    }//for
  }//QuestData

  public void readAIQuestDeckFiles()
  {
    readAIQuestDeckFiles(this, ai_getDeckNames());
  }

  static public void readAIQuestDeckFiles(QuestData data, ArrayList aiDeckNames)
  {
    data.easyAIDecks = readFile("questDecks-easy.txt", aiDeckNames);
    data.mediumAIDecks = readFile("questDecks-medium.txt", aiDeckNames);
    data.hardAIDecks = readFile("questDecks-hard.txt", aiDeckNames);
  }

  static public QuestData loadData()
  {
    try
    {
      //read file "questData"
      ObjectInputStream in = new ObjectInputStream(new FileInputStream(saveFileName));
      Object o = in.readObject();
      in.close();

      QuestData_State state = (QuestData_State) o;

      QuestData data = new QuestData();

      data.win        = state.win;
      data.lost       = state.lost;
      data.rankIndex  = state.rankIndex;
      data.difficulty = state.difficulty;

      data.cardPool = state.cardPool;
      data.myDecks  = state.myDecks;
      data.aiDecks  = state.aiDecks;

      readAIQuestDeckFiles(data, new ArrayList(data.aiDecks.keySet()));

      return data;
    }//try
    catch(Exception ex)
    {
      ex.printStackTrace();
      showError("Error loading Quest Data, " +ex);
    }

    return null;
  }//loadData()

  //CHANGED!!!!!!!!!!!!!!!!!
Attachments
questData_04-26-09.zip
questData, questDecks-easy.txt, questDecks-medium.txt, questDecks-hard.txt
(11.5 KiB) Downloaded 243 times
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Re: Quest Mode source code changes

Postby DennisBergkamp » 30 Apr 2009, 20:16

Ok, cool, I'll merge them :)
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Quest Mode source code changes

Postby Chris H. » 30 Apr 2009, 21:30

DennisBergkamp wrote:Ok, cool, I'll merge them :)
Yeah, very cool. 8)

With my beta testing, Forge was dividing the quest into stages and was displaying the names for decks in the appropriate questDecks file.

The number of decks in the easy and medium groups are slowly growing. I finished several more decks today. It will likely be several more weeks before I have enough to release another update to these files. :wink:
User avatar
Chris H.
Forge Moderator
 
Posts: 6320
Joined: 04 Nov 2008, 12:11
Location: Mac OS X Yosemite
Has thanked: 644 times
Been thanked: 643 times

Re: Quest Mode source code changes

Postby Huggybaby » 01 May 2009, 03:37

mtgrares wrote:(I can't imagine anyone else really wanting to read this, but...who knows.)
HA! I read it! and I wanted to too! :lol:
User avatar
Huggybaby
Administrator
 
Posts: 3207
Joined: 15 Jan 2006, 19:44
Location: Finally out of Atlanta
Has thanked: 701 times
Been thanked: 594 times


Return to Forge

Who is online

Users browsing this forum: No registered users and 159 guests


Who is online

In total there are 159 users online :: 0 registered, 0 hidden and 159 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 159 guests

Login Form