# Falsche Methode



## Kitero (16. Dez 2013)

Hey Leute!

Ich bin noch ein ziemlicher Javaneuling und habe in meiner Uni die Aufgabe bekommen, ein Würfelpokerspiel zu erstellen.
Das Programm liefert bei mir zwar das richtige Ergebnis, aber ich habe das Problem, dass unser Prüfprogramm nur eine bestimmte Version davon als richtig anerkennt.
Leider steh ich zurzeit ziemlich am Schlauch und habe keine Ahnung wie ich dieses Problem beheben kann.

Ich muss statt: 

```
public static int bewerteWurf(int[] wurf, int Round, int Player) {
```

den Code auf 


```
public static String bewerteWurf (int[] wurf, int Round, int Player) {
```
umändern... also statt dem int - String verwenden. 

Ich hoffe jemand kann mir dabei behilflich sein...
brauche das Programm schon morgen ;(
Wäre euch sehr dankbar 

Hier mein ganzer Code:


```
import java.util.*;


public class Aufgabe10 {

    public static int NrPlayers = 9;
    public static int NrRounds = 2;

    public static void main (String[] args) {

    int Game[][][];
    Random r = new java.util.Random();

    Game = new int[NrPlayers][NrRounds+1][5];

    for (int Round=1; Round <= NrRounds; Round++) {

        for (int Player = 0; Player < NrPlayers; Player++) {
        Game = rollDice(Game, Round, Player, r);
        Game[Player][0][0] = processResults(Game[Player][Round], Round, Player);
        } 

        processWinner(Game);
    }

    } 

    public static int[][][] rollDice(int[][][] Game, int Round, int Player, Random r) {

    for (int i = 0; i < Game.length; i++) {
        for (int j = 0; j < 5; j++) {
        Game[i][Round][j] = r.nextInt(6)+1;
        } 
    } 
    return(Game);
    }

    public static int processResults(int[] Dimes, int Round, int Player) {
    int Win = 0;
    int[] EyesCount = {0, 0, 0, 0, 0, 0}; 

    System.out.print("Results for player " + (Player+1) + " in round " + (Round) + ":");
    for (int i = 0; i < Dimes.length; i++) {
        System.out.print(" " + Dimes[i]);
        switch (Dimes[i]) {
        case 1: EyesCount[0] = EyesCount[0] + 1 ;break;
        case 2: EyesCount[1] = EyesCount[1] + 1; break;
        case 3: EyesCount[2] = EyesCount[2] + 1; break;
        case 4: EyesCount[3] = EyesCount[3] + 1; break;
        case 5: EyesCount[4] = EyesCount[4] + 1; break;
        case 6: EyesCount[5] = EyesCount[5] + 1; break;
        default:  break;
        } 
    } 

    
    if ( (EyesCount[1]==1) && (EyesCount[2]==1) && (EyesCount[3]==1) && (EyesCount[4]==1) )
        if ((EyesCount[0]==1) || (EyesCount[5]==1)) {
        Win = 1;
        System.out.print(" (Sequence)! ");
        } 
        else  ;
    else {
        for (int j = 0; j < 5 ; j++) {
        switch (EyesCount[j]) {
        case 5: Win = 4; System.out.print(" (Grand)! "); break;
        case 4: Win = 3; System.out.print(" (Poker)! "); break;
        case 3: {
            for (int h = 0; h < 5; h++) {
            if (EyesCount[h]==2) {
                Win = 2;
                System.out.print(" (Full House)! ");
            } 
            } 
            break;
        }
        }
        } 
    } 
    System.out.println("");
    return(Win);
    } 


    public static void processWinner(int[][][] Game) {
    int Winner = 0;
    int Points = 0;

    for (int i = 0; i < Game.length; i++) {

        if (Game[i][0][0] >= Points) {
        if (Game[i][0][0] > Points) {
            Winner = i+1;
            Points = Game[i][0][0];
            }
        else
            Winner = 0;
        }
    } 

    if(Winner > 0) System.out.println("Der Gewinner ist Spieler " + Winner);
    else  System.out.println("Niemand hat gewonnen!");
    System.out.println("******************************************");

    } 

}
```


----------



## Kitero (16. Dez 2013)

oh hab ausversehen den alten Code eingefügt...
der neue lautet natürlich:


```
import java.util.*;
 
 
public class Aufgabe10 {
 
    public static int NrPlayers = 9;
    public static int NrRounds = 2;
 
    public static void main (String[] args) {
 
    int Game[][][];
    Random r = new java.util.Random();
 
    Game = new int[NrPlayers][NrRounds+1][5];
 
    for (int Round=1; Round <= NrRounds; Round++) {
 
        for (int Player = 0; Player < NrPlayers; Player++) {
        Game = rollDice(Game, Round, Player, r);
        Game[Player][0][0] = bewerteWurf(Game[Player][Round], Round, Player);
        } 
 
        processWinner(Game);
    }
 
    } 
 
    public static int[][][] rollDice(int[][][] Game, int Round, int Player, Random r) {
 
    for (int i = 0; i < Game.length; i++) {
        for (int j = 0; j < 5; j++) {
        Game[i][Round][j] = r.nextInt(6)+1;
        } 
    } 
    return(Game);
    }
 
    public static int bewerteWurf(int[] wurf, int Round, int Player) {
    int Win = 0;
    int[] EyesCount = {0, 0, 0, 0, 0, 0}; 
 
    System.out.print("Results for player " + (Player+1) + " in round " + (Round) + ":");
    for (int i = 0; i < Dimes.length; i++) {
        System.out.print(" " + Dimes[i]);
        switch (Dimes[i]) {
        case 1: EyesCount[0] = EyesCount[0] + 1 ;break;
        case 2: EyesCount[1] = EyesCount[1] + 1; break;
        case 3: EyesCount[2] = EyesCount[2] + 1; break;
        case 4: EyesCount[3] = EyesCount[3] + 1; break;
        case 5: EyesCount[4] = EyesCount[4] + 1; break;
        case 6: EyesCount[5] = EyesCount[5] + 1; break;
        default:  break;
        } 
    } 
 
    
    if ( (EyesCount[1]==1) && (EyesCount[2]==1) && (EyesCount[3]==1) && (EyesCount[4]==1) )
        if ((EyesCount[0]==1) || (EyesCount[5]==1)) {
        Win = 1;
        System.out.print(" (Sequence)! ");
        } 
        else  ;
    else {
        for (int j = 0; j < 5 ; j++) {
        switch (EyesCount[j]) {
        case 5: Win = 4; System.out.print(" (Grand)! "); break;
        case 4: Win = 3; System.out.print(" (Poker)! "); break;
        case 3: {
            for (int h = 0; h < 5; h++) {
            if (EyesCount[h]==2) {
                Win = 2;
                System.out.print(" (Full House)! ");
            } 
            } 
            break;
        }
        }
        } 
    } 
    System.out.println("");
    return(Win);
    } 
 
 
    public static void processWinner(int[][][] Game) {
    int Winner = 0;
    int Points = 0;
 
    for (int i = 0; i < Game.length; i++) {
 
        if (Game[i][0][0] >= Points) {
        if (Game[i][0][0] > Points) {
            Winner = i+1;
            Points = Game[i][0][0];
            }
        else
            Winner = 0;
        }
    } 
 
    if(Winner > 0) System.out.println("Der Gewinner ist Spieler " + Winner);
    else  System.out.println("Niemand hat gewonnen!");
    System.out.println("******************************************");
 
    } 
 
}
```


----------

