How to do it...

We will build the VertexInfluence and InfluenceMap classes, which are used for handling vertices and the graph, respectively:

  1. Create the VertexInfluence class, deriving from Vertex:
using UnityEngine; 
using System.Collections; 
using System.Collections.Generic; 
 
public class VertexInfluence : Vertex 
{ 
    public Faction faction; 
    public float value = 0f; 
} 
  1. Implement the function for setting up values (it returns true if it was a success, and false otherwise):
public bool SetValue(Faction f, float v) 
{ 
    bool isUpdated = false; 
    if (v > value) 
    { 
        value = v; 
        faction = f; 
        isUpdated = true; 
    } 
    return isUpdated; 
} 
  1. Create the InfluenceMap class deriving from Graph (or a more specific graph implementation):
using UnityEngine; using System.Collections.Generic; ...

Get Unity 2018 Artificial Intelligence Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.