mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
*Moved HandSize shenanigans into the Player class, tightened up the code overall.
*Fixed minor error in stack description for AF_Tap abilities. *Added Vedalken Certarch.
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -5625,7 +5625,6 @@ src/forge/ComputerAI_General.java -text svneol=native#text/plain
|
||||
src/forge/ComputerAI_Input.java svneol=native#text/plain
|
||||
src/forge/ComputerAI_Rats2.java svneol=native#text/plain
|
||||
src/forge/ComputerAI_StackNotEmpty.java svneol=native#text/plain
|
||||
src/forge/ComputerAI_counterSpells.java -text svneol=native#text/plain
|
||||
src/forge/ComputerAI_counterSpells2.java -text svneol=native#text/plain
|
||||
src/forge/ComputerUtil.java -text svneol=native#text/plain
|
||||
src/forge/ComputerUtil_Attack2.java svneol=native#text/plain
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#Forge
|
||||
#Mon Nov 08 21:31:15 CET 2010
|
||||
gui.laf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel
|
||||
AI.stack.land=false
|
||||
gui.new=true
|
||||
stack.offset=tiny
|
||||
card.images.size=medium
|
||||
card.scale.larger.than.original=true
|
||||
card.overlay=true
|
||||
stack.max.size=3
|
||||
loss.condition.milling=false
|
||||
gui.laf.fonts=false
|
||||
|
||||
@@ -151,7 +151,7 @@ public class AbilityFactory_PermanentState {
|
||||
@Override
|
||||
public String getStackDescription(){
|
||||
// when getStackDesc is called, just build exactly what is happening
|
||||
StringBuilder sb = new StringBuilder("Untap ");
|
||||
StringBuilder sb = new StringBuilder("Tap ");
|
||||
String name = af.getHostCard().getName();
|
||||
Card tgt = getTargetCard();
|
||||
if (tgt != null)
|
||||
|
||||
@@ -12211,34 +12211,13 @@ public class CardFactory implements NewConstants {
|
||||
private static final long serialVersionUID = 98743547743456L;
|
||||
|
||||
public void execute() {
|
||||
card.setSVar("HSStamp","" + Input_Cleanup.GetHandSizeStamp());
|
||||
if(card.getController() == AllZone.HumanPlayer) {
|
||||
//System.out.println("Human played me! Mode(" + Mode + ") Amount(" + Amount + ") Target(" + Target + ")" );
|
||||
if(Target.equals("Self")) {
|
||||
Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp"))));
|
||||
}
|
||||
else if(Target.equals("Opponent")) {
|
||||
Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp"))));
|
||||
}
|
||||
else if(Target.equals("All")) {
|
||||
Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp"))));
|
||||
Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp"))));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//System.out.println("Compy played me! Mode(" + Mode + ") Amount(" + Amount + ") Target(" + Target + ")" );
|
||||
if(Target.equals("Self")) {
|
||||
Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp"))));
|
||||
}
|
||||
else if(Target.equals("Opponent")) {
|
||||
Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp"))));
|
||||
}
|
||||
else if(Target.equals("All")) {
|
||||
Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp"))));
|
||||
Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp"))));
|
||||
}
|
||||
}
|
||||
card.setSVar("HSStamp","" + Player.getHandSizeStamp());
|
||||
if(Target.equals("Self") || Target.equals("All")) {
|
||||
card.getController().addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp"))));
|
||||
}
|
||||
if(Target.equals("Opponent") || Target.equals("All")) {
|
||||
card.getController().getOpponent().addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp"))));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -12246,31 +12225,12 @@ public class CardFactory implements NewConstants {
|
||||
private static final long serialVersionUID = -6843545358873L;
|
||||
|
||||
public void execute() {
|
||||
if(card.getController() == AllZone.HumanPlayer) {
|
||||
if(Target.equals("Self")) {
|
||||
Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp")));
|
||||
}
|
||||
else if(Target.equals("Opponent")) {
|
||||
Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp")));
|
||||
}
|
||||
else if(Target.equals("All")) {
|
||||
Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp")));
|
||||
Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp")));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Target.equals("Self")) {
|
||||
Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp")));
|
||||
}
|
||||
else if(Target.equals("Opponent")) {
|
||||
Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp")));
|
||||
}
|
||||
else if(Target.equals("All")) {
|
||||
Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp")));
|
||||
Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp")));
|
||||
}
|
||||
}
|
||||
if(Target.equals("Self") || Target.equals("All")) {
|
||||
card.getController().removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp")));
|
||||
}
|
||||
if(Target.equals("Opponent") || Target.equals("All")) {
|
||||
card.getController().getOpponent().removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp")));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -12280,16 +12240,16 @@ public class CardFactory implements NewConstants {
|
||||
public void execute() {
|
||||
Log.debug("HandSize", "Control changed: " + card.getController());
|
||||
if(card.getController().equals(AllZone.HumanPlayer)) {
|
||||
Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp")));
|
||||
Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp"))));
|
||||
AllZone.HumanPlayer.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp")));
|
||||
AllZone.ComputerPlayer.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp"))));
|
||||
|
||||
Computer_Cleanup.sortHandSizeOperations();
|
||||
AllZone.ComputerPlayer.sortHandSizeOperations();
|
||||
}
|
||||
else if(card.getController().equals(AllZone.ComputerPlayer)) {
|
||||
Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp")));
|
||||
Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp"))));
|
||||
AllZone.ComputerPlayer.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp")));
|
||||
AllZone.HumanPlayer.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp"))));
|
||||
|
||||
Input_Cleanup.sortHandSizeOperations();
|
||||
AllZone.HumanPlayer.sortHandSizeOperations();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
package forge;
|
||||
|
||||
public class ComputerAI_counterSpells {
|
||||
|
||||
public static void counter_Spell(SpellAbility sa)
|
||||
{
|
||||
if (sa.getSourceCard().isCreature())
|
||||
counter_CreatureSpell(sa);
|
||||
|
||||
else
|
||||
counter_NonCreatureSpell(sa);
|
||||
}
|
||||
|
||||
public static void counter_CreatureSpell(SpellAbility sa)
|
||||
{
|
||||
if (!hasPlayableCounterSpells() && !hasPlayableCreatureCounterSpells())
|
||||
return;
|
||||
|
||||
CardList counterSpells;
|
||||
if (hasPlayableCreatureCounterSpells())
|
||||
counterSpells = getPlayableCreatureCounterSpells();
|
||||
else
|
||||
counterSpells = getPlayableCounterSpells();
|
||||
|
||||
boolean countered = false;
|
||||
for (Card var:counterSpells)
|
||||
{
|
||||
if (countered)
|
||||
break;
|
||||
else if (CardUtil.getConvertedManaCost(var.getManaCost()) <= CardUtil.getConvertedManaCost(sa) ||
|
||||
(var.getName().equals("Overwhelming Intellect") && CardUtil.getConvertedManaCost(sa) >= 3 ))
|
||||
{
|
||||
SpellAbility sp = var.getSpellAbility()[0];
|
||||
//ComputerUtil.playNoStack(sp);
|
||||
ComputerUtil.playStack(sp);
|
||||
countered = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void counter_NonCreatureSpell(SpellAbility sa)
|
||||
{
|
||||
if (!hasPlayableCounterSpells())
|
||||
return;
|
||||
|
||||
CardList counterSpells;
|
||||
counterSpells = getPlayableCounterSpells();
|
||||
|
||||
boolean countered = false;
|
||||
for (Card var:counterSpells)
|
||||
{
|
||||
if (countered)
|
||||
break;
|
||||
else if (CardUtil.getConvertedManaCost(var.getManaCost()) <= CardUtil.getConvertedManaCost(sa))
|
||||
{
|
||||
SpellAbility sp = var.getSpellAbility()[0];
|
||||
//ComputerUtil.playNoStack(sp);
|
||||
ComputerUtil.playStack(sp);
|
||||
countered = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasPlayableCounterSpells()
|
||||
{
|
||||
return getPlayableCounterSpells().size() > 0;
|
||||
}
|
||||
|
||||
public static boolean hasPlayableCreatureCounterSpells()
|
||||
{
|
||||
return getPlayableCreatureCounterSpells().size() > 0;
|
||||
}
|
||||
|
||||
public static CardList getPlayableCounterSpells()
|
||||
{
|
||||
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, AllZone.ComputerPlayer);
|
||||
CardList list = new CardList(hand.getCards());
|
||||
list = list.filter(new CardListFilter()
|
||||
{
|
||||
|
||||
|
||||
public boolean addCard(Card c) {
|
||||
if (c.getSpellAbility().length == 0)
|
||||
return false;
|
||||
|
||||
SpellAbility sa = c.getSpellAbility()[0];
|
||||
return c.getName().equals("Counterspell") || c.getName().equals("Cancel") ||
|
||||
c.getName().equals("Remand") || c.getName().equals("Mystic Snake") ||
|
||||
c.getName().equals("Absorb") || c.getName().equals("Undermine") ||
|
||||
c.getName().equals("Punish Ignorance") || c.getName().equals("Dismiss") ||
|
||||
c.getName().equals("Last Word") || c.getName().equals("Dissipate")
|
||||
&& ComputerUtil.canPayCost(sa);
|
||||
}
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
public static CardList getPlayableCreatureCounterSpells()
|
||||
{
|
||||
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, AllZone.ComputerPlayer);
|
||||
CardList list = new CardList(hand.getCards());
|
||||
list = list.filter(new CardListFilter()
|
||||
{
|
||||
public boolean addCard(Card c) {
|
||||
if (c.getSpellAbility().length == 0)
|
||||
return false;
|
||||
SpellAbility sa = c.getSpellAbility()[0];
|
||||
return c.getName().equals("Exclude") || c.getName().equals("Overwhelming Intellect") ||
|
||||
c.getName().equals("Preemptive Strike") || c.getName().equals("False Summoning") ||
|
||||
c.getName().equals("Essence Scatter") || c.getName().equals("Remove Soul")
|
||||
&& ComputerUtil.canPayCost(sa);
|
||||
}
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -1,85 +1,10 @@
|
||||
|
||||
package forge;
|
||||
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class Computer_Cleanup extends Input {
|
||||
|
||||
private static LinkedList<HandSizeOp> handSizeOperations = new LinkedList<HandSizeOp>();
|
||||
private static int MaxHandSize = 7;
|
||||
|
||||
public static void clearHandSizeOperations() {
|
||||
handSizeOperations.clear();
|
||||
}
|
||||
|
||||
public static void sortHandSizeOperations() {
|
||||
if(handSizeOperations.size() < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object arr[] = handSizeOperations.toArray();
|
||||
int changes = 1;
|
||||
|
||||
while(changes > 0) {
|
||||
changes = 0;
|
||||
for(int i=1;i<arr.length;i++) {
|
||||
if(((HandSizeOp)arr[i]).hsTimeStamp < ((HandSizeOp)arr[i-1]).hsTimeStamp) {
|
||||
HandSizeOp tmp = (HandSizeOp)arr[i];
|
||||
arr[i] = arr[i-1];
|
||||
arr[i-1] = tmp;
|
||||
changes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
handSizeOperations.clear();
|
||||
for(int i=0;i<arr.length;i++) {
|
||||
handSizeOperations.add((HandSizeOp)arr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void calcMaxHandSize() {
|
||||
|
||||
int ret = 7;
|
||||
for(int i=0;i<handSizeOperations.size();i++)
|
||||
{
|
||||
if(handSizeOperations.get(i).Mode.equals("="))
|
||||
{
|
||||
ret = handSizeOperations.get(i).Amount;
|
||||
}
|
||||
else if(handSizeOperations.get(i).Mode.equals("+") && ret >= 0)
|
||||
{
|
||||
ret = ret + handSizeOperations.get(i).Amount;
|
||||
}
|
||||
else if(handSizeOperations.get(i).Mode.equals("-") && ret >= 0)
|
||||
{
|
||||
ret = ret - handSizeOperations.get(i).Amount;
|
||||
if(ret < 0) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
MaxHandSize = ret;
|
||||
}
|
||||
public static void addHandSizeOperation(HandSizeOp theNew)
|
||||
{
|
||||
handSizeOperations.add(theNew);
|
||||
}
|
||||
public static void removeHandSizeOperation(int timestamp)
|
||||
{
|
||||
for(int i=0;i<handSizeOperations.size();i++)
|
||||
{
|
||||
if(handSizeOperations.get(i).hsTimeStamp == timestamp)
|
||||
{
|
||||
handSizeOperations.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static final long serialVersionUID = -145924458598185438L;
|
||||
|
||||
@Override
|
||||
@@ -87,7 +12,7 @@ public class Computer_Cleanup extends Input {
|
||||
Random r = new Random();
|
||||
Card[] c = AllZone.Computer_Hand.getCards();
|
||||
// while(7 < c.length) {
|
||||
while(MaxHandSize < c.length && MaxHandSize != -1) {
|
||||
while(AllZone.ComputerPlayer.getMaxHandSize() < c.length && AllZone.ComputerPlayer.getMaxHandSize() != -1) {
|
||||
c[r.nextInt(c.length)].getController().discard(c[r.nextInt(c.length)], null);
|
||||
c = AllZone.Computer_Hand.getCards();
|
||||
}
|
||||
|
||||
@@ -2359,8 +2359,8 @@ public class GameAction {
|
||||
AllZone.StaticEffects.reset();
|
||||
StaticEffectKeywordReset = true;
|
||||
|
||||
Computer_Cleanup.clearHandSizeOperations();
|
||||
Input_Cleanup.clearHandSizeOperations();
|
||||
AllZone.HumanPlayer.clearHandSizeOperations();
|
||||
AllZone.ComputerPlayer.clearHandSizeOperations();
|
||||
|
||||
|
||||
{//re-number cards just so their unique numbers are low, just for user friendliness
|
||||
|
||||
@@ -1,92 +1,12 @@
|
||||
|
||||
package forge;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
|
||||
|
||||
public class Input_Cleanup extends Input {
|
||||
private static final long serialVersionUID = -4164275418971547948L;
|
||||
|
||||
private static int NextHandSizeStamp = 0;
|
||||
|
||||
public static int GetHandSizeStamp() {
|
||||
return NextHandSizeStamp++;
|
||||
}
|
||||
|
||||
private static LinkedList<HandSizeOp> handSizeOperations = new LinkedList<HandSizeOp>();
|
||||
private static int MaxHandSize = 7;
|
||||
|
||||
public static void clearHandSizeOperations() {
|
||||
handSizeOperations.clear();
|
||||
NextHandSizeStamp = 0;
|
||||
}
|
||||
|
||||
public static void sortHandSizeOperations() {
|
||||
if(handSizeOperations.size() < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object arr[] = handSizeOperations.toArray();
|
||||
int changes = 1;
|
||||
|
||||
while(changes > 0) {
|
||||
changes = 0;
|
||||
for(int i=1;i<arr.length;i++) {
|
||||
if(((HandSizeOp)arr[i]).hsTimeStamp < ((HandSizeOp)arr[i-1]).hsTimeStamp) {
|
||||
HandSizeOp tmp = (HandSizeOp)arr[i];
|
||||
arr[i] = arr[i-1];
|
||||
arr[i-1] = tmp;
|
||||
changes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
handSizeOperations.clear();
|
||||
for(int i=0;i<arr.length;i++) {
|
||||
handSizeOperations.add((HandSizeOp)arr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void calcMaxHandSize() {
|
||||
|
||||
int ret = 7;
|
||||
for(int i=0;i<handSizeOperations.size();i++)
|
||||
{
|
||||
if(handSizeOperations.get(i).Mode.equals("="))
|
||||
{
|
||||
ret = handSizeOperations.get(i).Amount;
|
||||
}
|
||||
else if(handSizeOperations.get(i).Mode.equals("+") && ret >= 0)
|
||||
{
|
||||
ret = ret + handSizeOperations.get(i).Amount;
|
||||
}
|
||||
else if(handSizeOperations.get(i).Mode.equals("-") && ret >= 0)
|
||||
{
|
||||
ret = ret - handSizeOperations.get(i).Amount;
|
||||
if(ret < 0) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
MaxHandSize = ret;
|
||||
}
|
||||
public static void addHandSizeOperation(HandSizeOp theNew)
|
||||
{
|
||||
handSizeOperations.add(theNew);
|
||||
}
|
||||
public static void removeHandSizeOperation(int timestamp)
|
||||
{
|
||||
for(int i=0;i<handSizeOperations.size();i++)
|
||||
{
|
||||
if(handSizeOperations.get(i).hsTimeStamp == timestamp)
|
||||
{
|
||||
handSizeOperations.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessage() {
|
||||
if (AllZone.Phase.getPlayerTurn().isComputer()){
|
||||
@@ -99,14 +19,14 @@ public class Input_Cleanup extends Input {
|
||||
|
||||
//MUST showMessage() before stop() or it will overwrite the next Input's message
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("Cleanup Phase: You can only have a maximum of ").append(MaxHandSize);
|
||||
sb.append("Cleanup Phase: You can only have a maximum of ").append(AllZone.HumanPlayer.getMaxHandSize());
|
||||
sb.append(" cards, you currently have ").append(n).append(" cards in your hand - select a card to discard");
|
||||
AllZone.Display.showMessage(sb.toString());
|
||||
|
||||
|
||||
//goes to the next phase
|
||||
// if(n <= 7) {
|
||||
if(n <= MaxHandSize || MaxHandSize == -1) {
|
||||
if(n <= AllZone.HumanPlayer.getMaxHandSize() || AllZone.HumanPlayer.getMaxHandSize() == -1) {
|
||||
CombatUtil.removeAllDamage();
|
||||
|
||||
//for debugging: System.out.println("need to nextPhase(Input_Cleanup.showMessage(), n<=7) = true");
|
||||
@@ -133,8 +53,8 @@ public class Input_Cleanup extends Input {
|
||||
public void AI_CleanupDiscard(){
|
||||
int size = AllZone.Computer_Hand.getCards().length;
|
||||
|
||||
if (MaxHandSize != -1){
|
||||
int numDiscards = size - MaxHandSize;
|
||||
if (AllZone.ComputerPlayer.getMaxHandSize() != -1){
|
||||
int numDiscards = size - AllZone.ComputerPlayer.getMaxHandSize();
|
||||
//for(int i = 0; i < numDiscards; i++){
|
||||
AllZone.ComputerPlayer.discard(numDiscards, null);
|
||||
//AllZone.GameAction.AI_discard(null);
|
||||
|
||||
@@ -292,9 +292,6 @@ public class Phase extends MyObservable
|
||||
|
||||
GameActionUtil.executeCardStateEffects();
|
||||
|
||||
Input_Cleanup.calcMaxHandSize();
|
||||
Computer_Cleanup.calcMaxHandSize();
|
||||
|
||||
needToNextPhase = false;
|
||||
|
||||
// If the Stack isn't empty why is nextPhase being called?
|
||||
|
||||
@@ -41,6 +41,8 @@ public abstract class Player extends MyObservable{
|
||||
altLose = false;
|
||||
winCondition = "";
|
||||
loseCondition = "";
|
||||
|
||||
handSizeOperations = new ArrayList<HandSizeOp>();
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
@@ -637,6 +639,76 @@ public abstract class Player extends MyObservable{
|
||||
return list.size() >= 3;
|
||||
}
|
||||
|
||||
private ArrayList<HandSizeOp> handSizeOperations;
|
||||
|
||||
public int getMaxHandSize() {
|
||||
|
||||
int ret = 7;
|
||||
for(int i=0;i<handSizeOperations.size();i++)
|
||||
{
|
||||
if(handSizeOperations.get(i).Mode.equals("="))
|
||||
{
|
||||
ret = handSizeOperations.get(i).Amount;
|
||||
}
|
||||
else if(handSizeOperations.get(i).Mode.equals("+") && ret >= 0)
|
||||
{
|
||||
ret = ret + handSizeOperations.get(i).Amount;
|
||||
}
|
||||
else if(handSizeOperations.get(i).Mode.equals("-") && ret >= 0)
|
||||
{
|
||||
ret = ret - handSizeOperations.get(i).Amount;
|
||||
if(ret < 0) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void sortHandSizeOperations() {
|
||||
if(handSizeOperations.size() < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
int changes = 1;
|
||||
|
||||
while(changes > 0) {
|
||||
changes = 0;
|
||||
for(int i=1;i<handSizeOperations.size();i++) {
|
||||
if(handSizeOperations.get(i).hsTimeStamp < handSizeOperations.get(i-1).hsTimeStamp) {
|
||||
HandSizeOp tmp = handSizeOperations.get(i);
|
||||
handSizeOperations.set(i, handSizeOperations.get(i-1));
|
||||
handSizeOperations.set(i-1, tmp);
|
||||
changes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addHandSizeOperation(HandSizeOp theNew)
|
||||
{
|
||||
handSizeOperations.add(theNew);
|
||||
}
|
||||
public void removeHandSizeOperation(int timestamp)
|
||||
{
|
||||
for(int i=0;i<handSizeOperations.size();i++)
|
||||
{
|
||||
if(handSizeOperations.get(i).hsTimeStamp == timestamp)
|
||||
{
|
||||
handSizeOperations.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void clearHandSizeOperations() {
|
||||
handSizeOperations.clear();
|
||||
}
|
||||
|
||||
private static int NextHandSizeStamp = 0;
|
||||
|
||||
public static int getHandSizeStamp() {
|
||||
return NextHandSizeStamp++;
|
||||
}
|
||||
////////////////////////////////
|
||||
//
|
||||
// generic Object overrides
|
||||
|
||||
Reference in New Issue
Block a user