HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaMinor

Poker Bank application

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
bankpokerapplication

Problem

For playing a Poker tournament, I wanted to create an application which should calculate the pot and the money of all players at every time.

PokerBank class:

```
public class PokerBank {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

System.out.println("---------------Spiel Beginnen----------------");

try {
request();
} catch (IOException e) {
System.err.println("Fehler bei der Eingabe");
}
String[] playernames = new String[numberOfPlayers];
try {
playernames = requestNames();
} catch (IOException e) {
System.err.println("Fehler bei der Names Eingabe");
}

Player[] players = new Player[playernames.length];
players = requestPlayers(playernames);

// Initialisation of the Players
double bigBlind = initialBigblind;

// first call of the play with the Pot of zero and the dealer Offset Zero
boolean round = true;
// The firts round is set as true becouse it now it is the first round
playRound(bigBlind, players, round, 0,0);

}
public static int numberOfPlayers;
public static double initialBigblind;
public static double initialCapital;

/**
* Method to request the main Settings
* @throws IOException
*/
public static void request() throws IOException {
System.out.println("Wie viele Spieler machen mit?");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
numberOfPlayers = Integer.parseInt(reader.readLine());
System.out.println("Wie hoch ist der Anfangsbetrag jedes Spielers?");
initialCapital = Double.parseDouble(reader.readLine());
System.out.println("Wie hoch ist der Big Blind?");
initialBigblind = Double.parseDouble(reader.readLine());

}

/**
*
* Method to play the round
* @param BigBlind the Big blind of the game
* @param players The Players in form of an Array
* @param NewRound boolean if it is a new round
* @param Pot Potsize
* @param DealerOffSet to store

Solution

Language

The I/O of your programm is german. That's okay, but not so good if you post this in an mainly English Q&A forum. I'm german too ;)

Main method

Player[] players = new Player[playernames.length];
players=requestPlayers(playernames);
double bigBlind = initialBigBlind;
boolean round = true;
playRound(bigBlind,requestPlayers(playernames),round,0,0);


Why don't shorten to:

playRound(initialBigBlind,new Player[playernames.length],0,0);


request function

Use java.util.Scanner. Also what is if I just input

Wie viele Spieler machen mit?
> foo


Probably not what you want. And you need that code repeatedly. So make an extra function:

static Scanner s = new Scanner(System.in);
public int readInt(String message){
  while(!s.hasNextInt()){
    System.out.println(message);
  }
  return s.nextInt();
}
public double readDouble(String message){
  while(!s.hasNextDouble()){
    System.out.println(message);
  }
  return s.nextDouble();
}


Now the foo as input doesn't works any more to crash your programm.

Wie viele Spieler machen mit?
> foo
Wie viele Spieler machen mit?
> 5
...


playRound function

Messy. Just messy and totally overloaded. And recursive. Clean up a little bit and think about a loop. And renaming the whole thing. Sorry, but I can't give you any specific advise, I don't know Poker good enough to see any logic. That may isn't connected too your code-style. :(

OOP

Java is for object-oriented-programming. If you want to use only functions then go and use Python. No offense to Python but it's definitely not normal Java to put everything (except the Player) into static context. Maybe At least create an class.

public class PokerGame{
  //...
}


Player class

public void setIN(){//...
public void setOUT(){//...


Why don't just use one method

public boolean setIn(boolean in){
  boolean old = this.in;
  this.in = in;
  return old;
}


Ausgabe?!?!?!

public void Ausgabe(){/...


Not pretty English. Also there is a toString() method.

@Override
public void toString(){
  return name+"\n"+money+"\n"+"-------------------"); 
}


And then use System.out.println(player); instead player.Ausgabe();

Sorry If I sound rude sometimes. I don't mean so I'm just not so good in English and this sounds fairly aggressive to me. I don't want to be rude.

Code Snippets

Player[] players = new Player[playernames.length];
players=requestPlayers(playernames);
double bigBlind = initialBigBlind;
boolean round = true;
playRound(bigBlind,requestPlayers(playernames),round,0,0);
playRound(initialBigBlind,new Player[playernames.length],0,0);
Wie viele Spieler machen mit?
> foo
static Scanner s = new Scanner(System.in);
public int readInt(String message){
  while(!s.hasNextInt()){
    System.out.println(message);
  }
  return s.nextInt();
}
public double readDouble(String message){
  while(!s.hasNextDouble()){
    System.out.println(message);
  }
  return s.nextDouble();
}
Wie viele Spieler machen mit?
> foo
Wie viele Spieler machen mit?
> 5
...

Context

StackExchange Code Review Q#144657, answer score: 3

Revisions (0)

No revisions yet.