-
Notifications
You must be signed in to change notification settings - Fork 0
/
ai.nim
144 lines (115 loc) · 4.21 KB
/
ai.nim
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
{.optimization: speed.}
import strutils
const TeamName: cstring = "SERS TEAM"
var CurGame: cint = 0
var CurAction: cint = 0
var Teleport: cint = 0
var bGameEnd: cint = 0
var AI_TeamID = 0
var WheelLeft: cint = 0
var WheelRight: cint = 0
var LED_1: cint = 0
var MyState: cint = 0
var SuperObj_X: cint = 0
var SuperObj_Y: cint = 0
var SuperObj_Num: cint = 0
var OtherRob_SMS: cint = 0
var OtherRob_PositionX: cint = 0
var OtherRob_PositionY: cint = 0
var ObjState: cint = 0
var ObjPositionX: cint = 0
var ObjPositionY: cint = 0
var ObjDuration: cint = 0
var MySMS: cint = 0
var US_Front: cint = 0
var US_Left: cint = 0
var US_Right: cint = 0
var CSLeft_R: cint = 0
var CSLeft_G: cint = 0
var CSLeft_B: cint = 0
var CSRight_R: cint = 0
var CSRight_G: cint = 0
var CSRight_B: cint = 0
var PositionX: cint = 0
var PositionY: cint = 0
var TM_State: cint = 0
var Compass: cint = 0
var Time: cint = 0
var TimerDuration: cint = 0
proc setGameID*(GameID: cint): void {.exportc: "SetGameID", dynlib.} =
CurGame = GameID
bGameEnd = 0
proc setTeamID*(TeamID: cint): void {.exportc: "SetTeamID", dynlib.} =
AI_TeamID = TeamID
proc getGameID*(): cint {.exportc: "GetGameID", dynlib.} =
return CurGame
proc isGameEnd*(): cint {.exportc: "IsGameEnd", dynlib.} =
return bGameEnd
proc getDebugInfo*(): cstring {.exportc: "GetDebugInfo", dynlib.} =
let infoData = @[
"bGameEnd=$1" % [$bGameEnd],
"TimerDuration=$1" % [$TimerDuration]
]
let info = infoData.join(";") & ";"
return info
proc getTeamName*(): cstring {.exportc: "GetTeamName", dynlib.} =
return TeamName
proc getCurAction*(): cint {.exportc: "GetCurAction", dynlib.} =
return CurAction
proc getTeleport*(): cint {.exportc: "GetTeleport", dynlib.} =
## Only Used by CsBot Rescue Platform
return Teleport
proc setSuperObj*(x: cint, y: cint, num: cint): void {.exportc: "SetSuperObj", dynlib.} =
## Only Used by CsBot Rescue Platform
SuperObj_X = x
SuperObj_Y = y
SuperObj_Num = num
proc getSuperObj*(x: ptr cint; y: ptr cint; num: ptr cint): void {.exportc: "GetSuperObj", dynlib.} =
## Only Used by CsBot Rescue Platform
x[] = SuperObj_X
y[] = SuperObj_Y
num[] = SuperObj_Num
proc updateRobInfo*(sms: cint, x: cint, y: cint): void {.exportc: "UpdateRobInfo", dynlib.} =
## Used by CoSpace Rescue Simulation.
## Called each time frame by simulator to update the other robot information.
OtherRob_SMS = sms
OtherRob_PositionX = x
OtherRob_PositionY = y
proc updateObjectInfo*(x: cint, y: cint, state: cint, duration: cint): void {.exportc: "UpdateObjectInfo", dynlib.} =
## Only Used by CsBot Rescue Platform
ObjState = state
ObjPositionX = x
ObjPositionY = y
ObjDuration = duration
proc getMySMS*(): cint {.exportc: "GetMySMS", dynlib.} =
return MySMS
proc setDataAI*(packet: ptr UncheckedArray[cint]; AI_IN: ptr UncheckedArray[cint]): void {.exportc: "SetDataAI", dynlib.} =
var sum: cint = 0
US_Front = AI_IN[0]; packet[0] = US_Front; sum += US_Front;
US_Left = AI_IN[1]; packet[1] = US_Left; sum += US_Left;
US_Right = AI_IN[2]; packet[2] = US_Right; sum += US_Right;
CSLeft_R = AI_IN[3]; packet[3] = CSLeft_R; sum += CSLeft_R;
CSLeft_G = AI_IN[4]; packet[4] = CSLeft_G; sum += CSLeft_G;
CSLeft_B = AI_IN[5]; packet[5] = CSLeft_B; sum += CSLeft_B;
CSRight_R = AI_IN[6]; packet[6] = CSRight_R; sum += CSRight_R;
CSRight_G = AI_IN[7]; packet[7] = CSRight_G; sum += CSRight_G;
CSRight_B = AI_IN[8]; packet[8] = CSRight_B; sum += CSRight_B;
PositionX = AI_IN[9]; packet[9] = PositionX; sum += PositionX;
PositionY = AI_IN[10]; packet[10] = PositionY; sum += PositionY;
TM_State = AI_IN[11]; packet[11] = TM_State; sum += TM_State;
Compass = AI_IN[12]; packet[12] = Compass; sum += Compass;
Time = AI_IN[13]; packet[13] = Time; sum += Time;
packet[14] = sum;
proc getCommand*(AIOut: ptr UncheckedArray[cint]): void {.exportc: "GetCommand", dynlib.} =
AIOut[0] = WheelLeft
AIOut[1] = WheelRight
AIOut[2] = LED_1
AIOut[3] = MyState
proc onTimer*(): void {.exportc: "OnTimer", dynlib.} =
## Main robot login
TimerDuration += 1
case CurGame:
of 0:
echo "0"
else:
echo "defaulted"