Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion code/HellMapManager/Cores/MapDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public bool Import(byte[] data)
}
return false;
}
public string Export()
public string Export(MapEncoding encoding)
{
_lock.EnterWriteLock();
try
Expand All @@ -104,7 +104,10 @@ public string Export()
{
return "";
}
var rawencoding = Current.Map.Encoding;
Current.Map.Encoding = encoding;
var data = HMMEncoder.GetEncoding(Current.Map.Encoding).GetString(HMMEncoder.Encode(Current));
Current.Map.Encoding = rawencoding;
return data;
}
catch (Exception)
Expand Down
7 changes: 6 additions & 1 deletion code/HellMapManager/Services/API/Dll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ public static IntPtr DllExport(IntPtr input, int encoding)
try
{
Raw(input, encoding);
var result = AppKernel.MapDatabase.Export();
var mapencoding = encoding switch
{
1 => MapEncoding.GB18030,
_ => MapEncoding.Default,
};
var result = AppKernel.MapDatabase.Export(mapencoding);
return RawOut(result, encoding);
}
catch (Exception)
Expand Down
28 changes: 11 additions & 17 deletions doc/api/example/blocked.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ end
local blocker=Blocker:new()

local query=hmmlib.QueryPathAny.new()
query.From={"2522"}
query.Target={"3431"}
query.Start="2522"
query.Target={"2440","2544","2494"}

local result=json.decode(hmm:call("querypathany", json.encode(query)))
local result=json.decode(hmm:call("querypathordered", json.encode(query)))
if (result==nil) then
print("No path found")
else
Expand All @@ -66,12 +66,9 @@ else
end

blocker:block(blockedroom, blockedStep)
query=hmmlib.QueryPathAny.new()
query.From={"2522"}
query.Target={"3431"}
query.Environment=hmmlib.Environment.new()
query.Environment.BlockedLinks=blocker:list()
result=json.decode(hmm:call("querypathany", json.encode(query)))
result=json.decode(hmm:call("querypathordered", json.encode(query)))
if (result==nil) then
print("No blocked path found")
else
Expand Down Expand Up @@ -115,24 +112,21 @@ hmm = hmmpy.HMMDll("./HellMapManager.so")
with open('hongchen.hmm', 'r', encoding='utf-8') as f:
hmm.call("import",f.read())

query=hmmpy.QueryPathAny()
query.From=["2522"]
query.Target=["3431"]
query=hmmpy.QueryPath()
query.Start="2522"
query.Target=["2440","2544","2494"]

result=json.loads(hmm.call("querypathany", hmm.encode(query)))
result=json.loads(hmm.call("querypathordered", hmm.encode(query)))
if (result==None):
print("No path found")
else:
print("Path found:")
print(result)

