// TODO the planning entity list from the solution should be used and might already contain initialized entities
List<SeatDesignation> seatDesignationList = createSeatDesignationList(dinnerParty);
// Assign one guest at a time
List<Seat> undesignatedSeatList = new ArrayList<Seat>(dinnerParty.getSeatList());
for (SeatDesignation seatDesignation : seatDesignationList) {
Score bestScore = SimpleScore.valueOf(Integer.MIN_VALUE);
Seat bestSeat = null;
boolean added = false;
// Try every seat for that guest
// TODO by reordening the seats so index 0 has a different table then index 1 and so on,
// this will probably be faster because perfectMatch will be true sooner
for (Seat seat : undesignatedSeatList) {
if (seatDesignation.getGuest().getGender() == seat.getRequiredGender()) {
if (!added) {
scoreDirector.beforeEntityAdded(seatDesignation);
seatDesignation.setSeat(seat);
scoreDirector.afterEntityAdded(seatDesignation);
added = true;
} else {
scoreDirector.beforeVariableChanged(seatDesignation, "seat");
seatDesignation.setSeat(seat);
scoreDirector.afterVariableChanged(seatDesignation, "seat");
}
Score score = scoreDirector.calculateScore();
if (score.compareTo(bestScore) > 0) {
bestScore = score;
bestSeat = seat;
}
}
}