forked from ChalmersGU-AI-course/shrdlite-course-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorld.ts
74 lines (58 loc) · 1.66 KB
/
World.ts
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
69
70
71
72
73
74
// Interface definitions for worlds
interface ObjectDefinition {
form: string;
size: string;
color: string;
}
interface WorldState {
stacks: string[][];
holding: string;
arm: number;
objects: { [s:string]: ObjectDefinition; };
examples: string[];
}
interface World {
currentState : WorldState;
printWorld(callback? : () => void) : void;
performPlan(plan: string[], callback? : () => void) : void;
readUserInput(prompt : string, callback : (string) => void) : void;
printSystemOutput(output : string, participant? : string) : void;
printDebugInfo(info : string) : void;
printError(error : string, message? : string) : void;
}
module WorldFunc {
export function world2String(w : WorldState) : string
{
var out : string = "";
for (var i in w.stacks)
{
out= out.concat(i);
for(var j in w.stacks[i])
{
out = out.concat(w.stacks[i][j]);
}
}
out = out.concat(w.arm.toString());
if(w.holding !== null)
out = out.concat(w.holding);
return out;
}
export function compareWorld(w1 :WorldState,w2 :WorldState ) : boolean
{
for (var i in w1.stacks)
{
for(var j in w1.stacks[i])
{
if(w1.stacks[i][j] !== w2.stacks[i][j])
{
return false;
}
}
}
if(w1.arm !== w2.arm)
return false;
if(w1.holding !== w2.holding)
return false;
return true;
}
}