Skip to content

First commit lab-02 Anton Drazdoŭski#37

Open
aadeglmmy wants to merge 2 commits into
Rrenkens:mainfrom
aadeglmmy:lab02
Open

First commit lab-02 Anton Drazdoŭski#37
aadeglmmy wants to merge 2 commits into
Rrenkens:mainfrom
aadeglmmy:lab02

Conversation

@aadeglmmy

Copy link
Copy Markdown

No description provided.

Comment on lines +20 to +31
int generatingTime = configReader.getGeneratingTime();
int shipCapacityMin = configReader.getShipCapacityMin();
int shipCapacityMax = configReader.getShipCapacityMax();
String[] cargoTypes = configReader.getCargoTypes();
int maxShips = configReader.getMaxShips();
int dockQuantity = configReader.getDocks();
int unloadingSpeed = configReader.getUnloadingSpeed();
int[] dockCapacity = configReader.getDockCapacity();
int hoboQuantity = configReader.getHobos();
int[] ingredientsCount = configReader.getIngredientsCount();
int stealingTime = configReader.getStealingTime();
int eatingTime = configReader.getEatingTime();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кмк ConfigReader уже заточен под структуру, поэтому мог уже возвращать и Tunnel, Docks и т. д.

}

private Ship generateShip() {
Random random = new Random();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше не создавать на каждый вызов метода generateShip новый инстанс.

while (ship.getCapacity() > 0) {
dockLock.lock();
try {
while (dockFullness[cargoTypeIndex] >= capacity) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Может быть такое, что нагенериили x одинаковых короблей, и тогда с этой точки не сдвинутся будет.

}
}
try {
Thread.sleep(unloadingSpeed * 1000L);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unloadingSpeed – это сколько за секунду товаров разгружает док.

}
}
try {
Thread.sleep(unloadingSpeed * 1000L);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Спать с взятым мьютексом не очень хорошая идея.

Comment on lines +52 to +86
do {
while (true) {
synchronized (hobos) {
while (hobos.getStolenIngredients()[cargoTypeCounter]
== hobos.getIngredientsCount()[cargoTypeCounter]) {
cargoTypeCounter = (cargoTypeCounter + 1) % numOfCargoTypes;
if (cargoTypeCounter == cargoTypeIndex) {
breaker = true;
break;
}
}
if (breaker) {
breaker = false;
break;
}
synchronized (docks[dockCounter]) {
if (!(docks[dockCounter].getDockFullness()[cargoTypeCounter] != 0
&& hobos.getStolenIngredients()[cargoTypeCounter]
< hobos.getIngredientsCount()[cargoTypeCounter])) {
break;
}
docks[dockCounter].decrementDockFullness(cargoTypeCounter);
hobos.incrementStolenIngredients(cargoTypeCounter);
}
}
try {
Thread.sleep(stealingTime * 1000L);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// System.out.println("Hobo " + this + " stole from dock " + docks[dockCounter] + " cargo "
// + cargoTypeCounter);
}
dockCounter = (dockCounter + 1) % docks.length;
} while (dockCounter != dockIndex);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не очень понял смысл этого цикла.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants