#Since I described the way of using

1 messages · Page 1 of 1 (latest)

green musk
#

what's "crim"? I'm just curious

heavy warren
#

They probably meant crime as the other variables and hints/comments are weaponry, evidence, weapon-checked, weapon-found etc

slim rune
#

Sorry @vernal silo for the reply, but the Weaponry checked = 0; isn't in any function

vernal silo
#

It’s not a full and runnable example, more an outline of what to do. The pieces themselves should work, though.
The statements between (including) that line and getting the IEnumerable at the end would go into some utility method.

slim rune
#

Alright, thank you, I'll let you know how it goes 😎

vernal silo
#

Whatever contains the user’s choices on evidence presence/absence to use as factors for the choice
Could be a list of wrapper class instances, where each one either holds references to the radio buttons for a specific weapon type or only stores the data

slim rune
#

Currently I have:

using System.Collections.Generic;
using UnityEngine;
using System.Linq;

public class Enums : MonoBehaviour
{
    public List<Criminal> criminals;
    public Evidence collectedEvidence;

    [System.Flags]
    public enum Evidence
    {
        None = 0,
        Male = 1 << 0,
        Guns = 1 << 1,
        Melee = 1 << 2,
        MissingFingers = 1 << 3,
        Ring = 1 << 4
    }

    [System.Serializable]
    public struct Criminal
    {
        public string name;
        public Evidence requiredEvidence;

        public Criminal(string name, Evidence requiredEvidence)
        {
            this.name = name;
            this.requiredEvidence = requiredEvidence;
        }
    }

    public List<string> IdentifyCriminals(Evidence collectedEvidence)
    {
        var possibleCriminals = criminals
            .Where(criminal => (collectedEvidence & criminal.requiredEvidence) != Evidence.None)
            .ToList();

        var validCriminals = possibleCriminals
            .Where(criminal => (criminal.requiredEvidence & collectedEvidence) == criminal.requiredEvidence)
            .Select(criminal => criminal.name)
            .ToList();

        foreach(var a in possibleCriminals)
        {
            Debug.Log(a.name);
        }
        return validCriminals;
    }

    private void Start()
    {
        criminals = new List<Criminal>
        {
            new Criminal("A", Evidence.Guns),
            new Criminal("B", Evidence.Guns | Evidence.Melee),
            new Criminal("C", Evidence.Guns | Evidence.Melee | Evidence.MissingFingers)
        };

        Debug.Log("Possible Criminals: " + string.Join(", ", IdentifyCriminals(collectedEvidence)));
    }

    private void CollectEvidence(Evidence evidence)
    {
        collectedEvidence |= evidence;
    }
}

But it isn't filtering the criminals properly

#

My collected evidence is Melee, 2 of the criminals have melee, but none show up when the
Debug.Log("Possible Criminals: " + string.Join(", ", IdentifyCriminals(collectedEvidence)));

heavy warren
#
Debug.Log($"Criminals:");
for(int i = 0; i < criminals.Count; ++i)
    Debug.Log("${i}: {criminals[i]}");
Debug.Log($"Possible:");
for(var criminal in possibleCriminals)
    Debug.Log("{criminal}");
Debug.Log($"Valid:");
for(var criminal in validCriminals )
    Debug.Log("{criminal}");```
slim rune
#
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class CriminalIdentification : MonoBehaviour
{
    public Evidence collectedEvidence;

    // Evidence Types as Flags
    [Flags]
    public enum Evidence
    {
        None = 0,
        Male = 1 << 0,
        Guns = 1 << 1,
        Melee = 1 << 2,
        Hostages = 1 << 3,
        missingFingers = 1 << 4,
        ring = 1 << 5
    }

    // Criminal Data Class
    [Serializable]
    public class Criminal
    {
        public string Type;
        public Evidence RequiredEvidence;

        public Criminal(string type, Evidence evidence)
        {
            Type = type;
            RequiredEvidence = evidence;
        }
    }

    [SerializeField]
    private List<Criminal> criminals = new List<Criminal> { };

    public void AddEvidence(Evidence evidence)
    {
        collectedEvidence |= evidence;
        Debug.Log("Collected: " + evidence.ToString());
    }

    public List<string> IdentifyCriminals()
    {
        return criminals
            .Where(criminal => (criminal.RequiredEvidence & collectedEvidence) == collectedEvidence)
            .Select(criminal => criminal.Type)
            .ToList();
    }

    void Start()
    {
        // Identify possible criminals
        var possibleCriminals = IdentifyCriminals();

        // Output the results
        if (possibleCriminals.Count == 0)
        {
            Debug.Log("No criminals can be identified with the collected evidence.");
        }
        else
        {
            string original = "Possible Criminal(s): ";
            foreach (var criminal in possibleCriminals)
            {
                original += criminal + ", ";
            }
            Debug.Log(original.TrimEnd(',', ' '));
        }
    }
}