@@ -227,6 +227,8 @@ async def draw_start(sid, data):
227227 p ['last_nodes' ] = []
228228 p ['last_arrows' ] = []
229229 p ['submitted' ] = False
230+ # ✅ [Agent 행동] Chaos 채점 룰 초기화 (신규 게임 시작)
231+ room ['chaos_bonus_check' ] = None
230232 # [수정일: 2026-03-03] DB(unit03) 미션 lazy 로드
231233 missions = await _get_missions ()
232234 if not missions :
@@ -282,8 +284,17 @@ async def run_draw_room_tick(room_id):
282284 print (f"⏰ [Poll] Hint pushed to { actual_target [:8 ]} " )
283285 await sio .emit ('coach_hint' , hint_payload , to = actual_target )
284286 if res .get ('chaos_event' ):
287+ chaos_ev = res ['chaos_event' ]
285288 print (f"⏰ [Poll] Chaos pushed in Room: { room_id } " )
286- await sio .emit ('chaos_event' , res ['chaos_event' ], room = room_id )
289+ # ✅ [Agent 행동] Poll에서 오는 Chaos도 동일하게 게임 룰 수정
290+ req_comp = chaos_ev .get ('required_component' )
291+ if req_comp and room_id in draw_rooms :
292+ draw_rooms [room_id ]['chaos_bonus_check' ] = {
293+ 'component' : req_comp ,
294+ 'bonus_pts' : 20 ,
295+ 'penalty_pts' : - 10 ,
296+ }
297+ await sio .emit ('chaos_event' , chaos_ev , room = room_id )
287298
288299 await asyncio .sleep (8 ) # 8초마다 체크 (trigger_policy 임계값과 상충되지 않는 주기로 선정)
289300 print (f"🛑 [ArchDraw] Periodic check stopped for room: { room_id } " )
@@ -310,7 +321,18 @@ async def draw_submit(sid, data):
310321 complete_bonus = 20 if ratio == 1.0 else 0 # 전부 통과 시 +20점
311322 combo_bonus = min (data .get ('combo' , 0 ), 5 ) * 2 # 최대 10점 (5콤보 상한)
312323 pts = check_score + time_bonus + complete_bonus + combo_bonus
313-
324+
325+ # ✅ [Agent 행동 반영] ChaosAgent가 설정한 게임 룰 체크
326+ chaos_check = room .get ('chaos_bonus_check' )
327+ if chaos_check :
328+ placed_ids = [n .get ('compId' ) for n in data .get ('final_nodes' , [])]
329+ if chaos_check ['component' ] in placed_ids :
330+ pts += chaos_check ['bonus_pts' ]
331+ print (f"✅ [ArchDraw] Chaos 조건 충족: { player ['name' ]} +{ chaos_check ['bonus_pts' ]} 점 ({ chaos_check ['component' ]} 배치 확인)" )
332+ else :
333+ pts += chaos_check ['penalty_pts' ] # 음수값
334+ print (f"❌ [ArchDraw] Chaos 조건 미충족: { player ['name' ]} { chaos_check ['penalty_pts' ]} 점 ({ chaos_check ['component' ]} 누락)" )
335+
314336 player ['score' ] += pts
315337 player ['last_pts' ] = pts
316338 player ['last_checks' ] = checks
@@ -439,6 +461,8 @@ async def draw_next_round(sid, data):
439461 room_state .hint_history = {}
440462 room_state .past_event_ids = []
441463 room_state .player_designs = {}
464+ # ✅ [Agent 행동] 다음 라운드에서 Chaos 채점 룰 리셋
465+ room ['chaos_bonus_check' ] = None
442466
443467 # 새로운 무작위 문제 선택 + 팔레트 서버 생성
444468 cur_round = data .get ('round' , room .get ('current_round' , 1 ) + 1 )
@@ -487,9 +511,19 @@ async def draw_canvas_sync(sid, data):
487511 target_sid = res ['coach_hint' ].get ('_target_sid' , sid )
488512 print (f"💡 [ArchDraw] Hint Sent to { target_sid [:8 ]} : { hint_payload .get ('message' , '' )[:20 ]} ..." )
489513 await sio .emit ('coach_hint' , hint_payload , to = target_sid ) # [수정일: 2026-03-03] room= → to= (개인 전송)
490- if res .get ('chaos_event' ):
491- print (f"🔥 [ArchDraw] Chaos Event in Room: { room_id } " )
492- await sio .emit ('chaos_event' , res ['chaos_event' ], room = room_id )
514+ if res .get ('chaos_event' ):
515+ chaos_ev = res ['chaos_event' ]
516+ print (f"🔥 [ArchDraw] Chaos Event in Room: { room_id } | required_component={ chaos_ev .get ('required_component' )} " )
517+ # ✅ [Agent 행동] Chaos가 게임 룰을 직접 수정 — 채점 시 반영됨
518+ req_comp = chaos_ev .get ('required_component' )
519+ if req_comp :
520+ draw_rooms [room_id ]['chaos_bonus_check' ] = {
521+ 'component' : req_comp ,
522+ 'bonus_pts' : 20 ,
523+ 'penalty_pts' : - 10 ,
524+ }
525+ print (f"📋 [ArchDraw] Chaos 채점 룰 추가: +20 if { req_comp } placed, -10 if not" )
526+ await sio .emit ('chaos_event' , chaos_ev , room = room_id )
493527
494528@sio .event
495529async def draw_chaos_complete (sid , data ):
0 commit comments