Skip to content

Commit 5fd81a8

Browse files
authored
Merge pull request #131 from eesast/fix-run
Fix run
2 parents dd715df + 483edb4 commit 5fd81a8

3 files changed

Lines changed: 26 additions & 41 deletions

File tree

dependency/shell/run.sh

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,6 @@ fi
5151
: "${TEAM_LABEL:=TeamA}"
5252
: "${CONNECT_IP:=172.17.0.1}"
5353

54-
# ── Retry helper ───────────────────────────────────────────────────────────
55-
function retry_command {
56-
local command="$1"
57-
local max_attempts=5
58-
local attempt_num=1
59-
local sleep_seconds=10
60-
61-
while [ $attempt_num -le $max_attempts ]; do
62-
echo "Attempt $attempt_num / $max_attempts to run command: $command"
63-
64-
eval $command &
65-
local pid=$!
66-
67-
sleep $sleep_seconds
68-
69-
if kill -0 $pid 2>/dev/null; then
70-
echo "Failed to connect to server. Retrying..."
71-
((attempt_num++))
72-
else
73-
echo "Connected to server successfully."
74-
return 0
75-
fi
76-
done
77-
78-
echo "Failed to connect to server after $max_attempts attempts."
79-
return 1
80-
}
81-
8254
# ═══════════════════════════════════════════════════════════════════════════
8355
# SERVER
8456
# ═══════════════════════════════════════════════════════════════════════════
@@ -170,20 +142,22 @@ elif [ "$TERMINAL" = "CLIENT" ]; then
170142

171143
command="nice -n 0 python3 ${cp_dir}/PyAPI/main.py \
172144
-I $CONNECT_IP -P $PORT \
173-
-t $team_id -s $TEAM_SEQ_ID \
145+
-t $team_id \
174146
-p $player_idx"
175147

176-
retry_command "$command" > "$output_dir/team${TEAM_SEQ_ID}-$code_name.log" 2>&1 &
148+
echo "Launching: $command"
149+
eval "$command" > "$output_dir/team${TEAM_SEQ_ID}-$code_name.log" 2>&1 &
177150

178151
elif [ -f "./$code_name" ]; then
179152
echo "Found ./$code_name"
180153

181154
command="nice -n 0 ./$code_name \
182155
-I $CONNECT_IP -P $PORT \
183-
-t $team_id -s $TEAM_SEQ_ID \
156+
-t $team_id \
184157
-p $player_idx"
185158

186-
retry_command "$command" > "$output_dir/team${TEAM_SEQ_ID}-$code_name.log" 2>&1 &
159+
echo "Launching: $command"
160+
eval "$command" > "$output_dir/team${TEAM_SEQ_ID}-$code_name.log" 2>&1 &
187161

188162
else
189163
break

logic/Gaming/Game.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public Game(MapStruct mapResource, int numOfTeam)
3434
tradeManager = new(this, gameMap);
3535
uplevelManager = new(this);
3636
teams = new ConcurrentDictionary<long, TeamState>();
37-
InitTeams();
37+
InitTeams(numOfTeam);
3838

3939
tradeManager = new TradeManager(this, gameMap);
4040
uplevelManager = new UplevelManager(this);

logic/Gaming/Teams.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,29 @@ public TeamSnapshot(long teamId, long score, int costTech, int efficiencyTech, i
7676
}
7777
}
7878

79-
private void InitTeams()
79+
private void InitTeams(int numOfTeam)
8080
{
81-
// 工厂位置应该对应地图中 PlaceType.FACTORY 的位置
82-
// MapInfo 中 defaultMap 的工厂位置是 [3,3], [3,46], [46,3], [46,46]
81+
if (numOfTeam < 2 || numOfTeam > 4)
82+
{
83+
throw new ArgumentOutOfRangeException(
84+
nameof(numOfTeam),
85+
numOfTeam,
86+
"Team count must be 2, 3, or 4."
87+
);
88+
}
89+
90+
// Team layout order:
91+
// Team 1: top-left, Team 2: bottom-right,
92+
// Team 3: bottom-left, Team 4: top-right.
8393
var corners = new (int cx, int cy)[]
8494
{
85-
(3, 3), // Team 1 工厂位置
86-
(3, 46), // Team 2 工厂位置
87-
(46, 3), // Team 3 工厂位置
88-
(46, 46) // Team 4 工厂位置
95+
(3, 3),
96+
(46, 46),
97+
(3, 46),
98+
(46, 3),
8999
};
90-
for (int i = 0; i < 4; i++)
100+
101+
for (int i = 0; i < numOfTeam; i++)
91102
{
92103
long teamId = i + 1;
93104
var (cx, cy) = corners[i];

0 commit comments

Comments
 (0)