I am soliciting help for a deceptively difficult design problem.
It is for a poker hand reading program. I am struggling with the various interdependencies.
You start with a session, described in a hand history file.
A poker session is played on a Table which is associated with a particular game and blind structure, etc. A table has a maximum number of seats occupied by players.
The hand history file describes a number of hands played at the table by the players.
Each hand, uniquely identified by a hand ID, contains a number of lines which can be parsed for information. Typically it is whether a player checks, folds, bets, raises and the amount, if applicable. I call these actions. A player can also show down a hand, showing his hole cards.
I currently keep track of Sessions, which contain a list of Hands – that seems logical to me. But if I want to find all of the hole cards played by a player, I have to iterate all hands within all sessions, looking for the player and retrieve their hole cards that they showed. Having each player keep track of hands they played, results in a whole lot of duplication, since multiple players played in the same hands.
At the highest level, I have
private ArrayList<Session> _sessions;
private Session _currentSession;
My Session class contains :
private String _fileName; // hand history file
private ArrayList<Player> _players;
private String _tableName;
private HashMap<Long, Hand> _hands; // key is hand Id
My Hand class contains :
private long _id;
private ArrayList<String> _lines;
private HashMap<String, HoleCards> _holeCards; // key is player name
private HashMap<Integer, Seat> _seats; // key is seat number
My Seat class contains :
private Player _player;
String _position; // SB, BB, EP, MP, CO, Button
String _won;
My Player class contains :
private String _name;
private ArrayList<Action> _actions;
My Action class contains :
String _action; // folds, calls, checks, bets, raises
BigDecimal _amount;
long _handId;
Hand_Stage _stage;
Also keeping track of actions is another difficulty. If I keep a list of actions per player, they are divided between players. Currently if I want to access the actions, I have to find which session, the hand Id is in, then I need to retrieve the player from the player list in that session and iterate through the list of actions, filtered on the hand Id.
I know from experience when things are difficult, my design is off, but I can’t pinpoint the problem in this case.