Skip to content

Instantly share code, notes, and snippets.

@letoh
Last active August 29, 2015 13:55
Show Gist options
  • Select an option

  • Save letoh/8713439 to your computer and use it in GitHub Desktop.

Select an option

Save letoh/8713439 to your computer and use it in GitHub Desktop.
Index: army/hwh/triple.erl
===================================================================
--- army/hwh/triple.erl (revision 841)
+++ army/hwh/triple.erl (working copy)
@@ -1,4 +1,4 @@
--module(hwh.triple).
+-module(triple).
-compile(export_all).
-include("hwh_schema.hrl").
@@ -11,10 +11,10 @@
run(Channel, Side, Queue) ->
process_flag(trap_exit,true),
Master = self(),
- InfoTb = .ets:new(info, [set, protected]),
+ InfoTb = ets:new(info, [set, protected]),
%%淇℃伅鏀堕泦杩涚▼锛屾敹闆嗘瘡涓垬鍖哄唴鏁屾垜鎯呭喌
- Info = spawn_link(hwh.info, start, [Master, Side]),
+ Info = spawn_link(info, start, [Master, Side]),
%% 鎺ユ敹鎴樺尯琛�
receive
@@ -25,45 +25,45 @@
Phone = #phone{channel=Channel, info=InfoTb, side=Side, queue=Queue, grid=Grid},
%%鍒嗗竷杩藉嚮杩涚▼
- ScatterL = .lists:map(
+ ScatterL = lists:map(
fun(Y) ->
- spawn_link(hwh.scatter, start, [Master, Y, Phone])
+ spawn_link(scatter, start, [Master, Y, Phone])
end,
[0,1,2]),
%%闃靛瀷鍜屾垬澹繘绋�
- FM = spawn_link(hwh.fm, start, [Master, Phone, random2]),
- SoldierList = .lists:map(
+ FM = spawn_link(fm, start, [Master, Phone, random2]),
+ SoldierList = lists:map(
fun(ID) ->
- spawn_link(hwh.one, start, [Master, Phone, {ID, Side}, hold])
+ spawn_link(one, start, [Master, Phone, {ID, Side}, hold])
end,
[1,2,3,4,5,6,7,8,9,10]),
%% 灏嗘墍鏈夎繘绋嬶紝浠ュ強Phone 浼犲叆寰幆绋嬪簭
- loop(Channel, .lists:merge([FM, Info], ScatterL), SoldierList, Phone).
+ loop(Channel, lists:merge([FM, Info], ScatterL), SoldierList, Phone).
%% Childs 浼犲叆涓昏涓轰簡娓呴櫎杩涚▼鐨�
loop(Channel, Childs, SoldierList, Phone) ->
receive
{'EXIT', Channel, finish} ->
- .lists:foreach(fun(PID) -> exit(PID, finish) end, Childs),
- .lists:foreach(fun(PID) -> exit(PID, finish) end, SoldierList);
+ lists:foreach(fun(PID) -> exit(PID, finish) end, Childs),
+ lists:foreach(fun(PID) -> exit(PID, finish) end, SoldierList);
%% 鎺ュ埌鍒楅樀浠诲姟锛屽悗閫氳繃info 琛紝鎶婂垪闃垫寚浠や紶閫掔粰鎴樺+
{set_fm, _FM, PosList} ->
Tb = Phone#phone.info,
- .ets:insert(Tb, {fm_pos, PosList}),
+ ets:insert(Tb, {fm_pos, PosList}),
loop(Channel, Childs, SoldierList, Phone);
{set_attack, _FM} ->
Master = self(),
- .lists:foreach(fun(PID) -> PID ! {set, Master, attack} end, SoldierList),
+ lists:foreach(fun(PID) -> PID ! {set, Master, attack} end, SoldierList),
loop(Channel, Childs, SoldierList, Phone);
%% 閫氳繃info 琛紝鍚戞垬澹笅杈捐拷鍑绘寚浠�
{pursue, _Scatter, ID} ->
Tb = Phone#phone.info,
- .ets:insert(Tb, {{pursue, ID}, 1}),
+ ets:insert(Tb, {{pursue, ID}, 1}),
loop(Channel, Childs, SoldierList, Phone);
_ -> loop(Channel, Childs, SoldierList, Phone)
Index: army/hwh/one.erl
===================================================================
--- army/hwh/one.erl (revision 841)
+++ army/hwh/one.erl (working copy)
@@ -1,4 +1,4 @@
--module(hwh.one).
+-module(one).
-compile(export_all).
-include("hwh_schema.hrl").
-include("schema.hrl").
@@ -24,7 +24,7 @@
start(Master, Phone, ID, AI) when is_record(Phone, phone) ->
process_flag(trap_exit, true),
- hwh.util:srand(),
+ util:srand(),
put(phone, Phone),
%%{Idx, _} = ID,
%%{ok, File} = .file:open(integer_to_list(Idx), [write]),
@@ -73,7 +73,7 @@
%%浠庨樀鍨嬩腑鎵惧埌鍚堥�傝嚜宸辩殑浣嶇疆
get_fm_dest(One, Phone) when is_record(Phone, phone) ->
Info = Phone#phone.info,
- case .ets:lookup(Info, fm_pos) of
+ case ets:lookup(Info, fm_pos) of
[] -> none;
[{fm_pos, PosList}|_] -> get_fm_dest(One, PosList)
@@ -84,7 +84,7 @@
Soldier = One#data.soldier,
SID = soldier_id(One),
{X, Y} = Soldier#soldier.position,
- [H|_] = .lists:sort(
+ [H|_] = lists:sort(
fun({ID1, X1,Y1}, {ID2, X2,Y2}) ->
if
ID1 =:= SID andalso ID2 =/= SID -> true;
@@ -108,12 +108,12 @@
acture_facing(_, F) -> F.
acture_facing(Soldier) -> acture_facing(Soldier#soldier.action, Soldier#soldier.facing).
acture_pos(Soldier) when Soldier#soldier.action =:= ?ActionForward ->
- .erlbattle:calcDestination(Soldier#soldier.position, Soldier#soldier.facing, 1);
+ erlbattle:calcDestination(Soldier#soldier.position, Soldier#soldier.facing, 1);
acture_pos(Soldier) -> Soldier#soldier.position.
%%瀵圭洰鏍囧璺紝骞舵洿鏂拌嚜宸辩殑鐩爣
search_path(One, Dest) ->
Soldier = One#data.soldier,
- case hwh.util:astar(acture_pos(Soldier), Dest, acture_facing(Soldier)) of
+ case util:astar(acture_pos(Soldier), Dest, acture_facing(Soldier)) of
none -> {none, One};
stop -> {Dest, One#data{path = []}};
[] -> {none, One#data{path = []}};
@@ -139,11 +139,11 @@
none -> killed;
Soldier ->
Channel = Phone#phone.channel,
- Facing = hwh.util:facing(Phone#phone.side),
+ Facing = util:facing(Phone#phone.side),
NewOne = One#data{soldier = Soldier},
- case hwh.util:path(Soldier, Dest, Facing) of
+ case util:path(Soldier, Dest, Facing) of
stop ->
- NewPathList = .lists:delete(Dest, NewOne#data.path),
+ NewPathList = lists:delete(Dest, NewOne#data.path),
free_play(NewOne#data{path = NewPathList}, Phone);
none ->
@@ -164,7 +164,7 @@
soldier(Soldier) when is_record(Soldier, soldier) -> soldier(Soldier#soldier.id);
soldier(ID) ->
{Idx, Side} = ID,
- .battlefield:get_soldier(Idx, Side).
+ battlefield:get_soldier(Idx, Side).
%%绉诲姩鎴栬�呮敾鍑�
@@ -209,16 +209,16 @@
%%姝ゆ椂鍦ㄨ韩杈规壘鏈夋病鏈夋帴瑙︾殑鏁屼汉銆� 濡傛灉鏈夛紝鎸戣儗鍚戣嚜宸辩殑涓�涓晫浜猴紙搴斾负鍔犳垚鏈�澶氾級锛涘鏋滄病鏈夛紝灏遍殢渚胯浆鍚戜竴涓晫浜�
%%濡傛灉娌℃湁浠讳綍鏁屼汉灏辫繑鍥瀗one
touch_around(Soldier, _) ->
- L = .lists:flatmap(
+ L = lists:flatmap(
fun(Facing) ->
- Pos = .erlbattle:calcDestination(Soldier#soldier.position, Facing, 1),
- case .battlefield:get_soldier_by_position(Pos) of
+ Pos = erlbattle:calcDestination(Soldier#soldier.position, Facing, 1),
+ case battlefield:get_soldier_by_position(Pos) of
none -> [];
Other -> turn_to_enemy(Soldier, Other, {Other, Facing})
end
end,
[?DirEast, ?DirWest, ?DirNorth, ?DirSouth]),
- L2 = .lists:sort(
+ L2 = lists:sort(
fun({Other1, Facing1}, {Other2, Facing2}) ->
if
Other1#soldier.facing =:= Facing1 -> true;
@@ -229,13 +229,13 @@
L),
case L2 of
[] -> none;
- [{_, F}|_] -> {hwh.util:turn(F), 0}
+ [{_, F}|_] -> {util:turn(F), 0}
end.
%%杩藉嚮鏁屼汉
purse_enemy(One, Phone) ->
- case .ets:lookup(Phone#phone.info, {pursue, One#data.id}) of
+ case ets:lookup(Phone#phone.info, {pursue, One#data.id}) of
[] -> army_forward(One, Phone); %娌℃湁杩藉嚮鎸囦护锛屽氨鎭㈠鏈濆鏂归樀鍦板墠鏅�
_ -> search_enemy(One, Phone)
end.
@@ -244,8 +244,8 @@
%%鏈濋瀹氭柟鍚戝墠杩�
army_forward(One, Phone) ->
Soldier = One#data.soldier,
- Facing = hwh.util:facing(Phone#phone.side),
- Action = hwh.util:turn(Facing),
+ Facing = util:facing(Phone#phone.side),
+ Action = util:turn(Facing),
X = if
Soldier#soldier.facing =/= Facing andalso Soldier#soldier.action =/= Action ->
{Action, 0};
@@ -257,12 +257,12 @@
%%鏌ユ壘绂昏嚜宸辨渶杩戠殑鏁屼汉
search_enemy(One, Phone) ->
- Enemys = .battlefield:get_soldier_by_side(hwh.util:enemy(Phone#phone.side)),
+ Enemys = battlefield:get_soldier_by_side(util:enemy(Phone#phone.side)),
Soldier = One#data.soldier,
- NewEnemys = .lists:sort(
+ NewEnemys = lists:sort(
fun(E1, E2) ->
- L1 = hwh.util:dist(Soldier, E1),
- L2 = hwh.util:dist(Soldier, E2),
+ L1 = util:dist(Soldier, E1),
+ L2 = util:dist(Soldier, E2),
L1 =< L2
end,
Enemys),
@@ -286,8 +286,8 @@
select_target(_, none, T2) -> T2;
select_target(_, T1, T2) when T1#soldier.id =:= T2#soldier.id -> T2;
select_target(Soldier, T1, T2) ->
- L1 = hwh.util:dist(Soldier, T1),
- L2 = hwh.util:dist(Soldier, T2),
+ L1 = util:dist(Soldier, T1),
+ L2 = util:dist(Soldier, T2),
if
(L1 - L2) > 1 -> T2;
true -> T1
@@ -305,8 +305,8 @@
%%鑾峰彇鎴樺+鍓嶆柟鐨勭洰鏍�
front_soldier(Soldier, Dist) ->
- Pos = .erlbattle:calcDestination(Soldier#soldier.position, Soldier#soldier.facing, Dist),
- .battlefield:get_soldier_by_position(Pos).
+ Pos = erlbattle:calcDestination(Soldier#soldier.position, Soldier#soldier.facing, Dist),
+ battlefield:get_soldier_by_position(Pos).
%%鏍规嵁鍓嶆柟鎯呭舰鍐冲畾涓嬩竴姝ュ姩浣�
Index: army/hwh/fm.erl
===================================================================
--- army/hwh/fm.erl (revision 841)
+++ army/hwh/fm.erl (working copy)
@@ -1,4 +1,4 @@
--module(hwh.fm).
+-module(fm).
-compile(export_all).
-include("hwh_schema.hrl").
-include("schema.hrl").
@@ -7,7 +7,7 @@
start(Master, Phone, Type) when is_record(Phone, phone) ->
process_flag(trap_exit, true),
- hwh.util:srand(),
+ util:srand(),
PosList = init_fm(Master, Phone#phone.side, Type),
loop(Master, Phone, #data{poslist=PosList}).
@@ -29,25 +29,25 @@
%% 闅忔満鍐冲畾鍦� X=1,2,3 鐨勫熀鍑嗙嚎甯冮樀
calc_poslist(Side, Type) ->
- L = hwh.fm_box:type(Type),
- Offset = .random:uniform(3),
+ L = fm_box:type(Type),
+ Offset = random:uniform(3),
if
- Side =:= ?RedSide -> .lists:map(fun({ID, X, Y}) -> {ID, X+Offset, Y} end, L);
- true -> .lists:map(fun({ID, X, Y}) -> {ID, 14-X-Offset, Y} end, L)
+ Side =:= ?RedSide -> lists:map(fun({ID, X, Y}) -> {ID, X+Offset, Y} end, L);
+ true -> lists:map(fun({ID, X, Y}) -> {ID, 14-X-Offset, Y} end, L)
end.
%%纭鎴樺+鏄惁鍒拌揪鎸囧畾闃靛瀷
check_fm(Master, Phone, Data) ->
- L = .lists:map(
+ L = lists:map(
fun({_, X, Y}) ->
- case hwh.bf:get_soldier_by_position({X, Y}) of
+ case bf:get_soldier_by_position({X, Y}) of
none -> 0;
Soldier -> check_soldier(Soldier, Phone#phone.side)
end
end,
Data#data.poslist),
- Len = .lists:sum(L),
+ Len = lists:sum(L),
if
%% 濡傛灉閮ㄩ槦鍏ㄩ儴鍒拌揪鎸囧畾浣嶇疆锛屾垨鑰呭凡缁忚Е鏁岋紝灏卞彂璧锋垬鏂椾换鍔�
Len >= length(Data#data.poslist) -> Master ! {set_attack, self()};
Index: army/hwh/scatter.erl
===================================================================
--- army/hwh/scatter.erl (revision 841)
+++ army/hwh/scatter.erl (working copy)
@@ -1,4 +1,4 @@
--module(hwh.scatter).
+-module(scatter).
-compile(export_all).
-include("hwh_schema.hrl").
-include("schema.hrl").
@@ -37,31 +37,31 @@
{row_soldier(Y, Phone, #grid_info.friend), row_soldier(Y, Phone, #grid_info.enemy)}.
row_soldier(Y, Phone, Key) ->
Grid = Phone#phone.grid,
- L = .lists:map(
+ L = lists:map(
fun(X) ->
- [GridInfo|_] = .ets:lookup(Grid, {X, Y}),
+ [GridInfo|_] = ets:lookup(Grid, {X, Y}),
element(Key, GridInfo)
end,
[0, 1, 2]),
- .lists:umerge(L).
+ lists:umerge(L).
%%涓嬩护鏈鐨勬垜鍐涜拷鍑绘晫鍐�
scatter(Master, IDs, Phone) ->
%%浠庢垬鍦鸿〃涓彇鍑烘墍鏈夎繕娲荤潃鐨勬垬澹璞�
- Soldiers = .lists:flatmap(
+ Soldiers = lists:flatmap(
fun(ID) ->
- case hwh.one:soldier(ID) of
+ case one:soldier(ID) of
none -> [];
Soldier -> [Soldier]
end
end,
IDs),
Info = Phone#phone.info,
- .lists:foreach(
+ lists:foreach(
fun(Soldier) ->
%% 鐪嬬湅褰撳墠鎴樺+鏈夋病鏈夊湪杩藉嚮鏁屼汉锛屽鏋滄病鏈夊氨鍚戜富绋嬪簭鍙戦�佽拷鍑绘寚浠�
- case .ets:lookup(Info, {pursue, Soldier#soldier.id}) of
+ case ets:lookup(Info, {pursue, Soldier#soldier.id}) of
[] -> Master ! {pursue, self(), Soldier#soldier.id};
_ -> none
end
Index: army/hwh/bf.erl
===================================================================
--- army/hwh/bf.erl (revision 841)
+++ army/hwh/bf.erl (working copy)
@@ -1,4 +1,4 @@
--module(hwh.bf).
+-module(bf).
-compile(export_all).
-include("schema.hrl").
@@ -14,7 +14,7 @@
act_sequence = '_'
},
- case .ets:match_object(battle_field,Pattern) of
+ case ets:match_object(battle_field,Pattern) of
[Soldier|_] ->
Soldier;
[]->
Index: army/hwh/fm_box.erl
===================================================================
--- army/hwh/fm_box.erl (revision 841)
+++ army/hwh/fm_box.erl (working copy)
@@ -1,11 +1,11 @@
--module(hwh.fm_box).
+-module(fm_box).
-compile(export_all).
%%{ID, X, Y}
type(triangle2) ->
- .io:format("triangle2~n", []),
+ io:format("triangle2~n", []),
[
{1, 0, 2},
{2, 1,3},
@@ -19,7 +19,7 @@
{10, 0,11}
];
type(double_w) ->
- .io:format("double_w~n", []),
+ io:format("double_w~n", []),
[
{1, 1, 2},
{2, 0, 3},
@@ -33,7 +33,7 @@
{10, 1, 11}
];
type(crane) ->
- .io:format("crane~n", []),
+ io:format("crane~n", []),
[
{1, 3, 2},
{2, 2, 3},
@@ -48,9 +48,9 @@
];
type(random) ->
L = [triangle2, double_w, crane],
- N = .random:uniform(length(L)),
- type(.lists:nth(N, L));
+ N = random:uniform(length(L)),
+ type(lists:nth(N, L));
type(random2) ->
L = [triangle2, double_w, crane, triangle2, double_w, crane],
- N = .random:uniform(length(L)),
- type(.lists:nth(N, L)).
\ No newline at end of file
+ N = random:uniform(length(L)),
+ type(lists:nth(N, L)).
Index: army/hwh/info.erl
===================================================================
--- army/hwh/info.erl (revision 841)
+++ army/hwh/info.erl (working copy)
@@ -1,4 +1,4 @@
--module(hwh.info).
+-module(info).
-compile(export_all).
-include("hwh_schema.hrl").
-include("schema.hrl").
@@ -6,7 +6,7 @@
start(Master, Side) ->
process_flag(trap_exit, true),
- Tb = .ets:new(grid, [set, protected, {keypos, #grid_info.id}]),
+ Tb = ets:new(grid, [set, protected, {keypos, #grid_info.id}]),
init(Tb),
Master ! {grid, Tb},
loop(Tb, Side, Master).
@@ -16,15 +16,15 @@
Grids = [{0,0}, {0,1}, {0,2},
{1,0}, {1,1}, {1,2},
{2,0}, {2,1}, {2,2}],
- .lists:foreach(fun(ID) -> .ets:insert(Tb, #grid_info{id=ID}) end,
+ lists:foreach(fun(ID) -> ets:insert(Tb, #grid_info{id=ID}) end,
Grids).
loop(Tb, Side, Master) ->
reset(Tb),
- Enemys = .battlefield:get_soldier_by_side(util:enemy(Side)),
+ Enemys = battlefield:get_soldier_by_side(util:enemy(Side)),
update_grid(Tb, Enemys, #grid_info.enemy),
- Friends = .battlefield:get_soldier_by_side(Side),
+ Friends = battlefield:get_soldier_by_side(Side),
update_grid(Tb, Friends, #grid_info.friend),
receive
@@ -35,13 +35,13 @@
%% 更新每个战区内的敌我情形
update_grid(Tb, Soldiers, Key) ->
- .lists:foreach(
+ lists:foreach(
fun(S) ->
{X, Y} = S#soldier.position,
ID = {X div 5, Y div 5},
- [Info|_] = .ets:lookup(Tb, ID),
+ [Info|_] = ets:lookup(Tb, ID),
NewSoldiers = [S#soldier.id|element(Key, Info)],
- .ets:update_element(Tb, ID, {Key, NewSoldiers})
+ ets:update_element(Tb, ID, {Key, NewSoldiers})
end,
Soldiers).
@@ -51,7 +51,7 @@
Grids = [{0,0}, {0,1}, {0,2},
{1,0}, {1,1}, {1,2},
{2,0}, {2,1}, {2,2}],
- .lists:foreach(fun(ID) -> .ets:update_element(Tb, ID, {#grid_info.friend, []}) end,
+ lists:foreach(fun(ID) -> ets:update_element(Tb, ID, {#grid_info.friend, []}) end,
Grids),
- .lists:foreach(fun(ID) -> .ets:update_element(Tb, ID, {#grid_info.enemy, []}) end,
+ lists:foreach(fun(ID) -> ets:update_element(Tb, ID, {#grid_info.enemy, []}) end,
Grids).
Index: army/hwh/util.erl
===================================================================
--- army/hwh/util.erl (revision 841)
+++ army/hwh/util.erl (working copy)
@@ -1,4 +1,4 @@
--module(hwh.util).
+-module(util).
-compile(export_all).
-include("schema.hrl").
@@ -11,12 +11,20 @@
calc_area(Side) ->
- case .battlefield:get_soldier_by_side(Side) of
+ case battlefield:get_soldier_by_side(Side) of
[] -> none;
Soldiers -> calc_soldier_area(Soldiers)
end.
+calc_area_bound(Soldiers, F) ->
+ [H|_] = lists:sort(
+ fun(S1, S2) ->
+ F(S1#soldier.position, S2#soldier.position)
+ end,
+ Soldiers),
+ H.
+
calc_soldier_area([]) -> none;
calc_soldier_area(Soldiers) ->
S1 = calc_area_bound(Soldiers, fun({X1, _}, {X2, _}) -> X1 > X2 end),
@@ -30,15 +38,7 @@
{length(Soldiers), East, South, West, North}.
-calc_area_bound(Soldiers, F) ->
- [H|_] = .lists:sort(
- fun(S1, S2) ->
- F(S1#soldier.position, S2#soldier.position)
- end,
- Soldiers),
- H.
-
%%瀵昏矾
path(#soldier{position = {SX, SY}} = Soldier, {DX, DY}) ->
path(SX, SY, DX, DY, Soldier#soldier.facing, Soldier#soldier.action, check).
@@ -109,7 +109,7 @@
srand() ->
{A, B, C} = now(),
- .random:seed(A, B, C).
+ random:seed(A, B, C).
dist({X, Y}, {X2, Y2}) -> abs(X-X2) + abs(Y-Y2);
@@ -118,7 +118,7 @@
road_blocking(Pos) ->
- case .battlefield:get_soldier_by_position(Pos) of
+ case battlefield:get_soldier_by_position(Pos) of
none -> false;
_ -> true
end.
@@ -150,7 +150,7 @@
astar_i(_, [], _) -> none;
astar_i(Dest, [Opn|_], _) when Dest =:= Opn#opn.pos ->
- [_|Path] = .lists:reverse([Dest|Opn#opn.parent]),
+ [_|Path] = lists:reverse([Dest|Opn#opn.parent]),
Path;
astar_i(Dest, [Opn|OpenList], CloseList) ->
%%1.鍙栧嚭openlist澶磋妭鐐癸紝鏀惧叆closelist
@@ -167,7 +167,7 @@
update_opn(Old, _) -> Old.
append_opn(Dest, OpenList, []) ->
- .lists:sort(fun(O1, O2) ->
+ lists:sort(fun(O1, O2) ->
if
O1#opn.pos =:= Dest -> true; %%dest
O2#opn.pos =:= Dest -> false; %%dest
@@ -177,10 +177,10 @@
end,
OpenList);
append_opn(Dest, OpenList, [Opn|TOpns]) ->
- OpenList2 = case .lists:keymember(Opn#opn.pos, #opn.pos, OpenList) of
+ OpenList2 = case lists:keymember(Opn#opn.pos, #opn.pos, OpenList) of
false -> [Opn|OpenList];
true ->
- .lists:map(fun(Old) ->
+ lists:map(fun(Old) ->
update_opn(Old, Opn)
end,
OpenList)
@@ -192,7 +192,7 @@
facing_cost(_, _) -> 0.5.
get_around(Dest, Opn, CloseList) ->
Parent = {SX, SY} = Opn#opn.pos,
- L1 = .lists:map(fun( {F, X, Y} ) ->
+ L1 = lists:map(fun( {F, X, Y} ) ->
NewPos = {SX + X, SY + Y},
Dist = dist(NewPos, Dest),
PreDist = 1 + facing_cost(F, Opn#opn.facing) + Opn#opn.fcos,
@@ -206,13 +206,13 @@
}
end,
[{?DirEast, 1, 0}, {?DirWest, -1, 0}, {?DirNorth, 0, 1}, {?DirSouth, 0, -1}]),
- .lists:filter(fun(O) ->
+ lists:filter(fun(O) ->
{X, Y} = O#opn.pos,
if
O#opn.pos =:= Dest -> true; %%dest
X > 14 orelse X < 0 -> false;
Y > 14 orelse Y < 0 -> false;
- true -> not (road_blocking(O#opn.pos) orelse .lists:member(O#opn.pos, CloseList))
+ true -> not (road_blocking(O#opn.pos) orelse lists:member(O#opn.pos, CloseList))
end
end,
L1).
Index: army/h1/x_front.erl
===================================================================
--- army/h1/x_front.erl (revision 841)
+++ army/h1/x_front.erl (working copy)
@@ -1,4 +1,4 @@
--module(h1.x_front).
+-module(x_front).
-behaviour(gen_fsm).
-compile(export_all).
-include("schema.hrl").
@@ -14,7 +14,7 @@
start_link(ID, Phone) ->
- .gen_fsm:start_link(?MODULE, {self(), ID, Phone}, []).
+ gen_fsm:start_link(?MODULE, {self(), ID, Phone}, []).
init({Master, ID, Phone}) ->
@@ -25,27 +25,27 @@
state_detecting(timeout, {ID, Phone, Data}) ->
Soldiers = get_front(ID, Phone),
NewData = notify_detect_result(Soldiers, Data),
- h1.util:next_detect_state(Soldiers, state_detecting, {ID, Phone, NewData});
+ util:next_detect_state(Soldiers, state_detecting, {ID, Phone, NewData});
state_detecting(set_control, StateData) ->
{next_state, state_fighting, StateData, 1}.
get_front(ID, Phone) ->
- h1.util:get_enemy(ID, Phone,
+ util:get_enemy(ID, Phone,
fun(#soldier{facing = Facing}) ->
- [h1.util:forward(Facing, 1), h1.util:forward(Facing, 2)]
+ [util:forward(Facing, 1), util:forward(Facing, 2)]
end,
- h1.util:friend_filter(Phone),
+ util:friend_filter(Phone),
fun(Soldier, E1, E2) ->
- Dist1 = h1.util:dist(Soldier, E1),
- Dist2 = h1.util:dist(Soldier, E2),
+ Dist1 = util:dist(Soldier, E1),
+ Dist2 = util:dist(Soldier, E2),
Dist1 =< Dist2
end).
notify_detect_result(Soldiers, Data) ->
OldScore = Data#data.last_score,
- NewScore = h1.util:notify_detect_result(Soldiers, OldScore, ?X_Front_Score),
+ NewScore = util:notify_detect_result(Soldiers, OldScore, ?X_Front_Score),
Data#data{ last_score = NewScore }.
@@ -53,7 +53,7 @@
Soldiers = get_front(ID, Phone),
attack_front(ID, Soldiers, Phone),
NewData = notify_detect_result(Soldiers, Data),
- h1.util:next_detect_state(Soldiers, state_fighting, {ID, Phone, NewData});
+ util:next_detect_state(Soldiers, state_fighting, {ID, Phone, NewData});
state_fighting(lost_control, StateData) ->
{next_state, state_detecting, StateData, 1}.
Index: army/h1/x_around.erl
===================================================================
--- army/h1/x_around.erl (revision 841)
+++ army/h1/x_around.erl (working copy)
@@ -1,4 +1,4 @@
--module(h1.x_around).
+-module(x_around).
-behaviour(gen_fsm).
-compile(export_all).
-export([init/1, handle_event/3, terminate/3]).
@@ -15,7 +15,7 @@
start_link(ID, Phone) ->
- .gen_fsm:start_link(?MODULE, {self(), ID, Phone}, []).
+ gen_fsm:start_link(?MODULE, {self(), ID, Phone}, []).
init({Master, ID, Phone}) ->
@@ -26,15 +26,15 @@
state_detecting(timeout, {ID, Phone, Data}) ->
Soldiers = get_around(ID, Phone),
NewData = notify_detect_result(Soldiers, Data),
- h1.util:next_detect_state(Soldiers, state_detecting, {ID, Phone, NewData});
+ util:next_detect_state(Soldiers, state_detecting, {ID, Phone, NewData});
state_detecting(set_control, StateData) ->
{next_state, state_fighting, StateData, 1}.
get_around(ID, Phone) ->
- h1.util:get_enemy(ID, Phone,
+ util:get_enemy(ID, Phone,
fun(_) -> [{1,1}, {1,-1}, {-1,1}, {-1,-1}] end,
- h1.util:friend_filter(Phone),
+ util:friend_filter(Phone),
fun(_Soldier, E1, E2) ->
{ID1, _Side} = E1#soldier.id,
{ID2, _Side} = E2#soldier.id,
@@ -44,7 +44,7 @@
notify_detect_result(Soldiers, Data) ->
OldScore = Data#data.last_score,
- NewScore = h1.util:notify_detect_result(Soldiers, OldScore, ?X_Around_Score),
+ NewScore = util:notify_detect_result(Soldiers, OldScore, ?X_Around_Score),
Data#data{ last_score = NewScore }.
@@ -52,7 +52,7 @@
Soldiers = get_around(ID, Phone),
attack_around(ID, Soldiers, Phone),
NewData = notify_detect_result(Soldiers, Data),
- h1.util:next_detect_state(Soldiers, state_fighting, {ID, Phone, NewData});
+ util:next_detect_state(Soldiers, state_fighting, {ID, Phone, NewData});
state_fighting(lost_control, StateData) ->
{next_state, state_detecting, StateData, 1}.
@@ -66,21 +66,21 @@
attack(ID, Soldier, EnemyPresume, Phone).
attack(ID, Soldier, {move, EnemyPosition}, Phone) ->
- Dir = h1.util:which_dir(Soldier#soldier.position, EnemyPosition),
+ Dir = util:which_dir(Soldier#soldier.position, EnemyPosition),
turn_to_direction(ID, Phone, Soldier, Dir);
attack(ID, Soldier, {nomove, EnemyPosition}, Phone) ->
- Dir = h1.util:which_dir(Soldier#soldier.position, EnemyPosition),
+ Dir = util:which_dir(Soldier#soldier.position, EnemyPosition),
turn_to_direction(ID, Phone, Soldier, Dir).
turn_to_direction(_ID, _Phone, #soldier{ facing = Dir }, Dir) ->
ok;
turn_to_direction(ID, Phone, _Soldier, Dir) ->
- Action = h1.util:turn_action(Dir),
+ Action = util:turn_action(Dir),
Channel = Phone#phone.channel,
Channel ! {command, Action, ID, 0, 0}.
presume(#soldier{ action = ?ActionForward, facing = Facing, position = {X, Y} }) ->
- {OX, OY} = h1.util:forward(Facing, 1),
+ {OX, OY} = util:forward(Facing, 1),
{move, {X+OX, Y+OY} };
presume(Soldier) ->
{nomove, Soldier#soldier.position}.
Index: army/h1/one.erl
===================================================================
--- army/h1/one.erl (revision 841)
+++ army/h1/one.erl (working copy)
@@ -1,4 +1,4 @@
--module(h1.one).
+-module(one).
-compile(export_all).
-include("def.hrl").
-include("schema.hrl").
@@ -8,18 +8,18 @@
process_flag(trap_exit, true),
put(master, Master),
put(soldier_id, ID),
- Plans = .lists:map(fun(M) ->
+ Plans = lists:map(fun(M) ->
{ok, PID} = apply(M, start_link, [ID, Phone]),
{PID, ?X_None_Score}
end,
- [h1.x_front, h1.x_near, h1.x_around]),
+ [x_front, x_near, x_around]),
loop(Master, Plans, none).
loop(Master, Plans, CurPlan) ->
receive
{'EXIT', Master, finish} ->
- .lists:foreach(fun({PID,_}) -> .gen_fsm:send_all_state_event(PID, stop) end, Plans);
+ lists:foreach(fun({PID,_}) -> gen_fsm:send_all_state_event(PID, stop) end, Plans);
{set_score, PID, Score} ->
{NewPlans, NewCurPlan} = change_plan(Plans, PID, Score, CurPlan),
loop(Master, NewPlans, NewCurPlan);
@@ -29,9 +29,9 @@
change_plan(Plans, PID, Score, CurPlan) ->
- Plans1 = .lists:keystore(PID, 1, Plans, {PID, Score}),
- NewPlans = .lists:keysort(2, Plans1),
- NewCurPlan = notify_plan_change(CurPlan, .lists:last(NewPlans)),
+ Plans1 = lists:keystore(PID, 1, Plans, {PID, Score}),
+ NewPlans = lists:keysort(2, Plans1),
+ NewCurPlan = notify_plan_change(CurPlan, lists:last(NewPlans)),
{NewPlans, NewCurPlan}.
@@ -40,11 +40,11 @@
none;
notify_plan_change(CurPlan, {PID, _}) ->
lost_control(CurPlan),
- .gen_fsm:send_event(PID, set_control),
+ gen_fsm:send_event(PID, set_control),
PID.
lost_control(none) ->
ok;
lost_control(PID) ->
- .gen_fsm:send_event(PID, lost_control).
+ gen_fsm:send_event(PID, lost_control).
Index: army/h1/t1.erl
===================================================================
--- army/h1/t1.erl (revision 841)
+++ army/h1/t1.erl (working copy)
@@ -1,4 +1,4 @@
--module(h1.t1).
+-module(t1).
-compile(export_all).
-include("schema.hrl").
-include("def.hrl").
@@ -7,14 +7,14 @@
run(Channel, Side, Queue) ->
process_flag(trap_exit, true),
Phone = #phone{channel = Channel, side = Side, queue = Queue},
- SoldierIDs = .lists:map(fun(ID) -> spawn_link(h1.one, start_link, [self(), ID, Phone]) end, ?PreDef_army),
+ SoldierIDs = lists:map(fun(ID) -> spawn_link(one, start_link, [self(), ID, Phone]) end, ?PreDef_army),
loop(Channel, SoldierIDs).
loop(Channel, SoldierIDs) ->
receive
{'EXIT', Channel, finish} ->
- .lists:foreach(fun(PID) -> exit(PID, finish) end, SoldierIDs);
+ lists:foreach(fun(PID) -> exit(PID, finish) end, SoldierIDs);
_ ->
loop(Channel, SoldierIDs)
end.
Index: army/h1/x_near.erl
===================================================================
--- army/h1/x_near.erl (revision 841)
+++ army/h1/x_near.erl (working copy)
@@ -1,4 +1,4 @@
--module(h1.x_near).
+-module(x_near).
-behaviour(gen_fsm).
-compile(export_all).
-export([init/1, handle_event/3, terminate/3]).
@@ -14,7 +14,7 @@
start_link(ID, Phone) ->
- .gen_fsm:start_link(?MODULE, {self(), ID, Phone}, []).
+ gen_fsm:start_link(?MODULE, {self(), ID, Phone}, []).
init({Master, ID, Phone}) ->
@@ -25,25 +25,25 @@
state_detecting(timeout, {ID, Phone, Data}) ->
Soldiers = get_near(ID, Phone),
NewData = notify_detect_result(Soldiers, Data),
- h1.util:next_detect_state(Soldiers, state_detecting, {ID, Phone, NewData});
+ util:next_detect_state(Soldiers, state_detecting, {ID, Phone, NewData});
state_detecting(set_control, StateData) ->
{next_state, state_fighting, StateData, 1}.
get_near(ID, Phone) ->
- h1.util:get_enemy(ID, Phone,
+ util:get_enemy(ID, Phone,
fun(_) -> [{1,0}, {-1,0}, {0,1}, {0,-1}] end,
- h1.util:friend_filter(Phone),
+ util:friend_filter(Phone),
fun(Soldier, E1, E2) ->
- E1_score = h1.util:near_enemy_score(Soldier, E1),
- E2_score = h1.util:near_enemy_score(Soldier, E2),
+ E1_score = util:near_enemy_score(Soldier, E1),
+ E2_score = util:near_enemy_score(Soldier, E2),
E1_score >= E2_score
end).
notify_detect_result(Soldiers, Data) ->
OldScore = Data#data.last_score,
- NewScore = h1.util:notify_detect_result(Soldiers, OldScore, ?X_Near_Score),
+ NewScore = util:notify_detect_result(Soldiers, OldScore, ?X_Near_Score),
Data#data{ last_score = NewScore }.
@@ -51,7 +51,7 @@
Soldiers = get_near(ID, Phone),
attack_near(ID, Soldiers, Phone),
NewData = notify_detect_result(Soldiers, Data),
- h1.util:next_detect_state(Soldiers, state_fighting, {ID, Phone, NewData});
+ util:next_detect_state(Soldiers, state_fighting, {ID, Phone, NewData});
state_fighting(lost_control, StateData) ->
{next_state, state_detecting, StateData, 1}.
@@ -61,14 +61,14 @@
attack_near(_ID, none, _Phone) ->
noaction;
attack_near(ID, {Soldier, Enemy}, Phone) ->
- Dir = h1.util:which_dir(Soldier, Enemy),
+ Dir = util:which_dir(Soldier, Enemy),
attack_on_dir(ID, Soldier, Dir, Phone).
attack_on_dir(ID, #soldier{ facing = Dir}, Dir, Phone) ->
Channel = Phone#phone.channel,
Channel ! {command, ?ActionAttack, ID, 0, 0};
attack_on_dir(ID, Soldier, Dir, Phone) ->
- Action = h1.util:turn_action(Dir),
+ Action = util:turn_action(Dir),
Channel = Phone#phone.channel,
if
Action =:= Soldier#soldier.action ->
Index: army/h1/util.erl
===================================================================
--- army/h1/util.erl (revision 841)
+++ army/h1/util.erl (working copy)
@@ -1,4 +1,4 @@
--module(h1.util).
+-module(util).
-compile(export_all).
-include("schema.hrl").
-include("def.hrl").
@@ -59,17 +59,17 @@
idead;
get_enemy(Soldier, PosList, Filter, Sorter) ->
{X, Y} = Soldier#soldier.position,
- L1 = .lists:map(
+ L1 = lists:map(
fun({OX, OY}) ->
Pos = {X+OX, Y+OY},
- .battlefield:get_soldier_by_position(Pos)
+ battlefield:get_soldier_by_position(Pos)
end,
PosList(Soldier)),
- L2 = .lists:filter(
+ L2 = lists:filter(
fun(none) -> false;
(Enemy) -> Filter(Soldier, Enemy) end,
L1),
- L3 = .lists:sort(
+ L3 = lists:sort(
fun(E1, E2) -> Sorter(Soldier, E1, E2) end,
L2),
F =
@@ -77,7 +77,7 @@
([E|_]) -> {Soldier, E} end,
F(L3).
get_enemy(ID, Phone, PosList, Filter, Sorter) ->
- Soldier = .battlefield:get_soldier(ID, Phone#phone.side),
+ Soldier = battlefield:get_soldier(ID, Phone#phone.side),
get_enemy(Soldier, PosList, Filter, Sorter).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment