Reset total on reset

This commit is contained in:
Thibault Neveu
2018-06-15 16:47:49 +01:00
parent 9e16c49a46
commit 13074c36ec
5 changed files with 13 additions and 14 deletions
+3 -3
View File
File diff suppressed because one or more lines are too long
+3 -3
View File
File diff suppressed because one or more lines are too long
+3 -7
View File
@@ -125,7 +125,7 @@ export class AssetManger {
road.obstacle = false;
road.mapId = MAP.ROAD;
road.orientation = ASSETS.ROADS[info.type].orientation;
road.setCarPosition = (car: any, line: number) => this.setCarOnRoad(road, car, line);
road.setCarPosition = (car: any, line: number, force: boolean=false) => this.setCarOnRoad(road, car, line, force);
road.cars = [];
road.mx = info.mx; // Map x
road.my = info.my; // Map y
@@ -133,7 +133,7 @@ export class AssetManger {
this.level.addRoad(road);
}
setCarOnRoad(road: RoadSprite, car: any, line: number){
setCarOnRoad(road: RoadSprite, car: any, line: number, force: boolean=false){
/*
@road: (Obejct) road to position the car on
@car: (Object) car object to position
@@ -142,13 +142,9 @@ export class AssetManger {
if (line == undefined)
line = 0;
let carById = this.level.findCarById(road.cars[0]);
if (road.cars.length >= 1 && carById && carById.core.line == line){
if (!force && road.cars.length >= 1 && carById && carById.core.line == line){
line = line == 0 ? 1:0;
}
if (road.cars.length >= 2){
car.is_valid = false;
return;
}
car.line = line;
// Set the car on the road
+1 -1
View File
@@ -178,7 +178,7 @@ export class Car {
this.core.my = this.info.my;
let road = this.level.getRoad(this.core.my, this.core.mx);
if (road){ // If the car is on a road
road.setCarPosition(this.core, this.info.line);
road.setCarPosition(this.core, this.info.line, true);
}
}
+3
View File
@@ -91,6 +91,9 @@ export class Level extends World {
useless collisions.
*/
this.agent.reset();
for (var c = 0; c < this.cars.length; c++) {
this.cars[c].reset();
}
}
setReward(agent_col: any, on_road: any, action: any){