-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCar.cs
49 lines (41 loc) · 1.23 KB
/
Car.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
public class Car
{
public Cell Cell;
public int Value;
public int Direction;
public DirectionType DirectionType;
public bool Horizontal;
public bool Visited;
public Convoy Convoy;
public int MinimumDelay;
public Car(Cell cell, int value, char direction)
{
Cell = cell;
cell.Car = this;
Value = value;
Direction = ">v<^".IndexOf(direction);
DirectionType = "<>".Contains(direction) ? DirectionType.HORIZONTAL : DirectionType.VERTICAL;
}
public Cell Next() => Cell.Next[(int)DirectionType];
public override string ToString()
{
return Cell + " " + ">v<^"[Direction];
}
public double Urgency(List<Convoy> convoy) => 1000 * Convoy.Urgency(convoy) + Convoy.ID + 0.01 * Convoy.Cars.IndexOf(this);
public bool DFS_Visited;
public int Dependants;
public int DFS()
{
if (DFS_Visited) return Dependants;
DFS_Visited = true;
Dependants = 0;
foreach (Cell n in Cell.Neighbors)
{
if (n == null || n.Car == null || n.Car.Next() != this.Cell) continue;
Dependants += 1 + n.Car.DFS();
}
return Dependants;
}
}