diff --git a/class/application/Controller$3.class b/class/application/Controller$3.class index 5af37a53a20cac3ee4c586dd3c0da87139da798f..2128f395e0c1285f380c5a39a35da7d4cc20120f 100644 Binary files a/class/application/Controller$3.class and b/class/application/Controller$3.class differ diff --git a/class/application/Controller$4.class b/class/application/Controller$4.class index 83d0a0d6d7d5d44b27d64481536e0e22438f65a6..18e172e014f9f90cf9c77aac8d174c5207080d6d 100644 Binary files a/class/application/Controller$4.class and b/class/application/Controller$4.class differ diff --git a/class/application/Controller$5.class b/class/application/Controller$5.class index 50f44e4cf0791a6e12b8034d9836a60254a4090e..8af2d7a21736cb309334f3db6649df62f7150a7c 100644 Binary files a/class/application/Controller$5.class and b/class/application/Controller$5.class differ diff --git a/class/application/Controller$6.class b/class/application/Controller$6.class index 3bf96ae40a12298d8a832db127f13f189970680a..c6e728912a18f3fbf8453904330e8e10bf5fec52 100644 Binary files a/class/application/Controller$6.class and b/class/application/Controller$6.class differ diff --git a/class/application/Controller$7.class b/class/application/Controller$7.class index 2eaef6fcc54693b6cfbb760248ece358e8144d99..924830cc9a644c72f247fc5b0f8afae39ecf9e96 100644 Binary files a/class/application/Controller$7.class and b/class/application/Controller$7.class differ diff --git a/class/application/Controller$8.class b/class/application/Controller$8.class index f0bab148e9474b147897c65235e50a0deb680447..317db5cfe359ab74d87b9e022e8e2e9ded25904a 100644 Binary files a/class/application/Controller$8.class and b/class/application/Controller$8.class differ diff --git a/class/application/Controller.class b/class/application/Controller.class index 02b838e5e9596bac1ddb95e100477043cbca5fd7..5cfe2b26c0c85dea77f618ede9f90e9d5812753a 100644 Binary files a/class/application/Controller.class and b/class/application/Controller.class differ diff --git a/class/logic/AI.class b/class/logic/AI.class index df353ee3ae663b8b959e6662320e38974158bf54..a3f028bb804f8d16c225286e94be4567d305afbc 100644 Binary files a/class/logic/AI.class and b/class/logic/AI.class differ diff --git a/class/logic/Game.class b/class/logic/Game.class index 96d0da5970d79a85319aa8ca68ad9face9bcbbc4..9e2fd9f9c22dc0f1b41c3b2ef245685d31c800d3 100644 Binary files a/class/logic/Game.class and b/class/logic/Game.class differ diff --git a/src/application/Controller.java b/src/application/Controller.java index 510ebe8507c2a4a974e65b78bf971438157d58fd..c3bb0b7561ea5b00250bf01b84f3d470414741dc 100644 --- a/src/application/Controller.java +++ b/src/application/Controller.java @@ -168,8 +168,10 @@ public class Controller } if(ais.size() == 3) - { - labelAI3Name.setText(ais.get(2).getName()); + { + labelAI1Name.setText(ais.get(1).getName()); + labelAI2Name.setText(ais.get(2).getName()); + labelAI3Name.setText(ais.get(0).getName()); labelAI3Name.setVisible(true); } } @@ -616,6 +618,7 @@ public class Controller } } + @SuppressWarnings("unused") public void moveCardFromDeckToAI(AI ai, ArrayList<Card> cards) { Card card = game.getDeck().drawCard(game.getDeadDeck()); @@ -809,6 +812,7 @@ public class Controller } } + @SuppressWarnings("unused") public void setAIDeck(AI ai) { clearAIDeck(ai); @@ -816,7 +820,7 @@ public class Controller ArrayList<Card> deck = ai.getDeck(); int counter = 1; - + for(Card currentCard : deck) { ImageView current = createBackCard(); diff --git a/src/logic/AI.java b/src/logic/AI.java index 30414e21cadb8fc83c44607b5429086c4ebaf399..793f957b4405dcded8445a6a7650a16fdac619a5 100644 --- a/src/logic/AI.java +++ b/src/logic/AI.java @@ -1,7 +1,6 @@ package logic; import java.util.ArrayList; -import java.util.Random; public class AI { @@ -34,7 +33,7 @@ public class AI { return wins; } - + public int getID() { return id; @@ -53,31 +52,31 @@ public class AI } public Card playCard(Card card) - { - deck.remove(card); + { + deck.remove(card); return card; } public ArrayList<Card> getValidCards(Card lastCard, Color wishColor, boolean challenge) - { - ArrayList<Card> validCards = new ArrayList<Card>(); + { + ArrayList<Card> validCards = new ArrayList<Card>(); if(challenge) { for(Card currentCard : deck) - { + { if(wishColor == null) { if(currentCard.getType().equals(CardType.DRAW_TWO) || currentCard.getType().equals(CardType.DRAW_FOUR)) { validCards.add(currentCard); } - } + } else if(wishColor.equals(Color.ALL)) - { + { if(currentCard.getType().equals(CardType.DRAW_TWO) || currentCard.getType().equals(CardType.DRAW_FOUR)) { validCards.add(currentCard); - } + } } else { @@ -91,23 +90,24 @@ public class AI else { if(wishColor == null) - { + { for(Card currentCard : deck) - { - if(currentCard.getColor().equals(lastCard.getColor()) || currentCard.getType().equals(lastCard.getType()) || currentCard.getType().equals(CardType.WILD) || currentCard.getType().equals(CardType.DRAW_FOUR)) + { + if(currentCard.getColor().equals(lastCard.getColor()) || currentCard.getType().equals(lastCard.getType()) || currentCard.getType().equals(CardType.WILD) + || currentCard.getType().equals(CardType.DRAW_FOUR)) { validCards.add(currentCard); - } + } } } else if(wishColor.equals(Color.ALL)) { for(Card currentCard : deck) - { - if(!currentCard.getType().equals(CardType.WILD) && !currentCard.getType().equals(CardType.DRAW_FOUR)) + { + if( ! currentCard.getType().equals(CardType.WILD) && ! currentCard.getType().equals(CardType.DRAW_FOUR)) { validCards.add(currentCard); - } + } } } else @@ -117,11 +117,11 @@ public class AI if(currentCard.getColor().equals(wishColor)) { validCards.add(currentCard); - } + } } - } - } - + } + } + return validCards; } @@ -134,7 +134,7 @@ public class AI { return name; } - + public ArrayList<Card> getDeck() { return deck; @@ -150,50 +150,36 @@ public class AI if(challenge) { System.out.println("draw " + game.getChallengeCounter() + " cards"); - ArrayList<Card> drawedCards = game.getDeck().drawCards(game.getChallengeCounter(), game.getDeadDeck()); + ArrayList<Card> drawedCards = game.getDeck().drawCards(game.getChallengeCounter(), game.getDeadDeck()); game.getController().moveCardFromDeckToAI(this, drawedCards); - System.out.println("deack after draw: " + deck); + System.out.println("deack after draw: " + deck); } else { System.out.println("draw one card"); ArrayList<Card> drawedCards = new ArrayList<Card>(); drawedCards.add(game.getDeck().drawCard(game.getDeadDeck())); - game.getController().moveCardFromDeckToAI(this, drawedCards); - System.out.println("deack after draw: " + deck); - } - } + game.getController().moveCardFromDeckToAI(this, drawedCards); + System.out.println("deack after draw: " + deck); + } + } else { System.out.println("choose"); System.out.println("AI chooses: " + getHighestValuedCard(validDeck)); - - + Card playedCard = getHighestValuedCard(validDeck); Color newWishColor = null; - + if(playedCard.getType().equals(CardType.WILD) || playedCard.getType().equals(CardType.DRAW_FOUR)) { - //TODO choose color that is mostly in deck (except black) - Random random = new Random(); - int colorInt = random.nextInt(4) + 1; - switch(colorInt) - { - case 1: newWishColor = Color.YELLOW; - break; - case 2: newWishColor = Color.RED; - break; - case 3: newWishColor = Color.BLUE; - break; - case 4: newWishColor = Color.GREEN; - break; - } + newWishColor = getBestColor(); } - - game.getController().moveAICardToDeadDeck(this, game.getCurrentPlayer(), playedCard, newWishColor); - } + + game.getController().moveAICardToDeadDeck(this, game.getCurrentPlayer(), playedCard, newWishColor); + } } - + private Card getHighestValuedCard(ArrayList<Card> validDeck) { Card highestValuedCard = validDeck.get(0); @@ -204,7 +190,52 @@ public class AI highestValuedCard = currentCard; } } - + return highestValuedCard; } + + private Color getBestColor() + { + int[] times = new int[4]; + + for(Card currentCard : deck) + { + switch(currentCard.getColor()) + { + case YELLOW: + times[0]++; + break; + case RED: + times[0]++; + break; + case BLUE: + times[0]++; + break; + case GREEN: + times[0]++; + break; + default: + break; + } + } + + int maxIndex = 0; + for(int i = 1; i < times.length; i++) + { + int newnumber = times[i]; + if((newnumber > times[maxIndex])) + { + maxIndex = i; + } + } + + switch(maxIndex) + { + case 0: return Color.YELLOW; + case 1: return Color.RED; + case 2: return Color.BLUE; + case 3: return Color.GREEN; + default: return null; + } + } } \ No newline at end of file diff --git a/src/logic/Game.java b/src/logic/Game.java index dca0ec965f836f846405a60765178335736649d1..4fddf15b144642d12d7f44361edaeed2635a9c6d 100644 --- a/src/logic/Game.java +++ b/src/logic/Game.java @@ -47,9 +47,9 @@ public class Game } else if(numberOfAIs == 3) { - ais.add(new AI("Computer 3", 3, this)); - ais.add(new AI("Computer 1", 1, this)); - ais.add(new AI("Computer 2", 2, this)); + ais.add(new AI("Computer 1", 3, this)); + ais.add(new AI("Computer 2", 1, this)); + ais.add(new AI("Computer 3", 2, this)); } gameCount = 0;