Compare commits

...

3 Commits

Author SHA1 Message Date
011084b8ec Add delay assimilate behavior 2022-04-12 18:41:15 +08:00
6c483317aa Add contact assimilate behavior 2022-04-12 17:44:51 +08:00
1b8f594ea2 Rename contact attacking 2022-04-12 17:05:45 +08:00
5 changed files with 199 additions and 11 deletions

View File

@ -4,7 +4,9 @@ import { PhysicsDynamics } from "@Behavior/PhysicsDynamics";
import { Brownian } from "@Behavior/Brownian"; import { Brownian } from "@Behavior/Brownian";
import { BoundaryConstraint } from "@Behavior/BoundaryConstraint"; import { BoundaryConstraint } from "@Behavior/BoundaryConstraint";
import { Tracking } from "@Behavior/Tracking"; import { Tracking } from "@Behavior/Tracking";
import { Attacking } from "@Behavior/Attacking"; import { ContactAttacking } from "@Behavior/ContactAttacking";
import { ContactAssimilate } from "@Behavior/ContactAssimilate";
import { DelayAssimilate } from "@Behavior/DelayAssimilate";
const AllBehaviors: IAnyBehaviorRecorder[] = [ const AllBehaviors: IAnyBehaviorRecorder[] = [
new BehaviorRecorder(Template), new BehaviorRecorder(Template),
@ -12,7 +14,9 @@ const AllBehaviors: IAnyBehaviorRecorder[] = [
new BehaviorRecorder(Brownian), new BehaviorRecorder(Brownian),
new BehaviorRecorder(BoundaryConstraint), new BehaviorRecorder(BoundaryConstraint),
new BehaviorRecorder(Tracking), new BehaviorRecorder(Tracking),
new BehaviorRecorder(Attacking), new BehaviorRecorder(ContactAttacking),
new BehaviorRecorder(ContactAssimilate),
new BehaviorRecorder(DelayAssimilate),
] ]
/** /**

View File

@ -0,0 +1,88 @@
import { Behavior } from "@Model/Behavior";
import { Group } from "@Model/Group";
import { Individual } from "@Model/Individual";
import { Model } from "@Model/Model";
type IContactAssimilateBehaviorParameter = {
target: "CLG",
assimilate: "CG",
success: "number",
range: "number"
}
type IContactAssimilateBehaviorEvent = {}
class ContactAssimilate extends Behavior<IContactAssimilateBehaviorParameter, IContactAssimilateBehaviorEvent> {
public override behaviorId: string = "ContactAssimilate";
public override behaviorName: string = "$Title";
public override iconName: string = "SyncStatus";
public override describe: string = "$Intro";
public override category: string = "$Interactive";
public override parameterOption = {
target: { type: "CLG", name: "$Target" },
assimilate: { type: "CG", name: "$Assimilate" },
range: { type: "number", name: "$Range", defaultValue: .05, numberMin: 0, numberStep: .01 },
success: { type: "number", name: "$Success", defaultValue: 90, numberMin: 0, numberMax: 100, numberStep: 5 }
};
public effect = (individual: Individual, group: Group, model: Model, t: number): void => {
let assimilateGroup = this.parameter.assimilate.objects;
if (!assimilateGroup) return;
for (let i = 0; i < this.parameter.target.objects.length; i++) {
const targetGroup = this.parameter.target.objects[i];
targetGroup.individuals.forEach((targetIndividual) => {
// 排除自己
if (targetIndividual === individual) return;
let dis = targetIndividual.distanceTo(individual);
// 进入同化范围
if (dis <= this.parameter.range) {
// 成功判定
if (Math.random() * 100 < this.parameter.success) {
targetIndividual.transfer(assimilateGroup!);
}
}
});
}
}
public override terms: Record<string, Record<string, string>> = {
"$Title": {
"ZH_CN": "接触同化",
"EN_US": "Contact Assimilate"
},
"$Target": {
"ZH_CN": "从哪个群...",
"EN_US": "From group..."
},
"$Assimilate": {
"ZH_CN": "到哪个群...",
"EN_US": "To group..."
},
"$Range": {
"ZH_CN": "同化范围 (m)",
"EN_US": "Assimilate range (m)"
},
"$Success": {
"ZH_CN": "成功率 (%)",
"EN_US": "Success rate (%)"
},
"$Intro": {
"ZH_CN": "将进入同化范围内的个体同化至另一个群",
"EN_US": "Assimilate individuals who enter the assimilation range to another group"
}
};
}
export { ContactAssimilate };

View File

@ -3,17 +3,17 @@ import { Group } from "@Model/Group";
import { Individual } from "@Model/Individual"; import { Individual } from "@Model/Individual";
import { Model } from "@Model/Model"; import { Model } from "@Model/Model";
type IAttackingBehaviorParameter = { type IContactAttackingBehaviorParameter = {
target: "CLG", target: "CLG",
success: "number", success: "number",
range: "number" range: "number"
} }
type IAttackingBehaviorEvent = {} type IContactAttackingBehaviorEvent = {}
class Attacking extends Behavior<IAttackingBehaviorParameter, IAttackingBehaviorEvent> { class ContactAttacking extends Behavior<IContactAttackingBehaviorParameter, IContactAttackingBehaviorEvent> {
public override behaviorId: string = "Attacking"; public override behaviorId: string = "ContactAttacking";
public override behaviorName: string = "$Title"; public override behaviorName: string = "$Title";
@ -54,8 +54,8 @@ class Attacking extends Behavior<IAttackingBehaviorParameter, IAttackingBehavior
public override terms: Record<string, Record<string, string>> = { public override terms: Record<string, Record<string, string>> = {
"$Title": { "$Title": {
"ZH_CN": "攻击", "ZH_CN": "接触攻击",
"EN_US": "Attacking" "EN_US": "Contact Attacking"
}, },
"$Target": { "$Target": {
"ZH_CN": "攻击目标", "ZH_CN": "攻击目标",
@ -76,4 +76,4 @@ class Attacking extends Behavior<IAttackingBehaviorParameter, IAttackingBehavior
}; };
} }
export { Attacking }; export { ContactAttacking };

View File

@ -0,0 +1,96 @@
import { Behavior } from "@Model/Behavior";
import { Group } from "@Model/Group";
import { Individual } from "@Model/Individual";
import { Model } from "@Model/Model";
type IDelayAssimilateBehaviorParameter = {
target: "CG",
maxDelay: "number",
minDelay: "number",
success: "number"
}
type IDelayAssimilateBehaviorEvent = {}
class DelayAssimilate extends Behavior<IDelayAssimilateBehaviorParameter, IDelayAssimilateBehaviorEvent> {
public override behaviorId: string = "DelayAssimilate";
public override behaviorName: string = "$Title";
public override iconName: string = "FunctionalManagerDashboard";
public override describe: string = "$Intro";
public override category: string = "$Initiative";
public override parameterOption = {
target: { type: "CG", name: "$Target" },
maxDelay: { type: "number", name: "$Max.Delay", defaultValue: 20, numberStep: 1, numberMin: 0 },
minDelay: { type: "number", name: "$Min.Delay", defaultValue: 5, numberStep: 1, numberMin: 0 },
success: { type: "number", name: "$Success", defaultValue: 90, numberStep: 5, numberMin: 0 }
};
public effect = (individual: Individual, group: Group, model: Model, t: number): void => {
let assimilateGroup = this.parameter.target.objects;
if (!assimilateGroup) return;
const {maxDelay, minDelay, success} = this.parameter;
let nextTime = individual.getData("DelayAssimilate.nextTime") ??
minDelay + Math.random() * (maxDelay - minDelay);
let currentTime = individual.getData("DelayAssimilate.currentTime") ?? 0;
currentTime += t;
if (currentTime > nextTime) {
// 成功判定
if (Math.random() * 100 < success) {
individual.transfer(assimilateGroup);
nextTime = undefined;
currentTime = undefined;
} else {
nextTime = minDelay + Math.random() * (maxDelay - minDelay);
currentTime = 0;
}
}
individual.setData("DelayAssimilate.nextTime", nextTime);
individual.setData("DelayAssimilate.currentTime", currentTime);
}
public override terms: Record<string, Record<string, string>> = {
"$Title": {
"ZH_CN": "延迟同化",
"EN_US": "Delayed assimilation"
},
"$Intro": {
"ZH_CN": "随着时间的推移,个体逐渐向另一个群同化。",
"EN_US": "Over time, individuals gradually assimilate to another group."
},
"$Target": {
"ZH_CN": "同化目标",
"EN_US": "Assimilation target"
},
"$Max.Delay": {
"ZH_CN": "最长时间",
"EN_US": "Longest time"
},
"$Min.Delay": {
"ZH_CN": "最短时间",
"EN_US": "Shortest time"
},
"$Success": {
"ZH_CN": "成功率",
"EN_US": "Minimum strength"
},
"$Initiative": {
"ZH_CN": "主动",
"EN_US": "Initiative"
}
};
}
export { DelayAssimilate };

View File

@ -131,8 +131,8 @@ class SimulatorWeb extends Component {
tracking.name = "Tracking"; tracking.color = [80, 200, 250]; tracking.name = "Tracking"; tracking.color = [80, 200, 250];
tracking.parameter.target.picker = fishLabel; tracking.parameter.target.picker = fishLabel;
let attacking = this.status.model.addBehavior(getBehaviorById("Attacking")); let attacking = this.status.model.addBehavior(getBehaviorById("ContactAttacking"));
attacking.name = "Attacking"; attacking.color = [120, 100, 250]; attacking.name = "Contact Attacking"; attacking.color = [120, 100, 250];
attacking.parameter.target.picker = fishLabel; attacking.parameter.target.picker = fishLabel;
fish1.addBehavior(dynamicFish); fish1.addBehavior(dynamicFish);