-
Notifications
You must be signed in to change notification settings - Fork 2
/
Baker.cs
68 lines (53 loc) · 1.77 KB
/
Baker.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
//using UnityEngine;
namespace Activ.GOAP{
[Serializable] public class Baker : Agent, Mapped{
public enum Cooking{Raw, Cooked, Burned}
//
public const int Step = 55;
public const int MaxHeat = 200;
public int temperature = 0;
public float bake;
//
[NonSerialized] (Option, Action)[] options;
[NonSerialized] AI client;
public Baker(){}
public Baker(AI client) => this.client = client;
public Cooking state => bake < 80 ? Cooking.Raw :
bake < 120 ? Cooking.Cooked :
Cooking.Burned;
public Cost Bake(){
bake += (temperature / 2); return true;
}
public Cost SetTemperature(int degrees){
temperature = degrees;
return true;
}
Option[] Agent.Options()
=> state != Cooking.Burned ? new Option[]{ Bake } : null;
(Option, Action)[] Mapped.Options()
=> state != Cooking.Burned ? CookingOptions() : null;
(Option, Action)[] CookingOptions(){
var n = MaxHeat/Step + 1;
options = options ?? new (Option, Action)[n];
for(int i = 0; i < n; i++){
var t = i * Step; // do not capture the iterator!
options[i] = (() => SetTemperature(t),
() => client.SetTemperature(t));
}
return options;
}
override public bool Equals(object other){
var that = other as Baker;
return this.bake == that.bake
&& this.temperature == that.temperature;
}
override public int GetHashCode()
=> temperature + (int)(bake * 1000);
override public string ToString()
=> $"Baker[ {state} at {temperature}℃ ]";
public interface AI{
void Bake();
void SetTemperature(int i);
}
}}