blocker.block(blockedroom, blockedStep)
query=hmmpy.QueryPathAny()
query.From=["2522"]
query.Target=["3431"]
query.Environment=hmmpy.Environment()
query.Environment.BlockedLinks=blocker.list()
result=json.loads(hmm.call("querypathany", hmm.encode(query)))
result=json.loads(hmm.call("querypathordered", hmm.encode(query)))
if (result==None):
print("No blocked path found")
else:
Expand All @@ -143,7 +137,7 @@ else:
## 输出
```
Path found:
{'From': '2522', 'To': '3431', 'Cost': 29, 'Steps': [{'Command': 'e', 'Target': '2440', 'Cost': 1}, {'Command': 'e', 'Target': '2544', 'Cost': 1}, {'Command': 'e', 'Target': '2494', 'Cost': 1}, {'Command': 'goto beijing', 'Target': '3432', 'Cost': 20}, {'Command': 'e', 'Target': '3436', 'Cost': 1}, {'Command': 'e', 'Target': '3500', 'Cost': 1}, {'Command': 'e', 'Target': '3501', 'Cost': 1}, {'Command': 'e', 'Target': '3404', 'Cost': 1}, {'Command': 'e', 'Target': '3430', 'Cost': 1}, {'Command': 'n', 'Target': '3431', 'Cost': 1}], 'Unvisited': []}
{'From': '2522', 'To': '2494', 'Cost': 3, 'Steps': [{'Command': 'e', 'Target': '2440', 'Cost': 1}, {'Command': 'e', 'Target': '2544', 'Cost': 1}, {'Command': 'e', 'Target': '2494', 'Cost': 1}], 'Unvisited': []}
Blocked path found:
{'From': '2522', 'To': '3431', 'Cost': 51, 'Steps': [{'Command': 'e', 'Target': '2440', 'Cost': 1}, {'Command': 's', 'Target': '2439', 'Cost': 1}, {'Command': 's', 'Target': '2460', 'Cost': 1}, {'Command': 's', 'Target': '2504', 'Cost': 1}, {'Command': 's', 'Target': '2505', 'Cost': 1}, {'Command': 's', 'Target': '2506', 'Cost': 1}, {'Command': 's', 'Target': '1600', 'Cost': 1}, {'Command': 's', 'Target': '1602', 'Cost': 1}, {'Command': 's', 'Target': '1603', 'Cost': 1}, {'Command': 's', 'Target': '1604', 'Cost': 1}, {'Command': 'w', 'Target': '1605', 'Cost': 1}, {'Command': 'n', 'Target': '2560', 'Cost': 1}, {'Command': 'n', 'Target': '2616', 'Cost': 1}, {'Command': 'n', 'Target': '2615', 'Cost': 1}, {'Command': 'n', 'Target': '2619', 'Cost': 1}, {'Command': 'n', 'Target': '2618', 'Cost': 1}, {'Command': 'n', 'Target': '2617', 'Cost': 1}, {'Command': 'n', 'Target': '2575', 'Cost': 1}, {'Command': 'e', 'Target': '2568', 'Cost': 1}, {'Command': 'e', 'Target': '2569', 'Cost': 1}, {'Command': 'n', 'Target': '2571', 'Cost': 1}, {'Command': 'n', 'Target': '2572', 'Cost': 1}, {'Command': 'n', 'Target': '2590', 'Cost': 1}, {'Command': 'w', 'Target': '2610', 'Cost': 1}, {'Command': 'n', 'Target': '2601', 'Cost': 1}, {'Command': 'goto beijing', 'Target': '3432', 'Cost': 20}, {'Command': 'e', 'Target': '3436', 'Cost': 1}, {'Command': 'e', 'Target': '3500', 'Cost': 1}, {'Command': 'e', 'Target': '3501', 'Cost': 1}, {'Command': 'e', 'Target': '3404', 'Cost': 1}, {'Command': 'e', 'Target': '3430', 'Cost': 1}, {'Command': 'n', 'Target': '3431', 'Cost': 1}], 'Unvisited': []}
{'From': '2522', 'To': '2494', 'Cost': 35, 'Steps': [{'Command': 'e', 'Target': '2440', 'Cost': 1}, {'Command': 's', 'Target': '2439', 'Cost': 1}, {'Command': 's', 'Target': '2460', 'Cost': 1}, {'Command': 'e', 'Target': '2448', 'Cost': 1}, {'Command': 'e', 'Target': '2449', 'Cost': 1}, {'Command': 'e', 'Target': '2450', 'Cost': 1}, {'Command': 'e', 'Target': '4033', 'Cost': 1}, {'Command': 'e', 'Target': '4034', 'Cost': 1}, {'Command': 'se', 'Target': '4151', 'Cost': 1}, {'Command': 's', 'Target': '4152', 'Cost': 1}, {'Command': 'e', 'Target': '4137', 'Cost': 1}, {'Command': 's', 'Target': '4140', 'Cost': 1}, {'Command': 'sw', 'Target': '4142', 'Cost': 1}, {'Command': 'goto yangzhou', 'Target': '2494', 'Cost': 20}, {'Command': 'w', 'Target': '2544', 'Cost': 1}, {'Command': 'e', 'Target': '2494', 'Cost': 1}], 'Unvisited': []}
```
9 changes: 5 additions & 4 deletions doc/api/example/convert.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
```lua
local hmmlib=require('hmm')
local hmm=hmmlib.new()
hmm:all("create")
hmm.DllEncoding=0 --0 for utf-8, 1 for gbk
local json=require('json')
local roomsdata=readroomsdata()
Expand Down Expand Up @@ -60,12 +61,12 @@ for key,value in ipairs(roomlinks)
exit.Cost=1
table.insert(rooms[from_room].Exits,exit)
end
inputrooms=hmmpy.Rooms.new()
inputrooms=hmmlib.Rooms.new()
for key,value in rooms()
table.insert(inputrooms.Rooms,room)
table.insert(inputrooms.Rooms,value)
end
hmm.call("insertrooms", json.encode(inputrooms))
output=hmm.call("export")
hmm:call("insertrooms", json.encode(inputrooms))
output=hmm:call("export")
print(output)
local file = assert(io.open("my.hmm", "w"))
file:write(output)
Expand Down
Loading