-
Notifications
You must be signed in to change notification settings - Fork 0
/
CombatGraph.fs
47 lines (41 loc) · 1.27 KB
/
CombatGraph.fs
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
module CombatGraph
open Types
open CombatMap
open Dijkstra
type CombatNodeTypeInfo = {
Type: CombatMapTile
Cost: Distance
}
let private tileCostInfo map tiles pos =
tryGetTileAt pos map
|> Option.bind (fun tile ->
match List.tryFind (fun t -> tile = t.Type) tiles with
| Some {Cost = cost} -> Some (nodeInfo pos cost)
| None -> None
)
let private nodesFromCombatMap tiles map =
combatPositions map
|> List.choose (tileCostInfo map tiles)
let private edges (nodeInfo: NodeInfo<Position> list) validPositions : EdgeInfo<Position> =
validPositions
|> List.map (fun p ->
let neighbours = allNeighbours p
validPositions
|> List.filter (fun curr -> List.contains curr neighbours)
|> List.map (fun pos ->
pos,
nodeInfo
|> List.find (fun {NodeID = pos2} -> pos = pos2)
|> (fun {Cost = c} -> c)
)
|> (function lst -> p, lst)
)
|> Map.ofList
let private edgesFromNodes (nodes: NodeInfo<Position> list) =
nodes
|> List.map (fun {NodeID = p} -> p)
|> edges nodes
let fillCombat map tiles destinations =
let nodes = nodesFromCombatMap tiles map
let edges = edgesFromNodes nodes
fill nodes edges destinations