-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAI.cs
More file actions
43 lines (42 loc) · 1.23 KB
/
AI.cs
File metadata and controls
43 lines (42 loc) · 1.23 KB
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
using System;
using MoonSharp.Interpreter;
namespace simplegame
{
interface IAI {
void PlayTurn(Turn turn);
}
class SimpleAI : IAI {
public void PlayTurn(Turn turn)
{
if(turn.IsEnemyInRange)
{
bool Result = turn.Attack();
if(Result)
{
turn.PlayerNote = "Woo! PWNED!";
}
else
{
turn.PlayerNote = "Lame!";
}
}
else
{
Random Rng = new Random();
turn.Move(1 - Rng.Next(0,3), 1 - Rng.Next(0,3));
// turn.PlayerNote = "Where are they?";
}
}
}
// Inherits MoonSharp.Interpreter.Script and sandboxes itself
// constructor parameter script should be a Lua script that defines function player_turn accepting a Turn as parameter
class LuaAI : Script, IAI {
public LuaAI(string script) : base(CoreModules.Preset_HardSandbox) {
UserData.RegisterType<Turn>();
DoString(script);
}
public void PlayTurn(Turn turn) {
DynValue _ = Call(Globals["player_turn"], turn);
}
}
}