Skip to content

Commit ec81d10

Browse files
committed
more explicit checks
1 parent 142f897 commit ec81d10

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/simulation/BindingSimulator2D.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,14 @@ export default class BindingSimulator implements IClientSimulatorImpl {
107107
private getProductColor(id: number, partnerId: number) {
108108
// one and only one of the agents should have a product color
109109
// so the order here is not important
110-
return (
111-
this.productColor.get(partnerId) || this.productColor.get(id) || ""
112-
);
110+
const color1 = this.productColor.get(id);
111+
const color2 = this.productColor.get(partnerId);
112+
if (color1 && color2) {
113+
throw new Error(
114+
`Both agents (${id} and ${partnerId}) have a product color defined. Only one should have a product color.`
115+
);
116+
}
117+
return color2 || color1 || "";
113118
}
114119

115120
private getRandomPoint() {

0 commit comments

Comments
 (0)