001    /**
002     * 
003     */
004    package jagafa.rule;
005    
006    import jagafa.object.Board;
007    import jagafa.object.Card;
008    import jagafa.object.Hand;
009    import jagafa.stats.CardTool;
010    
011    /**
012     * @author Besitzer
013     * 
014     */
015    public class SlalomObenStartRules implements RuleSet {
016            private enum UntenHierarchy {
017                    C6, C7, C8, C9, C10, CJ, CQ, CK, CAs;
018            }
019    
020            private enum ObenHierarchy {
021                    CAs, CK, CQ, CJ, C10, C9, C8, C7, C6;
022            }
023    
024            private static final int UNTEN = 0;
025    
026            private static final int OBEN = 1;
027    
028            private int direction_;
029    
030            private int startDirection_;
031    
032            private ObenRules oben_;
033            private UntenRules unten_;
034            
035            public Card getHigherCard(Card c1, Card c2) {
036                    if (this.direction_==OBEN) {
037                            return this.oben_.getHigherCard(c1,c2);
038                    } else {
039                            return this.unten_.getHigherCard(c1,c2);
040                    }
041            }
042    
043            public SlalomObenStartRules() {
044                    this.startDirection_ = OBEN;
045                    this.direction_ = OBEN;
046                    this.oben_ = new ObenRules();
047                    this.unten_ = new UntenRules();
048            }
049    
050            public int getPower(Card c, Board b) {
051                    
052                    int power = 0;
053    
054                    power = this.getValueRank(c, b);
055    
056                    power += 100 * this.getColorRank(c, b);
057    
058                    return power;
059            }
060    
061            public int getScore(Card c) {
062                    if (this.startDirection_==OBEN) {
063                            return this.oben_.getScore(c);
064                    } else {
065                            return this.unten_.getScore(c);
066                    }
067            }
068    
069            public boolean isValid(Card cardToCheck, Hand hand, Board board) {
070                    if (cardToCheck == null) {
071                            return false;
072                    }
073                    if (board.cardsPlayed() > 0) {
074                            Card firstCard = board.get(0);
075                            int firstColor = firstCard.getColor();
076    
077                            // Wenn keine Karten von der startFarbe auf der hand, dann egal
078                            // welche Karte gespielt wird
079                            if (CardTool.getAllOfColor(hand, firstColor).size() == 0) {
080                                    return true;
081                            } else {
082                                    // Wenn noch Karten von der startFarbe, dann muss Karte von der
083                                    // gleichen Farbe sein
084                                    if (cardToCheck.getColor() == (firstColor)) {
085                                            return true;
086                                    } else {
087                                            return false;
088                                    }
089                            }
090    
091                    }
092    
093                    return true;
094            }
095    
096            public int getValueRank(Card c, Board b) {
097                    if (this.direction_==OBEN) {
098                            return this.oben_.getValueRank(c,b);
099                    } else {
100                            return this.unten_.getValueRank(c,b);
101                    }
102            }
103    
104            public int getColorRank(Card c, Board b) {
105                    if (this.direction_==OBEN) {
106                            return this.oben_.getColorRank(c,b);
107                    } else {
108                            return this.unten_.getColorRank(c,b);
109                    }
110            }
111    
112            public boolean compareHigher(Card c1, Board b) {
113                    if (this.direction_==OBEN) {
114                            return this.oben_.compareHigher(c1,b);
115                    } else {
116                            return this.unten_.compareHigher(c1,b);
117                    }
118                    
119    
120            }
121    
122            /*
123             * (non-Javadoc)
124             * 
125             * @see jass.rule.Rules#getName()
126             */
127            public String getName() {
128                    if (this.direction_==OBEN) {
129                            return "Slalom (Oben)"; 
130                    } else {
131                            return "Slalom (Unten)";
132                    }
133                    
134            }
135    
136            /* (non-Javadoc)
137             * @see jass.rule.Rules#specialColor()
138             */
139            public int specialColor() {
140                    // TODO Auto-generated method stub
141                    return -1;
142            }
143    
144            public int hashCode() {
145                    int sum = 0;
146                    char carray[] = this.getName().toCharArray();
147                    for (int i = 0; i < carray.length; i++) {
148                            sum += (int) carray[i];
149                    }
150    
151                    return sum;
152            }
153            
154            
155            public void updateAfterTurn() {
156                    if (this.direction_==OBEN) {
157                            this.direction_ = UNTEN;
158                    } else {
159                            this.direction_ = OBEN;
160                    }
161            }
162    }